@@ -2,9 +2,10 @@ package collector
22
33import (
44 "fmt"
5- "k8s.io/apimachinery/pkg/util/intstr"
65 "strings"
76
7+ "k8s.io/apimachinery/pkg/util/intstr"
8+
89 log "github.com/ViaQ/logerr/v2/log/static"
910 "github.com/openshift/cluster-logging-operator/internal/auth"
1011 "github.com/openshift/cluster-logging-operator/internal/collector/common"
@@ -22,6 +23,9 @@ import (
2223)
2324
2425const (
26+ //DefaultMaxUnavailable is the maxUnavailable collector setting when not defined by spec.collector.maxUnavailable
27+ DefaultMaxUnavailable = "100%"
28+
2529 defaultAudience = "openshift"
2630 clusterLoggingPriorityClassName = "system-node-critical"
2731 MetricsPort = int32 (24231 )
@@ -69,9 +73,7 @@ type Factory struct {
6973 PodLabelVisitor PodLabelVisitor
7074 ResourceNames * factory.ForwarderResourceNames
7175 isDaemonset bool
72- LogLevel string
73- UseKubeCache bool
74- MaxUnavailable string
76+ annotations map [string ]string
7577}
7678
7779// CollectorResourceRequirements returns the resource requirements for a given collector implementation
@@ -89,12 +91,22 @@ func (f *Factory) NodeSelector() map[string]string {
8991func (f * Factory ) Tolerations () []v1.Toleration {
9092 return f .CollectorSpec .Tolerations
9193}
92-
9394func (f * Factory ) Affinity () * v1.Affinity {
9495 return f .CollectorSpec .Affinity
9596}
97+ func (f * Factory ) MaxUnavailable () intstr.IntOrString {
98+ if f .CollectorSpec .MaxUnavailable != nil {
99+ return * f .CollectorSpec .MaxUnavailable
100+ }
101+ if f .annotations != nil {
102+ if value , found := f .annotations [constants .AnnotationMaxUnavailable ]; found {
103+ return intstr .Parse (value )
104+ }
105+ }
106+ return intstr .Parse (DefaultMaxUnavailable )
107+ }
96108
97- func New (confHash , clusterID string , collectorSpec * obs.CollectorSpec , secrets internalobs.Secrets , configMaps map [string ]* v1.ConfigMap , forwarderSpec obs.ClusterLogForwarderSpec , resNames * factory.ForwarderResourceNames , isDaemonset bool , logLevel string , useCache bool , maxUnavailable string ) * Factory {
109+ func New (confHash , clusterID string , collectorSpec * obs.CollectorSpec , secrets internalobs.Secrets , configMaps map [string ]* v1.ConfigMap , forwarderSpec obs.ClusterLogForwarderSpec , resNames * factory.ForwarderResourceNames , isDaemonset bool , annotations map [ string ] string ) * Factory {
98110 if collectorSpec == nil {
99111 collectorSpec = & obs.CollectorSpec {}
100112 }
@@ -113,16 +125,14 @@ func New(confHash, clusterID string, collectorSpec *obs.CollectorSpec, secrets i
113125 ResourceNames : resNames ,
114126 PodLabelVisitor : vector .PodLogExcludeLabel ,
115127 isDaemonset : isDaemonset ,
116- LogLevel : logLevel ,
117- UseKubeCache : useCache ,
118- MaxUnavailable : maxUnavailable ,
128+ annotations : annotations ,
119129 }
120130 return factory
121131}
122132
123133func (f * Factory ) NewDaemonSet (namespace , name string , trustedCABundle * v1.ConfigMap , tlsProfileSpec configv1.TLSProfileSpec ) * apps.DaemonSet {
124134 podSpec := f .NewPodSpec (trustedCABundle , f .ForwarderSpec , f .ClusterID , tlsProfileSpec , namespace )
125- ds := factory .NewDaemonSet (namespace , name , name , constants .CollectorName , constants .VectorName , f .MaxUnavailable , * podSpec , f .CommonLabelInitializer , f .PodLabelVisitor )
135+ ds := factory .NewDaemonSet (namespace , name , name , constants .CollectorName , constants .VectorName , f .MaxUnavailable () , * podSpec , f .CommonLabelInitializer , f .PodLabelVisitor )
126136 ds .Spec .Template .Annotations [constants .AnnotationSecretHash ] = f .Secrets .Hash64a ()
127137 return ds
128138}
@@ -143,6 +153,7 @@ func (f *Factory) NewPodSpec(trustedCABundle *v1.ConfigMap, spec obs.ClusterLogF
143153 TerminationGracePeriodSeconds : utils.GetPtr [int64 ](10 ),
144154 Tolerations : append (constants .DefaultTolerations (), f .Tolerations ()... ),
145155 Affinity : f .Affinity (),
156+
146157 Volumes : []v1.Volume {
147158 {Name : metricsVolumeName , VolumeSource : v1.VolumeSource {Secret : & v1.SecretVolumeSource {SecretName : f .ResourceNames .SecretMetrics }}},
148159 {Name : tmpVolumeName , VolumeSource : v1.VolumeSource {EmptyDir : & v1.EmptyDirVolumeSource {Medium : v1 .StorageMediumMemory }}},
@@ -172,7 +183,7 @@ func (f *Factory) NewPodSpec(trustedCABundle *v1.ConfigMap, spec obs.ClusterLogF
172183
173184 addTrustedCABundle (collector , podSpec , trustedCABundle )
174185
175- f .Visit (collector , podSpec , f .ResourceNames , namespace , f . LogLevel )
186+ f .Visit (collector , podSpec , f .ResourceNames , namespace , LogLevel ( f . annotations ) )
176187
177188 podSpec .Containers = []v1.Container {
178189 * collector ,
@@ -413,3 +424,10 @@ func hasTrustedCABundle(configMap *v1.ConfigMap) (string, bool) {
413424 caBundle , ok := configMap .Data [constants .TrustedCABundleKey ]
414425 return caBundle , ok && caBundle != ""
415426}
427+
428+ func LogLevel (annotations map [string ]string ) string {
429+ if level , ok := annotations [constants .AnnotationVectorLogLevel ]; ok {
430+ return level
431+ }
432+ return "warn"
433+ }
0 commit comments