@@ -132,8 +132,6 @@ const (
132132)
133133
134134type Operator struct {
135- ctx context.Context
136-
137135 namespace , namespaceUserWorkload string
138136
139137 configMapName string
@@ -177,7 +175,6 @@ func New(
177175 }
178176
179177 o := & Operator {
180- ctx : ctx ,
181178 images : images ,
182179 telemetryMatches : telemetryMatches ,
183180 configMapName : configMapName ,
@@ -250,7 +247,7 @@ func New(
250247 o .informers = append (o .informers , informer )
251248
252249 informer = cache .NewSharedIndexInformer (
253- o .client .InfrastructureListWatchForResource (o . ctx , clusterResourceName ),
250+ o .client .InfrastructureListWatchForResource (ctx , clusterResourceName ),
254251 & configv1.Infrastructure {}, resyncPeriod , cache.Indexers {},
255252 )
256253 informer .AddEventHandler (cache.ResourceEventHandlerFuncs {
@@ -373,7 +370,7 @@ func (o *Operator) Run(ctx context.Context) error {
373370 go r (ctx , 1 )
374371 }
375372
376- go o .worker ()
373+ go o .worker (ctx )
377374
378375 ticker := time .NewTicker (5 * time .Minute )
379376 defer ticker .Stop ()
@@ -449,20 +446,20 @@ func (o *Operator) handleEvent(obj interface{}) {
449446 o .enqueue (cmoConfigMap )
450447}
451448
452- func (o * Operator ) worker () {
453- for o .processNextWorkItem () {
449+ func (o * Operator ) worker (ctx context. Context ) {
450+ for o .processNextWorkItem (ctx ) {
454451 }
455452}
456453
457- func (o * Operator ) processNextWorkItem () bool {
454+ func (o * Operator ) processNextWorkItem (ctx context. Context ) bool {
458455 key , quit := o .queue .Get ()
459456 if quit {
460457 return false
461458 }
462459 defer o .queue .Done (key )
463460
464461 o .reconcileAttempts .Inc ()
465- err := o .sync (key .(string ))
462+ err := o .sync (ctx , key .(string ))
466463 if err == nil {
467464 o .reconcileStatus .Set (1 )
468465 o .queue .Forget (key )
@@ -493,23 +490,23 @@ func (o *Operator) enqueue(obj interface{}) {
493490 o .queue .Add (key )
494491}
495492
496- func (o * Operator ) sync (key string ) error {
497- config , err := o .Config (key )
493+ func (o * Operator ) sync (ctx context. Context , key string ) error {
494+ config , err := o .Config (ctx , key )
498495 if err != nil {
499- o .reportError (err , "InvalidConfiguration" )
496+ o .reportError (ctx , err , "InvalidConfiguration" )
500497 return err
501498 }
502499 config .SetImages (o .images )
503500 config .SetTelemetryMatches (o .telemetryMatches )
504501 config .SetRemoteWrite (o .remoteWrite )
505502
506503 var proxyConfig manifests.ProxyReader
507- proxyConfig , err = o .loadProxyConfig ()
504+ proxyConfig , err = o .loadProxyConfig (ctx )
508505 if err != nil {
509506 klog .Warningf ("using proxy config from CMO configmap: %v" , err )
510507 proxyConfig = config
511508 }
512- factory := manifests .NewFactory (o .namespace , o .namespaceUserWorkload , config , o .loadInfrastructureConfig (), proxyConfig , o .assets )
509+ factory := manifests .NewFactory (o .namespace , o .namespaceUserWorkload , config , o .loadInfrastructureConfig (ctx ), proxyConfig , o .assets )
513510
514511 tl := tasks .NewTaskRunner (
515512 o .client ,
@@ -530,7 +527,7 @@ func (o *Operator) sync(key string) error {
530527 tasks .NewTaskSpec ("Updating node-exporter" , tasks .NewNodeExporterTask (o .client , factory )),
531528 tasks .NewTaskSpec ("Updating kube-state-metrics" , tasks .NewKubeStateMetricsTask (o .client , factory )),
532529 tasks .NewTaskSpec ("Updating openshift-state-metrics" , tasks .NewOpenShiftStateMetricsTask (o .client , factory )),
533- tasks .NewTaskSpec ("Updating prometheus-adapter" , tasks .NewPrometheusAdapterTask (o . ctx , o .namespace , o .client , factory )),
530+ tasks .NewTaskSpec ("Updating prometheus-adapter" , tasks .NewPrometheusAdapterTask (ctx , o .namespace , o .client , factory )),
534531 tasks .NewTaskSpec ("Updating Telemeter client" , tasks .NewTelemeterClientTask (o .client , factory , config )),
535532 tasks .NewTaskSpec ("Updating configuration sharing" , tasks .NewConfigSharingTask (o .client , factory , config )),
536533 tasks .NewTaskSpec ("Updating Thanos Querier" , tasks .NewThanosQuerierTask (o .client , factory , config )),
@@ -539,14 +536,14 @@ func (o *Operator) sync(key string) error {
539536 }),
540537 )
541538 klog .Info ("Updating ClusterOperator status to in progress." )
542- err = o .client .StatusReporter ().SetInProgress ()
539+ err = o .client .StatusReporter ().SetInProgress (ctx )
543540 if err != nil {
544541 klog .Errorf ("error occurred while setting status to in progress: %v" , err )
545542 }
546543
547- taskName , err := tl .RunAll ()
544+ taskName , err := tl .RunAll (ctx )
548545 if err != nil {
549- o .reportError (err , taskName )
546+ o .reportError (ctx , err , taskName )
550547 return err
551548 }
552549
@@ -557,32 +554,33 @@ func (o *Operator) sync(key string) error {
557554 }
558555 klog .Info ("Updating ClusterOperator status to done." )
559556 o .failedReconcileAttempts = 0
560- err = o .client .StatusReporter ().SetDone (degradedConditionMessage , degradedConditionReason )
557+ err = o .client .StatusReporter ().SetDone (ctx , degradedConditionMessage , degradedConditionReason )
558+
561559 if err != nil {
562560 klog .Errorf ("error occurred while setting status to done: %v" , err )
563561 }
564562
565563 return nil
566564}
567565
568- func (o * Operator ) reportError (err error , taskName string ) {
566+ func (o * Operator ) reportError (ctx context. Context , err error , taskName string ) {
569567 klog .Infof ("ClusterOperator reconciliation failed (attempt %d), retrying. Err: %v" , o .failedReconcileAttempts + 1 , err )
570568 if o .failedReconcileAttempts == 2 {
571569 // Only update the ClusterOperator status after 3 retries have been attempted to avoid flapping status.
572570 klog .Infof ("Updating ClusterOperator status to failed after %d attempts. Err: %v" , o .failedReconcileAttempts + 1 , err )
573571 failedTaskReason := strings .Join (strings .Fields (taskName + "Failed" ), "" )
574- reportErr := o .client .StatusReporter ().SetFailed (err , failedTaskReason )
572+ reportErr := o .client .StatusReporter ().SetFailed (ctx , err , failedTaskReason )
575573 if reportErr != nil {
576574 klog .Errorf ("error occurred while setting status to failed: %v" , reportErr )
577575 }
578576 }
579577 o .failedReconcileAttempts ++
580578}
581579
582- func (o * Operator ) loadInfrastructureConfig () * InfrastructureConfig {
580+ func (o * Operator ) loadInfrastructureConfig (ctx context. Context ) * InfrastructureConfig {
583581 var infrastructureConfig * InfrastructureConfig
584582
585- infrastructure , err := o .client .GetInfrastructure (clusterResourceName )
583+ infrastructure , err := o .client .GetInfrastructure (ctx , clusterResourceName )
586584 if err != nil {
587585 klog .Warningf ("Error getting cluster infrastructure: %v" , err )
588586
@@ -602,10 +600,10 @@ func (o *Operator) loadInfrastructureConfig() *InfrastructureConfig {
602600 return o .lastKnowInfrastructureConfig
603601}
604602
605- func (o * Operator ) loadProxyConfig () (* ProxyConfig , error ) {
603+ func (o * Operator ) loadProxyConfig (ctx context. Context ) (* ProxyConfig , error ) {
606604 var proxyConfig * ProxyConfig
607605
608- proxy , err := o .client .GetProxy (clusterResourceName )
606+ proxy , err := o .client .GetProxy (ctx , clusterResourceName )
609607 if err != nil {
610608 klog .Warningf ("Error getting cluster proxy configuration: %v" , err )
611609
@@ -622,10 +620,10 @@ func (o *Operator) loadProxyConfig() (*ProxyConfig, error) {
622620 return o .lastKnowProxyConfig , nil
623621}
624622
625- func (o * Operator ) loadUserWorkloadConfig () (* manifests.UserWorkloadConfiguration , error ) {
623+ func (o * Operator ) loadUserWorkloadConfig (ctx context. Context ) (* manifests.UserWorkloadConfiguration , error ) {
626624 cmKey := fmt .Sprintf ("%s/%s" , o .namespaceUserWorkload , o .userWorkloadConfigMapName )
627625
628- userCM , err := o .client .GetConfigmap (o .namespaceUserWorkload , o .userWorkloadConfigMapName )
626+ userCM , err := o .client .GetConfigmap (ctx , o .namespaceUserWorkload , o .userWorkloadConfigMapName )
629627 if err != nil {
630628 if apierrors .IsNotFound (err ) {
631629 klog .Warningf ("User Workload Monitoring %q ConfigMap not found. Using defaults." , cmKey )
@@ -676,7 +674,7 @@ func (o *Operator) loadConfig(key string) (*manifests.Config, error) {
676674 return cParsed , nil
677675}
678676
679- func (o * Operator ) Config (key string ) (* manifests.Config , error ) {
677+ func (o * Operator ) Config (ctx context. Context , key string ) (* manifests.Config , error ) {
680678 c , err := o .loadConfig (key )
681679 if err != nil {
682680 return nil , err
@@ -687,7 +685,7 @@ func (o *Operator) Config(key string) (*manifests.Config, error) {
687685 // loadConfig() already initializes the structs with nil values for
688686 // UserWorkloadConfiguration struct.
689687 if * c .ClusterMonitoringConfiguration .UserWorkloadEnabled {
690- c .UserWorkloadConfiguration , err = o .loadUserWorkloadConfig ()
688+ c .UserWorkloadConfiguration , err = o .loadUserWorkloadConfig (ctx )
691689 if err != nil {
692690 return nil , err
693691 }
@@ -696,29 +694,29 @@ func (o *Operator) Config(key string) (*manifests.Config, error) {
696694 // Only fetch the token and cluster ID if they have not been specified in the config.
697695 if c .ClusterMonitoringConfiguration .TelemeterClientConfig .ClusterID == "" || c .ClusterMonitoringConfiguration .TelemeterClientConfig .Token == "" {
698696 err := c .LoadClusterID (func () (* configv1.ClusterVersion , error ) {
699- return o .client .GetClusterVersion ("version" )
697+ return o .client .GetClusterVersion (ctx , "version" )
700698 })
701699
702700 if err != nil {
703701 klog .Warningf ("Could not fetch cluster version from API. Proceeding without it: %v" , err )
704702 }
705703
706704 err = c .LoadToken (func () (* v1.Secret , error ) {
707- return o .client .KubernetesInterface ().CoreV1 ().Secrets ("openshift-config" ).Get (o . ctx , "pull-secret" , metav1.GetOptions {})
705+ return o .client .KubernetesInterface ().CoreV1 ().Secrets ("openshift-config" ).Get (ctx , "pull-secret" , metav1.GetOptions {})
708706 })
709707
710708 if err != nil {
711709 klog .Warningf ("Error loading token from API. Proceeding without it: %v" , err )
712710 }
713711 }
714712
715- cm , err := o .client .GetConfigmap ("openshift-config" , "etcd-metric-serving-ca" )
713+ cm , err := o .client .GetConfigmap (ctx , "openshift-config" , "etcd-metric-serving-ca" )
716714 if err != nil {
717715 klog .Warningf ("Error loading etcd CA certificates for Prometheus. Proceeding with etcd disabled. Error: %v" , err )
718716 return c , nil
719717 }
720718
721- s , err := o .client .GetSecret ("openshift-config" , "etcd-metric-client" )
719+ s , err := o .client .GetSecret (ctx , "openshift-config" , "etcd-metric-client" )
722720 if err != nil {
723721 klog .Warningf ("Error loading etcd client secrets for Prometheus. Proceeding with etcd disabled. Error: %v" , err )
724722 return c , nil
0 commit comments