refactor(controller): Use WithContext variants in cloud node controllers

This change refactors the cloud-specific versions of the node lifecycle
and node IPAM controllers to use a context.Context for cancellation and
contextual logging, replacing the legacy stopCh pattern.

This is a follow-up to PR #133985, where these controllers were
separated out due to their use in the legacy Cloud Controller Manager
(CCM).

It is a known issue that the CCM's startup logic does not pass the
controller name via the context. This change proceeds with the
refactoring to unify the cancellation logic across controllers, while
acknowledging that contextual logs will be less detailed when these
controllers are run in the CCM.

Signed-off-by: Aditi Gupta <aditigpta@google.com>
This commit is contained in:
Aditi Gupta 2025-09-16 23:48:02 -07:00
parent 69aca29e6d
commit f58d1e101f
4 changed files with 3 additions and 4 deletions

View file

@ -36,7 +36,6 @@ package names
// 2.1. [TODO] logging should use a canonical controller name when referencing a controller (Eg. Starting X, Shutting down X)
// 2.2. [TODO] emitted events should have an EventSource.Component set to the controller name (usually when initializing an EventRecorder)
// 2.3. [TODO] registering ControllerManagerMetrics with ControllerStarted and ControllerStopped
// 2.4. [TODO] calling WaitForNamedCacheSync
// 3. defining controller options for "--help" command or generated documentation
// 3.1. controller name should be used to create a pflag.FlagSet when registering controller options (the name is rendered in a controller flag group header) in options.KubeControllerManagerOptions
// 3.2. when defined flag's help mentions a controller name

View file

@ -183,7 +183,7 @@ func (r *rangeAllocator) Run(ctx context.Context) {
logger.Info("Starting range CIDR allocator")
defer logger.Info("Shutting down range CIDR allocator")
if !cache.WaitForNamedCacheSync("cidrallocator", ctx.Done(), r.nodesSynced) {
if !cache.WaitForNamedCacheSyncWithContext(ctx, r.nodesSynced) {
return
}

View file

@ -141,7 +141,7 @@ func (nc *Controller) Run(ctx context.Context) {
klog.FromContext(ctx).Info("Starting ipam controller")
defer klog.FromContext(ctx).Info("Shutting down ipam controller")
if !cache.WaitForNamedCacheSync("node", ctx.Done(), nc.nodeInformerSynced) {
if !cache.WaitForNamedCacheSyncWithContext(ctx, nc.nodeInformerSynced) {
return
}

View file

@ -464,7 +464,7 @@ func (nc *Controller) Run(ctx context.Context) {
logger.Info("Starting node controller")
defer logger.Info("Shutting down node controller")
if !cache.WaitForNamedCacheSync("taint", ctx.Done(), nc.leaseInformerSynced, nc.nodeInformerSynced, nc.podInformerSynced, nc.daemonSetInformerSynced) {
if !cache.WaitForNamedCacheSyncWithContext(ctx, nc.leaseInformerSynced, nc.nodeInformerSynced, nc.podInformerSynced, nc.daemonSetInformerSynced) {
return
}