@@ -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,8 @@ type Factory struct {
6973 PodLabelVisitor PodLabelVisitor
7074 ResourceNames * factory.ForwarderResourceNames
7175 isDaemonset bool
72- LogLevel string
73- UseKubeCache bool
74- MaxUnavailable string
76+ //LogLevel string
77+ annotations map [string ]string
7578}
7679
7780// CollectorResourceRequirements returns the resource requirements for a given collector implementation
@@ -89,12 +92,22 @@ func (f *Factory) NodeSelector() map[string]string {
8992func (f * Factory ) Tolerations () []v1.Toleration {
9093 return f .CollectorSpec .Tolerations
9194}
92-
9395func (f * Factory ) Affinity () * v1.Affinity {
9496 return f .CollectorSpec .Affinity
9597}
98+ func (f * Factory ) MaxUnavailable () intstr.IntOrString {
99+ if f .CollectorSpec .MaxUnavailable != nil {
100+ return * f .CollectorSpec .MaxUnavailable
101+ }
102+ if f .annotations != nil {
103+ if value , found := f .annotations [constants .AnnotationMaxUnavailable ]; found {
104+ return intstr .Parse (value )
105+ }
106+ }
107+ return intstr .Parse (DefaultMaxUnavailable )
108+ }
96109
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 {
110+ 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 {
98111 if collectorSpec == nil {
99112 collectorSpec = & obs.CollectorSpec {}
100113 }
@@ -113,16 +126,14 @@ func New(confHash, clusterID string, collectorSpec *obs.CollectorSpec, secrets i
113126 ResourceNames : resNames ,
114127 PodLabelVisitor : vector .PodLogExcludeLabel ,
115128 isDaemonset : isDaemonset ,
116- LogLevel : logLevel ,
117- UseKubeCache : useCache ,
118- MaxUnavailable : maxUnavailable ,
129+ annotations : annotations ,
119130 }
120131 return factory
121132}
122133
123134func (f * Factory ) NewDaemonSet (namespace , name string , trustedCABundle * v1.ConfigMap , tlsProfileSpec configv1.TLSProfileSpec ) * apps.DaemonSet {
124135 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 )
136+ ds := factory .NewDaemonSet (namespace , name , name , constants .CollectorName , constants .VectorName , f .MaxUnavailable () , * podSpec , f .CommonLabelInitializer , f .PodLabelVisitor )
126137 ds .Spec .Template .Annotations [constants .AnnotationSecretHash ] = f .Secrets .Hash64a ()
127138 return ds
128139}
@@ -143,6 +154,7 @@ func (f *Factory) NewPodSpec(trustedCABundle *v1.ConfigMap, spec obs.ClusterLogF
143154 TerminationGracePeriodSeconds : utils.GetPtr [int64 ](10 ),
144155 Tolerations : append (constants .DefaultTolerations (), f .Tolerations ()... ),
145156 Affinity : f .Affinity (),
157+
146158 Volumes : []v1.Volume {
147159 {Name : metricsVolumeName , VolumeSource : v1.VolumeSource {Secret : & v1.SecretVolumeSource {SecretName : f .ResourceNames .SecretMetrics }}},
148160 {Name : tmpVolumeName , VolumeSource : v1.VolumeSource {EmptyDir : & v1.EmptyDirVolumeSource {Medium : v1 .StorageMediumMemory }}},
@@ -172,7 +184,7 @@ func (f *Factory) NewPodSpec(trustedCABundle *v1.ConfigMap, spec obs.ClusterLogF
172184
173185 addTrustedCABundle (collector , podSpec , trustedCABundle )
174186
175- f .Visit (collector , podSpec , f .ResourceNames , namespace , f . LogLevel )
187+ f .Visit (collector , podSpec , f .ResourceNames , namespace , LogLevel ( f . annotations ) )
176188
177189 podSpec .Containers = []v1.Container {
178190 * collector ,
@@ -413,3 +425,10 @@ func hasTrustedCABundle(configMap *v1.ConfigMap) (string, bool) {
413425 caBundle , ok := configMap .Data [constants .TrustedCABundleKey ]
414426 return caBundle , ok && caBundle != ""
415427}
428+
429+ func LogLevel (annotations map [string ]string ) string {
430+ if level , ok := annotations [constants .AnnotationVectorLogLevel ]; ok {
431+ return level
432+ }
433+ return "warn"
434+ }
0 commit comments