Skip to content

feat(kubelet): migrate kuberuntime to contextual logging #132427

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

soma00333
Copy link

@soma00333 soma00333 commented Jun 20, 2025

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR migrates the pkg/kubelet/kuberuntime package to use contextual logging as part of the ongoing effort to improve structured logging in Kubernetes.

The main changes include:

  • Replace all klog calls with contextual logging using logger from klog.FromContext(ctx)
  • Add context parameters to functions that need to pass context for logging
  • Update golangci-lint configuration files to enable contextual logging checks for kuberuntime
  • Update logcheck.conf to mark kuberuntime as using contextual logging
  • Update all test files to use ktesting.Init(t) for consistent logger initialization
  • Pass logger directly to short utility functions that only need logging functionality

Notable refactoring:

  • swapControllerAvailable: Refactored from a global sync.OnceValue variable to a field in kubeGenericRuntimeManager to eliminate context.TODO() usage. The implementation maintains lazy initialization using sync.OnceValue and ensures consistent design pattern throughout the codebase:
    • Added getSwapControllerAvailable func() bool field to kubeGenericRuntimeManager
    • Modified swapConfigurationHelper to accept getSwapControllerAvailable func() bool instead of eagerly evaluating the boolean value
    • This ensures lazy evaluation is consistent between kubeGenericRuntimeManager and swapConfigurationHelper

Please check the following documents

Which issue(s) this PR is related to:

Part of #130069

Special notes for your reviewer:

There are still 2 context.TODO() remaining in the package:

  • pkg/kubelet/kuberuntime/kuberuntime_manager.go:1612 (GeneratePodStatus)
  • pkg/kubelet/kuberuntime/util/util.go:31 (PodSandboxChanged)

These cannot be addressed in this PR because they are called from outside the kuberuntime package.

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. 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-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 20, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @soma00333. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added area/kubelet sig/node Categorizes an issue or PR as relevant to SIG Node. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 20, 2025
@k8s-ci-robot k8s-ci-robot requested review from pohly and tallclair June 20, 2025 11:58
@soma00333 soma00333 force-pushed the kuberuntime-contextual-logging-1 branch from 97ba55e to f043d19 Compare June 20, 2025 12:56
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 20, 2025
@soma00333 soma00333 force-pushed the kuberuntime-contextual-logging-1 branch from 1e1f5d0 to 89b884d Compare June 20, 2025 14:14
@soma00333 soma00333 marked this pull request as ready for review June 20, 2025 14:18
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 20, 2025
@bart0sh
Copy link
Contributor

bart0sh commented Jun 23, 2025

/triage accepted
/priority important-longterm
/ok-to-test
/assign

@soma00333 soma00333 force-pushed the kuberuntime-contextual-logging-1 branch 3 times, most recently from d7c88c4 to 54cfb79 Compare June 24, 2025 14:17
@bart0sh
Copy link
Contributor

bart0sh commented Jun 24, 2025

@soma00333 CI failure is fixed in master, please rebase.

@soma00333 soma00333 force-pushed the kuberuntime-contextual-logging-1 branch 2 times, most recently from 24facf1 to 350116a Compare June 25, 2025 10:13
@bart0sh
Copy link
Contributor

bart0sh commented Jun 25, 2025

/retest

@soma00333 soma00333 force-pushed the kuberuntime-contextual-logging-1 branch 3 times, most recently from ca08fb3 to 35a3e87 Compare June 26, 2025 10:18
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: soma00333
Once this PR has been reviewed and has the lgtm label, please assign dchen1107 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@soma00333 soma00333 force-pushed the kuberuntime-contextual-logging-1 branch from 35a3e87 to e67fad3 Compare June 26, 2025 10:27
@soma00333
Copy link
Author

/retest

1 similar comment
@bart0sh
Copy link
Contributor

bart0sh commented Jun 26, 2025

/retest

@bart0sh
Copy link
Contributor

bart0sh commented Jun 29, 2025

A couple of small nits, otherwise lgtm.

@soma00333 soma00333 force-pushed the kuberuntime-contextual-logging-1 branch from a4567eb to 8a9dbc1 Compare June 30, 2025 09:16
@bart0sh
Copy link
Contributor

bart0sh commented Jun 30, 2025

/lgtm

@soma00333 As your PR is quite big, I'd suggest to ask approvers on Slack or even on SIG-Node meeting to look at it. Otherwise it's going to be conflicting with other changes and you'll end up rebasing it again and again.

/assign @mrunalp @SergeyKanzhelev @dchen1107
for approval

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

LGTM label has been added.

Git tree hash: b1d7d3874ec8024f27428ca5cf9a8002a29fb166

@bart0sh bart0sh moved this from Needs Reviewer to Needs Approver in SIG Node: code and documentation PRs Jun 30, 2025
@soma00333
Copy link
Author

@bart0sh Thank you very much for your thoughtful review and valuable suggestions. I will.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Development

Successfully merging this pull request may close these issues.

6 participants