@@ -90,7 +90,7 @@ type ConfigMapReconciler struct {
9090}
9191
9292// NewConfigMapReconciler returns a pointer to a ConfigMapReconciler
93- func NewConfigMapReconciler (mgr manager.Manager , clusterConfig cluster.Config , watchNamespace string ,
93+ func NewConfigMapReconciler (ctx context. Context , mgr manager.Manager , clusterConfig cluster.Config , watchNamespace string ,
9494 proxyEnabled bool ) (* ConfigMapReconciler , error ) {
9595 clientset , err := kubernetes .NewForConfig (mgr .GetConfig ())
9696 if err != nil {
@@ -101,7 +101,7 @@ func NewConfigMapReconciler(mgr manager.Manager, clusterConfig cluster.Config, w
101101 if err != nil {
102102 return nil , err
103103 }
104- svcData , err := generateServicesManifest (directClient , clusterConfig .Network ().VXLANPort (), clusterConfig .Platform ())
104+ svcData , err := generateServicesManifest (ctx , directClient , clusterConfig .Network ().VXLANPort (), clusterConfig .Platform ())
105105 if err != nil {
106106 return nil , err
107107 }
@@ -132,22 +132,22 @@ func (r *ConfigMapReconciler) Reconcile(ctx context.Context,
132132
133133 var err error
134134 // Prevent WMCO upgrades while BYOH nodes are being processed.
135- if err := condition .MarkAsBusy (r .client , r .watchNamespace , r .recorder , ConfigMapController ); err != nil {
135+ if err := condition .MarkAsBusy (ctx , r .client , r .watchNamespace , r .recorder , ConfigMapController ); err != nil {
136136 return ctrl.Result {}, err
137137 }
138138 defer func () {
139- reconcileErr = markAsFreeOnSuccess (r .client , r .watchNamespace , r .recorder , ConfigMapController ,
139+ reconcileErr = markAsFreeOnSuccess (ctx , r .client , r .watchNamespace , r .recorder , ConfigMapController ,
140140 result .Requeue , reconcileErr )
141141 }()
142142
143143 // Create a new signer using the private key that the instances will be configured with
144- r .signer , err = signer .Create (kubeTypes.NamespacedName {Namespace : r .watchNamespace ,
144+ r .signer , err = signer .Create (ctx , kubeTypes.NamespacedName {Namespace : r .watchNamespace ,
145145 Name : secrets .PrivateKeySecret }, r .client )
146146 if err != nil {
147147 return ctrl.Result {}, fmt .Errorf ("unable to create signer from private key secret: %w" , err )
148148 }
149149
150- servicesManifest , err := generateServicesManifest (r .client , r .VXLANPort , r .platform )
150+ servicesManifest , err := generateServicesManifest (ctx , r .client , r .VXLANPort , r .platform )
151151 if err != nil {
152152 return ctrl.Result {}, err
153153 }
@@ -273,23 +273,23 @@ func (r *ConfigMapReconciler) reconcileNodes(ctx context.Context, windowsInstanc
273273
274274 r .log .Info ("processing" , "instances in" , wiparser .InstanceConfigMap )
275275 // For each instance, ensure that it is configured into a node
276- if err := r .ensureInstancesAreUpToDate (instances ); err != nil {
276+ if err := r .ensureInstancesAreUpToDate (ctx , instances ); err != nil {
277277 r .recorder .Eventf (windowsInstances , core .EventTypeWarning , "InstanceSetupFailure" , err .Error ())
278278 return err
279279 }
280280
281281 // Ensure that only instances currently specified by the ConfigMap are joined to the cluster as nodes
282- if err = r .deconfigureInstances (instances , nodes ); err != nil {
282+ if err = r .deconfigureInstances (ctx , instances , nodes ); err != nil {
283283 return fmt .Errorf ("error removing undesired nodes from cluster: %w" , err )
284284 }
285285
286286 return nil
287287}
288288
289289// ensureInstancesAreUpToDate configures all instances that require configuration
290- func (r * ConfigMapReconciler ) ensureInstancesAreUpToDate (instances []* instance.Info ) error {
290+ func (r * ConfigMapReconciler ) ensureInstancesAreUpToDate (ctx context. Context , instances []* instance.Info ) error {
291291 // Get private key to encrypt instance usernames
292- privateKeyBytes , err := secrets .GetPrivateKey (kubeTypes.NamespacedName {Namespace : r .watchNamespace ,
292+ privateKeyBytes , err := secrets .GetPrivateKey (ctx , kubeTypes.NamespacedName {Namespace : r .watchNamespace ,
293293 Name : secrets .PrivateKeySecret }, r .client )
294294 if err != nil {
295295 return err
@@ -304,7 +304,7 @@ func (r *ConfigMapReconciler) ensureInstancesAreUpToDate(instances []*instance.I
304304 if err != nil {
305305 return fmt .Errorf ("unable to encrypt username for instance %s: %w" , instanceInfo .Address , err )
306306 }
307- err = r .ensureInstanceIsUpToDate (instanceInfo , map [string ]string {BYOHLabel : "true" , nodeconfig .WorkerLabel : "" },
307+ err = r .ensureInstanceIsUpToDate (ctx , instanceInfo , map [string ]string {BYOHLabel : "true" , nodeconfig .WorkerLabel : "" },
308308 map [string ]string {UsernameAnnotation : encryptedUsername })
309309 if err != nil {
310310 // It is better to return early like this, instead of trying to configure as many instances as possible in a
@@ -321,7 +321,7 @@ func (r *ConfigMapReconciler) ensureInstancesAreUpToDate(instances []*instance.I
321321
322322// deconfigureInstances removes all BYOH nodes that are not specified in the given instances slice, and
323323// deconfigures the instances associated with them. The nodes parameter should be a list of all Windows BYOH nodes.
324- func (r * ConfigMapReconciler ) deconfigureInstances (instances []* instance.Info , nodes * core.NodeList ) error {
324+ func (r * ConfigMapReconciler ) deconfigureInstances (ctx context. Context , instances []* instance.Info , nodes * core.NodeList ) error {
325325 windowsInstances := & core.ConfigMap {ObjectMeta : meta.ObjectMeta {Name : wiparser .InstanceConfigMap ,
326326 Namespace : r .watchNamespace }}
327327 for _ , node := range nodes .Items {
@@ -331,7 +331,7 @@ func (r *ConfigMapReconciler) deconfigureInstances(instances []*instance.Info, n
331331 }
332332
333333 // no instance found in the provided list, remove the node from the cluster
334- if err := r .deconfigureInstance (& node ); err != nil {
334+ if err := r .deconfigureInstance (ctx , & node ); err != nil {
335335 return fmt .Errorf ("unable to deconfigure instance with node %s: %w" , node .GetName (), err )
336336 }
337337 r .recorder .Eventf (windowsInstances , core .EventTypeNormal , "InstanceTeardown" ,
@@ -451,12 +451,12 @@ func (r *ConfigMapReconciler) createServicesConfigMap(ctx context.Context) (*cor
451451// createServicesConfigMapOnBootup creates a valid ServicesConfigMap
452452// ConfigMapReconciler.createServicesConfigMap() cannot be used in its stead as the cache has not been
453453// populated yet, which is why the typed client is used here as it calls the API server directly.
454- func (r * ConfigMapReconciler ) createServicesConfigMapOnBootup () error {
454+ func (r * ConfigMapReconciler ) createServicesConfigMapOnBootup (ctx context. Context ) error {
455455 windowsServices , err := servicescm .Generate (servicescm .Name , r .watchNamespace , r .servicesManifest )
456456 if err != nil {
457457 return err
458458 }
459- cm , err := r .k8sclientset .CoreV1 ().ConfigMaps (r .watchNamespace ).Create (context . TODO () , windowsServices ,
459+ cm , err := r .k8sclientset .CoreV1 ().ConfigMaps (r .watchNamespace ).Create (ctx , windowsServices ,
460460 meta.CreateOptions {})
461461 if err != nil {
462462 return err
@@ -466,13 +466,13 @@ func (r *ConfigMapReconciler) createServicesConfigMapOnBootup() error {
466466}
467467
468468// EnsureServicesConfigMapExists ensures that the ServicesConfigMap is present and valid on operator bootup
469- func (r * ConfigMapReconciler ) EnsureServicesConfigMapExists () error {
470- windowsServices , err := r .k8sclientset .CoreV1 ().ConfigMaps (r .watchNamespace ).Get (context . TODO () , servicescm .Name ,
469+ func (r * ConfigMapReconciler ) EnsureServicesConfigMapExists (ctx context. Context ) error {
470+ windowsServices , err := r .k8sclientset .CoreV1 ().ConfigMaps (r .watchNamespace ).Get (ctx , servicescm .Name ,
471471 meta.GetOptions {})
472472 if err != nil {
473473 if k8sapierrors .IsNotFound (err ) {
474474 // If ConfigMap is not found, create it and return
475- return r .createServicesConfigMapOnBootup ()
475+ return r .createServicesConfigMapOnBootup (ctx )
476476 }
477477 return err
478478 }
@@ -484,13 +484,13 @@ func (r *ConfigMapReconciler) EnsureServicesConfigMapExists() error {
484484 }
485485
486486 // Delete and re-create the ConfigMap with the proper values
487- if err = r .k8sclientset .CoreV1 ().ConfigMaps (r .watchNamespace ).Delete (context . TODO () , windowsServices .Name ,
487+ if err = r .k8sclientset .CoreV1 ().ConfigMaps (r .watchNamespace ).Delete (ctx , windowsServices .Name ,
488488 meta.DeleteOptions {}); err != nil {
489489 return err
490490 }
491491 r .log .Info ("Deleted invalid resource" , "ConfigMap" ,
492492 kubeTypes.NamespacedName {Namespace : r .watchNamespace , Name : servicescm .Name })
493- return r .createServicesConfigMapOnBootup ()
493+ return r .createServicesConfigMapOnBootup (ctx )
494494}
495495
496496// createProxyCertsCM creates the trusted CA ConfigMap with the expected spec
@@ -529,7 +529,7 @@ func (r *ConfigMapReconciler) ensureTrustedCABundleInNodes(ctx context.Context)
529529
530530// ensureTrustedCABundleInNodes places the trusted CA bundle data into a file on the given node
531531func (r * ConfigMapReconciler ) ensureTrustedCABundleInNode (ctx context.Context , node core.Node ) error {
532- winInstance , err := r .instanceFromNode (& node )
532+ winInstance , err := r .instanceFromNode (ctx , & node )
533533 if err != nil {
534534 return err
535535 }
@@ -538,7 +538,7 @@ func (r *ConfigMapReconciler) ensureTrustedCABundleInNode(ctx context.Context, n
538538 if err != nil {
539539 return fmt .Errorf ("failed to create new nodeconfig: %w" , err )
540540 }
541- return nc .SyncTrustedCABundle ()
541+ return nc .SyncTrustedCABundle (ctx )
542542}
543543
544544// ensureProxyCertsCMIsValid ensures the trusted CA ConfigMap has the expected injection request. Patches the object if not.
@@ -555,7 +555,7 @@ func (r *ConfigMapReconciler) ensureProxyCertsCMIsValid(ctx context.Context, inj
555555 return fmt .Errorf ("unable to generate patch request body for label %s: %w" , InjectionRequestLabel , err )
556556 }
557557
558- if _ , err = r .k8sclientset .CoreV1 ().ConfigMaps (r .watchNamespace ).Patch (context . TODO () ,
558+ if _ , err = r .k8sclientset .CoreV1 ().ConfigMaps (r .watchNamespace ).Patch (ctx ,
559559 certificates .ProxyCertsConfigMap , kubeTypes .JSONPatchType , patchData , meta.PatchOptions {}); err != nil {
560560 return fmt .Errorf ("unable to apply patch %s to resource %s/%s: %w" , patchData , r .watchNamespace ,
561561 certificates .ProxyCertsConfigMap , err )
@@ -566,16 +566,16 @@ func (r *ConfigMapReconciler) ensureProxyCertsCMIsValid(ctx context.Context, inj
566566
567567// EnsureTrustedCAConfigMapExists ensures the trusted CA ConfigMap exists as expected.
568568// Creates it if it doesn't exist, patches it if it exists with improper spec.
569- func (r * ConfigMapReconciler ) EnsureTrustedCAConfigMapExists () error {
570- trustedCA , err := r .k8sclientset .CoreV1 ().ConfigMaps (r .watchNamespace ).Get (context . TODO () ,
569+ func (r * ConfigMapReconciler ) EnsureTrustedCAConfigMapExists (ctx context. Context ) error {
570+ trustedCA , err := r .k8sclientset .CoreV1 ().ConfigMaps (r .watchNamespace ).Get (ctx ,
571571 certificates .ProxyCertsConfigMap , meta.GetOptions {})
572572 if err != nil {
573573 if ! k8sapierrors .IsNotFound (err ) {
574574 return err
575575 }
576- return r .createProxyCertsCM (context . TODO () )
576+ return r .createProxyCertsCM (ctx )
577577 }
578- return r .ensureProxyCertsCMIsValid (context . TODO () , trustedCA .GetLabels ()[InjectionRequestLabel ])
578+ return r .ensureProxyCertsCMIsValid (ctx , trustedCA .GetLabels ()[InjectionRequestLabel ])
579579}
580580
581581// EnsureWICDRBAC ensures the WICD RBAC resources exist as expected
@@ -691,8 +691,8 @@ func (r *ConfigMapReconciler) ensureWICDClusterRoleBinding(ctx context.Context)
691691// generateServicesManifest generates and regenerates the services manifest.
692692// this gets called when the configmap reconciler is first created, to create the services manifest,
693693// and also when the rendered-worker configmap is changed, to regenerate it.
694- func generateServicesManifest (client client.Client , port string , platform oconfig.PlatformType ) (* servicescm.Data , error ) {
695- ign , err := ignition .New (client )
694+ func generateServicesManifest (ctx context. Context , client client.Client , port string , platform oconfig.PlatformType ) (* servicescm.Data , error ) {
695+ ign , err := ignition .New (ctx , client )
696696 if err != nil {
697697 return nil , fmt .Errorf ("error creating ignition object: %w" , err )
698698 }
0 commit comments