Skip to content

Migrate devicemanager to context logging (2/5) #132583

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

chuangw6
Copy link

@chuangw6 chuangw6 commented Jun 27, 2025

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Migrate pkg/kubelet/cm/devicemanager/topology_hints.go to context logging

Which issue(s) this PR is related to:

#130069

Special notes for your reviewer:

Until pkg/kubelet/cm/topologymanager/scope_pod.go is fully migrated, context.TODO is used to avoid exploding the PR size for just migrating devicemanager.

Does this PR introduce a user-facing change?

NONE

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


@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/L Denotes a PR that changes 100-499 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. labels Jun 27, 2025
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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 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 27, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @chuangw6. 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. sig/storage Categorizes an issue or PR as relevant to SIG Storage. wg/device-management Categorizes an issue or PR as relevant to WG Device Management. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 27, 2025
@k8s-ci-robot k8s-ci-robot requested review from bart0sh and klueska June 27, 2025 18:14
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 27, 2025
@chuangw6
Copy link
Author

@tallclair do you mind stamping ok-to-test

@chuangw6
Copy link
Author

/assign @tallclair

@ndixita
Copy link
Contributor

ndixita commented Jun 27, 2025

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 27, 2025
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 27, 2025
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 27, 2025
@chuangw6 chuangw6 force-pushed the ctx-log-2 branch 2 times, most recently from ff42d0e to 1b2dfda Compare June 27, 2025 19:24
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 27, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: chuangw6
Once this PR has been reviewed and has the lgtm label, please ask for approval from tallclair. 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

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 27, 2025
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 27, 2025
@@ -79,6 +79,8 @@ func (s *podScope) accumulateProvidersHints(pod *v1.Pod) []map[string][]Topology

for _, provider := range s.hintProviders {
// Get the TopologyHints for a Pod from a provider.
// TODO (https://github.com/kubernetes/kubernetes/issues/130069):
// Plumb context to GetTopologyHints when migrating global klog to context logging
Copy link
Contributor

Choose a reason for hiding this comment

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

What's global klog?

Copy link
Author

@chuangw6 chuangw6 Jun 30, 2025

Choose a reason for hiding this comment

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

@@ -17,7 +17,7 @@ limitations under the License.
package topologymanager

import (
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is out of scope of this PR, please remove.

Copy link
Author

Choose a reason for hiding this comment

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

I am unable to remove it. It seems to be added automatically by some formatter/sanity check when saving the file. https://github.com/search?q=repo%3Akubernetes%2Fkubernetes+%22v1+%5C%22k8s.io%2Fapi%2Fcore%2Fv1%5C%22%22&type=code

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like it's added by your editor, please consider removing as unrelated. Another editor can return the current import back.

@bart0sh
Copy link
Contributor

bart0sh commented Jun 29, 2025

@chuangw6 Thank you for your PR! Can you try to get rid of remaining context.Background and context.TODO calls where possible?

$ git grep 'context\.\(TODO\|Background\)' ./pkg/kubelet/cm/devicemanager/
pkg/kubelet/cm/devicemanager/endpoint.go:       return e.api.GetPreferredAllocation(context.Background(), &pluginapi.PreferredAllocationRequest{
pkg/kubelet/cm/devicemanager/endpoint.go:       return e.api.Allocate(context.Background(), &pluginapi.AllocateRequest{
pkg/kubelet/cm/devicemanager/endpoint.go:       ctx, cancel := context.WithTimeout(context.Background(), pluginapi.KubeletPreStartContainerRPCTimeoutInSecs*time.Second)
pkg/kubelet/cm/devicemanager/manager.go:        options, err := p.API().GetDevicePluginOptions(context.Background(), &pluginapi.Empty{})
pkg/kubelet/cm/devicemanager/plugin/v1beta1/client.go:  stream, err := c.client.ListAndWatch(context.Background(), &api.Empty{})
pkg/kubelet/cm/devicemanager/plugin/v1beta1/client.go:  ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
pkg/kubelet/cm/devicemanager/plugin/v1beta1/stub.go:                            err := wait.PollUntilContextTimeout(context.Background(), 10*time.Second, 2*time.Minute, false, func(context.Context) (done bool, err error) {
pkg/kubelet/cm/devicemanager/plugin/v1beta1/stub.go:    ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
pkg/kubelet/cm/devicemanager/plugin/v1beta1/stub.go:    _, err = client.Register(context.Background(), reqt)
pkg/kubelet/cm/devicemanager/topology_hints.go: logger := klog.FromContext(context.TODO())
pkg/kubelet/cm/devicemanager/topology_hints.go: logger := klog.FromContext(context.TODO())

@chuangw6
Copy link
Author

@bart0sh Thanks for review.

This PR is focused on pkg/kubelet/cm/devicemanager/topology_hints.go. I can try to do it in separate PR for other files under device manager.

Also note context.TODO() is explicitly used in topology_hints.go to avoid plumbing through ctx all over the places outside devicemanager because of the use of interface.

pkg/kubelet/cm/devicemanager/topology_hints.go: logger := klog.FromContext(context.TODO())
pkg/kubelet/cm/devicemanager/topology_hints.go: logger := klog.FromContext(context.TODO())

@chuangw6 chuangw6 requested a review from bart0sh June 30, 2025 21:29
@chuangw6
Copy link
Author

/test pull-kubernetes-unit-windows-master

@bart0sh
Copy link
Contributor

bart0sh commented Jul 1, 2025

This PR is focused on pkg/kubelet/cm/devicemanager/topology_hints.go. I can try to do it in separate PR for other files under device manager.

That would complicate review and approval and cause conflicts even in your future PRs for devicemanager. I'd suggest expanding the scope to at least one component. If you think device manager is too big for one PR, that's OK. You can start from it's sub-components, for example from pkg/kubelet/cm/devicemanager/plugin.

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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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/storage Categorizes an issue or PR as relevant to SIG Storage. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. wg/device-management Categorizes an issue or PR as relevant to WG Device Management.
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

5 participants