Skip to content

Conversation

@swatisehgal
Copy link
Contributor

@swatisehgal swatisehgal commented Oct 30, 2025

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().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.

Which issue(s) this PR is related to:

#130069

Does this PR introduce a user-facing change?

NONE

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>
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/kubelet area/test sig/node Categorizes an issue or PR as relevant to SIG Node. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 30, 2025
@ffromani
Copy link
Contributor

/triage accepted
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 31, 2025
Autogenerated by running:
```
./hack/update-mocks.sh
```
Signed-off-by: Swati Sehgal <swsehgal@redhat.com>
@swatisehgal swatisehgal force-pushed the node-cm-ctx-logging-migration branch from b002ba7 to 67280d4 Compare October 31, 2025 06:50
Signed-off-by: Swati Sehgal <swsehgal@redhat.com>
@swatisehgal swatisehgal force-pushed the node-cm-ctx-logging-migration branch from fc26905 to f225705 Compare October 31, 2025 08:14
@swatisehgal
Copy link
Contributor Author

@ffromani @bart0sh PTAL,this is ready for review!

Copy link
Contributor

@ffromani ffromani left a 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
Copy link
Contributor

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

Copy link
Contributor Author

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:

  1. The method doesn't need context for cancellation or deadlines - it's a simple synchronous update operation
  2. 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.

Copy link
Contributor

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>
@swatisehgal swatisehgal force-pushed the node-cm-ctx-logging-migration branch from c1ecefa to f2d075e Compare October 31, 2025 17:42
@ffromani
Copy link
Contributor

ffromani commented Nov 1, 2025

/lgtm

my comments have been addressed. Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 1, 2025
@ffromani
Copy link
Contributor

ffromani commented Nov 1, 2025

/retest

@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 34ca225f4a8acee745394a03c36f906fdbecad13

@k8s-ci-robot
Copy link
Contributor

@swatisehgal: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-e2e-capz-windows-master f2d075e link false /test pull-kubernetes-e2e-capz-windows-master

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.

@bart0sh bart0sh moved this from Triage to Needs Approver in SIG Node: code and documentation PRs Nov 1, 2025
@bart0sh
Copy link
Contributor

bart0sh commented Nov 1, 2025

/lgtm

/assign @ffromani @SergeyKanzhelev
for approval

@bart0sh
Copy link
Contributor

bart0sh commented Nov 1, 2025

/skip

Copy link
Contributor

@ffromani ffromani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@SergeyKanzhelev
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 3, 2025
@k8s-ci-robot k8s-ci-robot merged commit 4e84997 into kubernetes:master Nov 3, 2025
15 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.35 milestone Nov 3, 2025
@github-project-automation github-project-automation bot moved this from Needs Approver to Done in SIG Node: code and documentation PRs Nov 3, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in SIG Node CI/Test Board Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubelet area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note-none Denotes a PR that doesn't merit a release note. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Development

Successfully merging this pull request may close these issues.

5 participants