- 
                Notifications
    
You must be signed in to change notification settings  - Fork 41.6k
 
node: cm: migrate container manager to contextual logging #134985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
node: cm: migrate container manager to contextual logging #134985
Conversation
This commit migrates the container manager package to use
contextual logging.
This follows the contextual logging migration pattern where:
- Logger is passed from the boundary down to implementations
- klog.TODO() is used at call sites where context is not yet available
- Functions with context.Context extract logger via klog.FromContext(ctx)
- klog.InfoS/ErrorS/V().InfoS calls are replaced with logger.Info/Error/V().Info
- Sub-managers receive proper logger context from their callers
Some call sites still use klog.TODO() as placeholders, with TODO
comments indicating these will be replaced with proper contextual loggers
as the migration continues upward through the call stack.
Test/fake implementations use klog.Background() which is the appropriate
choice for test code where no real context is available.
Mock file updates (pkg/kubelet/cm/testing/mocks.go) were done manually
due to mockery tool incompatibility with Go 1.25 and will be committed
separately with an explanation.
Key changes:
1. PodContainerManager and ContainerManager interface updates:
   - PodContainerManager.EnsureExists: add logger parameter
   - PodContainerManager.Destroy: add logger parameter
   - PodContainerManager.ReduceCPULimits: add logger parameter
   - PodContainerManager.SetPodCgroupConfig: add logger parameter
   - ContainerManager.UpdateQOSCgroups: add logger parameter
   - Update all implementations (Linux, Windows, stub, noop, fake)
2. Helper function updates:
   - GetKubeletContainer: add logger parameter (Linux and unsupported platforms)
   - Update cmd/kubelet/app/server.go to pass logger to GetKubeletContainer
   - Comment out type assertion in helpers.go due to signature change
3. Cgroup manager contextual logging:
   - CgroupManager interface methods updated to accept logger:
     * Destroy: add logger parameter
     * ReduceCPULimits: add logger parameter
     * SetCgroupConfig: add logger parameter
   - Update cgroupCommon and unsupportedCgroupManager implementations
   - Migrate klog.InfoS/V().InfoS calls to logger.Info/V().Info
4. Container manager implementation updates:
   - Extract logger from context in NewContainerManager() and Start()
   - Pass logger to sub-managers (deviceManager, topologyManager)
   - Update DRA manager initialization to use logger from context
   - Migrate klog.InfoS/ErrorS to logger.Info/Error throughout
5. Call sites updated with TODO comments:
   - pkg/kubelet/kubelet.go: UpdateQOSCgroups, EnsureExists
   - pkg/kubelet/kubelet_pods.go: UpdateQOSCgroups, ReduceCPULimits, Destroy
   - pkg/kubelet/kuberuntime/kuberuntime_manager.go: SetPodCgroupConfig
   - pkg/kubelet/kuberuntime/kuberuntime_manager_test.go: test expectations
Most call sites currently use klog.TODO() as placeholders, with TODO
comments indicating these will be replaced with proper contextual loggers
as the migration continues upward through the call stack.
Test/fake implementations use klog.Background() which is the appropriate
choice for test code where no real context is available.
Mock file updates (pkg/kubelet/cm/testing/mocks.go) were done manually
due to mockery tool incompatibility with Go 1.25 and will be committed
separately with an explanation.
Signed-off-by: Swati Sehgal <swsehgal@redhat.com>
    | 
           /triage accepted  | 
    
Autogenerated by running: ``` ./hack/update-mocks.sh ``` Signed-off-by: Swati Sehgal <swsehgal@redhat.com>
b002ba7    to
    67280d4      
    Compare
  
    Signed-off-by: Swati Sehgal <swsehgal@redhat.com>
fc26905    to
    f225705      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few inline comments, but overall LGTM
like in other instances, I for one I'm not completely happy with the context/logger call chain, but I think is better to complete the porting and iterate later rather than dive into details at this stage. The current changeset is still an improvement.
| Start(context.Context, func() v1.ResourceList, ActivePodsFunc) error | ||
| GetQOSContainersInfo() QOSContainersInfo | ||
| UpdateCgroups() error | ||
| UpdateCgroups(logger klog.Logger) error | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure but this can probably use a context? we can also fix later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion here. I chose klog.Logger here because:
- The method doesn't need context for cancellation or deadlines - it's a simple synchronous update operation
 - It maintains consistency with the current pattern where we're passing loggers to methods that only need them for logging
 
We can keep it as-is with klog.Logger for now since it works, but I'm open to changing it to context if you prefer that approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under the impression that UpdateCgroups ultimately needs a Context as it ends up writing on sysfs through vendored packages; but if the context plumbing was not done yet, there's no ne need to do it now so we can leave as-is and we can re-evaluate later.
Signed-off-by: Swati Sehgal <swsehgal@redhat.com>
c1ecefa    to
    f2d075e      
    Compare
  
    | 
           /lgtm my comments have been addressed. Thanks!  | 
    
| 
           /retest  | 
    
| 
           LGTM label has been added. Git tree hash: 34ca225f4a8acee745394a03c36f906fdbecad13 
       | 
    
| 
           @swatisehgal: The following test failed, say  
 Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.  | 
    
| 
           /lgtm /assign @ffromani @SergeyKanzhelev  | 
    
| 
           /skip  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
| 
           /approve  | 
    
| 
           [APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ffromani, SergeyKanzhelev, swatisehgal The full list of commands accepted by this bot can be found here. The pull request process is described here 
Needs approval from an approver in each of these files:
 
      
 Approvers can indicate their approval by writing   | 
    
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
This commit migrates the container manager package to use contextual logging.
This follows the contextual logging migration pattern where:
- Logger is passed from the boundary down to implementations
-
klog.TODO()is used at call sites where context is not yet available- Functions with context.Context extract logger via
klog.FromContext(ctx)-
klog.InfoS/ErrorS/V().InfoScalls are replaced with logger.Info/Error/V().Info- Sub-managers receive proper logger context from their callers
Some call sites still use
klog.TODO()as placeholders, with TODOcomments indicating these will be replaced with proper contextual loggers
as the migration continues upward through the call stack.
Test/fake implementations use
klog.Background()which is the appropriatechoice for test code where no real context is available.
Which issue(s) this PR is related to:
#130069
Does this PR introduce a user-facing change?