Skip to content

Add context-based warning suppression to SetEmulationVersion #133207

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

PersistentJZH
Copy link

@PersistentJZH PersistentJZH commented Jul 25, 2025

What type of PR is this?

/kind feature

What this PR does / why we need it:

implement a context logger to optimize the warning logic

Which issue(s) this PR is related to:

Fix: #133056

Special notes for your reviewer:

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 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 25, 2025
Copy link

linux-foundation-easycla bot commented Jul 25, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not 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 Jul 25, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @PersistentJZH!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@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 the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 25, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @PersistentJZH. 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 the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Jul 25, 2025
@k8s-ci-robot k8s-ci-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 25, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: PersistentJZH
Once this PR has been reviewed and has the lgtm label, please assign msau42 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

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jul 25, 2025
@k8s-triage-robot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@BenTheElder
Copy link
Member

/cc @Jefftree

@k8s-ci-robot k8s-ci-robot requested a review from Jefftree July 29, 2025 20:51
@Jefftree
Copy link
Member

/ok-to-test
/cc @michaelasp

@k8s-ci-robot k8s-ci-robot requested a review from michaelasp July 29, 2025 21:13
@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 Jul 29, 2025
@@ -165,6 +165,8 @@ type MutableVersionedFeatureGate interface {
// Otherwise, the emulationVersion will be the same as the binary version.
// If set, the feature defaults and availability will be as if the binary is at the emulated version.
SetEmulationVersion(emulationVersion *version.Version) error
// SetEmulationVersionWithContext is like SetEmulationVersion but accepts a context for controlling behavior.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should still describe the behavior in the function description, other functions may get changed or removed.

Copy link
Author

Choose a reason for hiding this comment

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

ok, will describe the behavior.

type testLoggerKey struct{}

// WithWarningSuppressionContext returns a context with warning suppression flag
func WithWarningSuppressionContext(ctx context.Context) context.Context {
Copy link
Contributor

Choose a reason for hiding this comment

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

Imo I think we should have a different method of suppressing the warning than passing the value in the context. We shouldn't really have a scenario outside of testing where this isn't logged. @pohly's suggestion of passing a per test logger for this makes sense.

Possibly even we should error on this if we don't pass some allow override since we are setting an already set flag which is unusual during normal operation.

I think we should likely go with passing in a logger for now and follow up on what to do if the emulated version is set multiple times for a feature.

Copy link
Author

Choose a reason for hiding this comment

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

thanks for @michaelasp's advice. I will use a context logger to optimize the logic and report an error if don't pass some allow override.

if err := gate.(featuregate.MutableVersionedFeatureGate).SetEmulationVersion(originalEmuVer); err != nil {
// Use context to suppress warnings during test cleanup
ctx := featuregate.WithWarningSuppressionContext(context.Background())
if err := gate.(featuregate.MutableVersionedFeatureGate).SetEmulationVersionWithContext(ctx, originalEmuVer); err != nil {
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 probably where we can pass some sort of logger that isn't spammy, we expect the values to be changed here so we could probably log to somewhere outside of the base klog.

…minate test noise

Signed-off-by: zhihao jian <[email protected]>

optimize SetEmulationVersionWithContext logic
@PersistentJZH PersistentJZH force-pushed the feat/enhance-warning-in-set-emulation-version branch from adbd958 to 463f95f Compare July 30, 2025 10:51
@PersistentJZH
Copy link
Author

@michaelasp thanks for code review. I have resolved all comments above, pls help to review again, thank you !

// warnings will be redirected to the test output instead of the global klog.
// If features would change and no test logger is provided, an error will be returned to prevent
// unexpected behavior in production environments.
SetEmulationVersionWithContext(ctx context.Context, emulationVersion *version.Version) error
Copy link
Member

Choose a reason for hiding this comment

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

I think adding a WithContext version here is really confusing ... can we do something more scoped to the single integration test call site that will use this that doesn't expand the interface for all callers?

Copy link
Author

@PersistentJZH PersistentJZH Jul 30, 2025

Choose a reason for hiding this comment

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

yup, add SetEmulationVersionWithContext func here is confusing, but there doesn't seem to be a more elegant way to do this.
Is it possible to use klog.FromContext(ctx) to implement different loggers for different envs? However, even if we use klog.FromContext(ctx), we still need an additional parameter or additional method to pass context info.

eg: change SetEmulationVersion(emulationVersion *version.Version) error to SetEmulationVersion(ctx context.Context, emulationVersion *version.Version) error

The changes here are very large and all callers need to be changed, but it is not impossible to do so. Do you have any idea about this? @liggitt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. 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/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SetEmulationVersion: enhance warning
7 participants