Skip to content

Commit 9b5be73

Browse files
committed
test criocp controller
1 parent d809870 commit 9b5be73

File tree

1 file changed

+82
-80
lines changed

1 file changed

+82
-80
lines changed

pkg/controller/container-runtime-config/container_runtime_config_controller.go

Lines changed: 82 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ type Controller struct {
133133

134134
fgHandler ctrlcommon.FeatureGatesHandler
135135

136-
queue workqueue.TypedRateLimitingInterface[string]
137-
imgQueue workqueue.TypedRateLimitingInterface[string]
138-
// criocpQueue workqueue.TypedRateLimitingInterface[string]
136+
queue workqueue.TypedRateLimitingInterface[string]
137+
imgQueue workqueue.TypedRateLimitingInterface[string]
138+
criocpQueue workqueue.TypedRateLimitingInterface[string]
139139
}
140140

141141
// New returns a new container runtime config controller
@@ -203,7 +203,7 @@ func New(
203203

204204
ctrl.syncHandler = ctrl.syncContainerRuntimeConfig
205205
ctrl.syncImgHandler = ctrl.syncImageConfig
206-
// ctrl.syncCRIOCPHandler = ctrl.syncCRIOCredentialProviderConfig
206+
ctrl.syncCRIOCPHandler = ctrl.syncCRIOCredentialProviderConfig
207207
ctrl.enqueueContainerRuntimeConfig = ctrl.enqueue
208208

209209
ctrl.mcpLister = mcpInformer.Lister()
@@ -243,7 +243,7 @@ func (ctrl *Controller) Run(workers int, stopCh <-chan struct{}) {
243243
defer utilruntime.HandleCrash()
244244
defer ctrl.queue.ShutDown()
245245
defer ctrl.imgQueue.ShutDown()
246-
// defer ctrl.criocpQueue.ShutDown()
246+
defer ctrl.criocpQueue.ShutDown()
247247
listerCaches := []cache.InformerSynced{ctrl.mcpListerSynced, ctrl.mccrListerSynced, ctrl.ccListerSynced,
248248
ctrl.imgListerSynced, ctrl.icspListerSynced, ctrl.idmsListerSynced, ctrl.itmsListerSynced, ctrl.clusterVersionListerSynced}
249249

@@ -259,7 +259,9 @@ func (ctrl *Controller) Run(workers int, stopCh <-chan struct{}) {
259259
klog.Info("added CRIOCredentialProviderConfig observers with CRIOCredentialProviderConfig featuregate enabled")
260260
}
261261

262-
ctrl.configInformerFactory.Start(stopCh)
262+
if ctrl.policyInformerFactoryAdded || ctrl.criocpInformerFactoryAdded {
263+
ctrl.configInformerFactory.Start(stopCh)
264+
}
263265

264266
if ctrl.policyInformerFactoryAdded {
265267
listerCaches = append(listerCaches, ctrl.clusterImagePolicyListerSynced, ctrl.imagePolicyListerSynced)
@@ -286,7 +288,7 @@ func (ctrl *Controller) Run(workers int, stopCh <-chan struct{}) {
286288
go wait.Until(ctrl.imgWorker, time.Second, stopCh)
287289

288290
// Just need one worker for the CRIOCredentialProviderConfig
289-
// go wait.Until(ctrl.criocpWorker, time.Second, stopCh)
291+
go wait.Until(ctrl.criocpWorker, time.Second, stopCh)
290292

291293
<-stopCh
292294
}
@@ -361,18 +363,18 @@ func (ctrl *Controller) addCRIOCPObservers() {
361363
}
362364

363365
func (ctrl *Controller) criocpConfAdded(_ interface{}) {
364-
ctrl.imgQueue.Add("openshift-config")
365-
// ctrl.criocpQueue.Add("openshift-config")
366+
// ctrl.imgQueue.Add("openshift-config")
367+
ctrl.criocpQueue.Add("openshift-config")
366368
}
367369

368370
func (ctrl *Controller) criocpConfUpdated(_, _ interface{}) {
369-
ctrl.imgQueue.Add("openshift-config")
370-
// ctrl.criocpQueue.Add("openshift-config")
371+
// ctrl.imgQueue.Add("openshift-config")
372+
ctrl.criocpQueue.Add("openshift-config")
371373
}
372374

373375
func (ctrl *Controller) criocpConfDeleted(_ interface{}) {
374-
ctrl.imgQueue.Add("openshift-config")
375-
// ctrl.criocpQueue.Add("openshift-config")
376+
// ctrl.imgQueue.Add("openshift-config")
377+
ctrl.criocpQueue.Add("openshift-config")
376378
}
377379

378380
func (ctrl *Controller) addImagePolicyObservers() {
@@ -506,10 +508,10 @@ func (ctrl *Controller) imgWorker() {
506508
}
507509
}
508510

509-
// func (ctrl *Controller) criocpWorker() {
510-
// for ctrl.processNextCRIOCPWorkItem() {
511-
// }
512-
// }
511+
func (ctrl *Controller) criocpWorker() {
512+
for ctrl.processNextCRIOCPWorkItem() {
513+
}
514+
}
513515

514516
func (ctrl *Controller) processNextWorkItem() bool {
515517
key, quit := ctrl.queue.Get()
@@ -537,18 +539,18 @@ func (ctrl *Controller) processNextImgWorkItem() bool {
537539
return true
538540
}
539541

540-
// func (ctrl *Controller) processNextCRIOCPWorkItem() bool {
541-
// key, quit := ctrl.criocpQueue.Get()
542-
// if quit {
543-
// return false
544-
// }
545-
// defer ctrl.criocpQueue.Done(key)
542+
func (ctrl *Controller) processNextCRIOCPWorkItem() bool {
543+
key, quit := ctrl.criocpQueue.Get()
544+
if quit {
545+
return false
546+
}
547+
defer ctrl.criocpQueue.Done(key)
546548

547-
// err := ctrl.syncCRIOCPHandler(key)
548-
// ctrl.handleCRIOCPErr(err, key)
549+
err := ctrl.syncCRIOCPHandler(key)
550+
ctrl.handleCRIOCPErr(err, key)
549551

550-
// return true
551-
// }
552+
return true
553+
}
552554

553555
func (ctrl *Controller) handleErr(err error, key string) {
554556
if err == nil {
@@ -586,23 +588,23 @@ func (ctrl *Controller) handleImgErr(err error, key string) {
586588
ctrl.imgQueue.AddAfter(key, 1*time.Minute)
587589
}
588590

589-
// func (ctrl *Controller) handleCRIOCPErr(err error, key string) {
590-
// if err == nil {
591-
// ctrl.criocpQueue.Forget(key)
592-
// return
593-
// }
591+
func (ctrl *Controller) handleCRIOCPErr(err error, key string) {
592+
if err == nil {
593+
ctrl.criocpQueue.Forget(key)
594+
return
595+
}
594596

595-
// if ctrl.criocpQueue.NumRequeues(key) < maxRetries {
596-
// klog.V(2).Infof("Error syncing CRIOCredentialProviderConfig %v: %v", key, err)
597-
// ctrl.criocpQueue.AddRateLimited(key)
598-
// return
599-
// }
597+
if ctrl.criocpQueue.NumRequeues(key) < maxRetries {
598+
klog.V(2).Infof("Error syncing CRIOCredentialProviderConfig %v: %v", key, err)
599+
ctrl.criocpQueue.AddRateLimited(key)
600+
return
601+
}
600602

601-
// utilruntime.HandleError(err)
602-
// klog.V(2).Infof("Dropping CRIOCredentialProviderConfig %q out of the queue: %v", key, err)
603-
// ctrl.criocpQueue.Forget(key)
604-
// ctrl.criocpQueue.AddAfter(key, 1*time.Minute)
605-
// }
603+
utilruntime.HandleError(err)
604+
klog.V(2).Infof("Dropping CRIOCredentialProviderConfig %q out of the queue: %v", key, err)
605+
ctrl.criocpQueue.Forget(key)
606+
ctrl.criocpQueue.AddAfter(key, 1*time.Minute)
607+
}
606608

607609
// generateOriginalContainerRuntimeConfigs returns rendered default storage, registries and policy config files
608610
func generateOriginalContainerRuntimeConfigs(templateDir string, cc *mcfgv1.ControllerConfig, role string) (*ign3types.File, *ign3types.File, *ign3types.File, error) {
@@ -1206,44 +1208,44 @@ func (ctrl *Controller) syncImageConfig(key string) error {
12061208
return nil
12071209
}
12081210

1209-
// func (ctrl *Controller) syncCRIOCredentialProviderConfig(key string) error {
1210-
// startTime := time.Now()
1211-
// klog.V(4).Infof("Started syncing CRIOCredentialProvider config %q (%v)", key, startTime)
1212-
// defer func() {
1213-
// klog.V(4).Infof("Finished syncing CRIOCredentialProvider config %q (%v)", key, time.Since(startTime))
1214-
// }()
1215-
1216-
// // Get ControllerConfig
1217-
// controllerConfig, err := ctrl.ccLister.Get(ctrlcommon.ControllerConfigName)
1218-
// if err != nil {
1219-
// return fmt.Errorf("could not get ControllerConfig %w", err)
1220-
// }
1221-
1222-
// sel, err := metav1.LabelSelectorAsSelector(metav1.AddLabelToSelector(&metav1.LabelSelector{}, builtInLabelKey, ""))
1223-
// if err != nil {
1224-
// return err
1225-
// }
1226-
// // Find all the MCO built in MachineConfigPools
1227-
// mcpPools, err := ctrl.mcpLister.List(sel)
1228-
// if err != nil {
1229-
// return err
1230-
// }
1231-
1232-
// for _, pool := range mcpPools {
1233-
// role := pool.Name
1234-
// credProviderConfigIgn, err := generateOriginalCredentialProviderConfig(ctrl.templatesDir, controllerConfig, role)
1235-
// if err != nil {
1236-
// return fmt.Errorf("could not generate original CRIO credential provider config for role %s: %w", role, err)
1237-
// }
1238-
// contents, err := ctrlcommon.DecodeIgnitionFileContents(credProviderConfigIgn.Contents.Source, credProviderConfigIgn.Contents.Compression)
1239-
// if err != nil {
1240-
// return fmt.Errorf("could not decode CRIO credential provider config for role %s: %w", role, err)
1241-
// }
1242-
// klog.Infof("Decoded CRIO credential provider config contents successfully for role %s: %s", role, string(contents))
1243-
// }
1244-
1245-
// return nil
1246-
// }
1211+
func (ctrl *Controller) syncCRIOCredentialProviderConfig(key string) error {
1212+
startTime := time.Now()
1213+
klog.Infof("Started syncing CRIOCredentialProvider config %q (%v)", key, startTime)
1214+
defer func() {
1215+
klog.V(4).Infof("Finished syncing CRIOCredentialProvider config %q (%v)", key, time.Since(startTime))
1216+
}()
1217+
1218+
// // Get ControllerConfig
1219+
// controllerConfig, err := ctrl.ccLister.Get(ctrlcommon.ControllerConfigName)
1220+
// if err != nil {
1221+
// return fmt.Errorf("could not get ControllerConfig %w", err)
1222+
// }
1223+
1224+
// sel, err := metav1.LabelSelectorAsSelector(metav1.AddLabelToSelector(&metav1.LabelSelector{}, builtInLabelKey, ""))
1225+
// if err != nil {
1226+
// return err
1227+
// }
1228+
// // Find all the MCO built in MachineConfigPools
1229+
// mcpPools, err := ctrl.mcpLister.List(sel)
1230+
// if err != nil {
1231+
// return err
1232+
// }
1233+
1234+
// for _, pool := range mcpPools {
1235+
// role := pool.Name
1236+
// credProviderConfigIgn, err := generateOriginalCredentialProviderConfig(ctrl.templatesDir, controllerConfig, role)
1237+
// if err != nil {
1238+
// return fmt.Errorf("could not generate original CRIO credential provider config for role %s: %w", role, err)
1239+
// }
1240+
// contents, err := ctrlcommon.DecodeIgnitionFileContents(credProviderConfigIgn.Contents.Source, credProviderConfigIgn.Contents.Compression)
1241+
// if err != nil {
1242+
// return fmt.Errorf("could not decode CRIO credential provider config for role %s: %w", role, err)
1243+
// }
1244+
// klog.Infof("Decoded CRIO credential provider config contents successfully for role %s: %s", role, string(contents))
1245+
// }
1246+
1247+
return nil
1248+
}
12471249

12481250
func (ctrl *Controller) syncIgnitionConfig(managedKey string, ignFile *ign3types.Config, pool *mcfgv1.MachineConfigPool, ownerRef metav1.OwnerReference) (bool, error) {
12491251
rawIgn, err := json.Marshal(ignFile)

0 commit comments

Comments
 (0)