refactor(apiextensions-apiserver): Make finalizingController controller context-aware

This commit is contained in:
Aditi Gupta
2025-10-06 21:17:42 -07:00
parent 9998041e0f
commit 23209fc098
2 changed files with 8 additions and 5 deletions

View File

@@ -246,7 +246,7 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget)
go establishingController.RunWithContext(hookContext)
go nonStructuralSchemaController.RunWithContext(5, hookContext)
go apiApprovalController.RunWithContext(5, hookContext)
go finalizingController.Run(5, hookContext.Done())
go finalizingController.RunWithContext(5, hookContext)
discoverySyncedCh := make(chan struct{})
go discoveryController.Run(hookContext.Done(), discoverySyncedCh)

View File

@@ -242,7 +242,7 @@ func (c *CRDFinalizer) deleteInstances(ctx context.Context, crd *apiextensionsv1
if len(listObj.(*unstructured.UnstructuredList).Items) == 0 {
return true, nil
}
klog.V(2).Infof("%s.%s waiting for %d items to be removed", crd.Status.AcceptedNames.Plural, crd.Spec.Group, len(listObj.(*unstructured.UnstructuredList).Items))
klog.FromContext(ctx).V(2).Info("Waiting for items to be removed", "resource", crd.Status.AcceptedNames.Plural, "group", crd.Spec.Group, "count", len(listObj.(*unstructured.UnstructuredList).Items))
return false, nil
})
if err != nil {
@@ -261,17 +261,20 @@ func (c *CRDFinalizer) deleteInstances(ctx context.Context, crd *apiextensionsv1
}, nil
}
// Run is a legacy wrapper that starts the controller.
//
//logcheck:context // RunWithContext should be used instead of Run in code which supports contextual logging.
func (c *CRDFinalizer) Run(workers int, stopCh <-chan struct{}) {
c.RunWithContext(workers, wait.ContextForChannel(stopCh))
}
//logcheck:context // RunWithContext should be used instead of Run in code which supports contextual logging.
func (c *CRDFinalizer) RunWithContext(workers int, ctx context.Context) {
defer utilruntime.HandleCrash()
defer c.queue.ShutDown()
klog.Info("Starting CRDFinalizer")
defer klog.Info("Shutting down CRDFinalizer")
logger := klog.FromContext(ctx)
logger.Info("Starting CRDFinalizer")
defer logger.Info("Shutting down CRDFinalizer")
if !cache.WaitForCacheSync(ctx.Done(), c.crdSynced) {
return