Skip to content
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

✨ clusterctl: Suppress "finalizer name" API warnings in "move" command #11173

Merged

Conversation

dlipovetsky
Copy link
Contributor

@dlipovetsky dlipovetsky commented Sep 11, 2024

What this PR does / why we need it:
As described in #10932, the move command shows, when talking to Kubernetes 1.29.0 or newer, API server warnings related to Cluster API's finalizer names. These are shown at the default verbosity; in fact, verbosity cannot hide them at the moment.

This PR adds the flag --hide-api-warnings to the move command. By default, the flag is set to true, so API warnings are hidden. The user can reveal warnings by setting the flag to false.

Here is an example of the move command output with the flag set to false; this is equivalent to the output prior to this PR:

> bin/clusterctl move --hide-api-warnings-false --to-kubeconfig=capi-quickstart.conf
Performing move...
Discovering Cluster API objects
Moving Cluster API objects Clusters=1
Moving Cluster API objects ClusterClasses=1
Waiting for all resources to be ready to move
Creating objects in the target cluster
[KubeAPIWarningLogger] metadata.finalizers: "cluster.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[KubeAPIWarningLogger] Cluster refers to ClusterClass default/quick-start, but this ClusterClass hasn't been successfully reconciled. Cluster topology has not been fully validated. Please take a look at the ClusterClass status
[KubeAPIWarningLogger] metadata.finalizers: "dockercluster.infrastructure.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[KubeAPIWarningLogger] metadata.finalizers: "machinedeployment.topology.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[KubeAPIWarningLogger] metadata.finalizers: "machinepool.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[KubeAPIWarningLogger] metadata.finalizers: "kubeadm.controlplane.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[KubeAPIWarningLogger] metadata.finalizers: "machine.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[KubeAPIWarningLogger] metadata.finalizers: "dockermachinepool.infrastructure.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[KubeAPIWarningLogger] metadata.finalizers: "machineset.topology.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[KubeAPIWarningLogger] metadata.finalizers: "dockermachine.infrastructure.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[KubeAPIWarningLogger] metadata.finalizers: "machine.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[KubeAPIWarningLogger] metadata.finalizers: "dockermachine.infrastructure.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
Deleting objects from the source cluster

And here is an example with the flag set to true; this is the default behavior in this PR:

> bin/clusterctl move --kubeconfig=capi-quickstart.conf --to-kubeconfig=$HOME/.kube/config
Performing move...
Discovering Cluster API objects
Moving Cluster API objects Clusters=1
Moving Cluster API objects ClusterClasses=1
Waiting for all resources to be ready to move
Creating objects in the target cluster
Deleting objects from the source cluster

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

/area clusterctl

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 11, 2024
@k8s-ci-robot k8s-ci-robot added do-not-merge/needs-area PR is missing an area label size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 11, 2024
@dlipovetsky
Copy link
Contributor Author

dlipovetsky commented Sep 11, 2024

I've created this is a draft PR, because this might not be the implementation we want. Other options to consider:

  1. Use the existing, global verbosity flag --v to hide/show API server warnings, instead of introducing a new flag just for the move command.
  2. Hide a limited set of warnings, e.g. only warnings related to the Cluster API's finalizers.

/cc @sbueringer

@dlipovetsky
Copy link
Contributor Author

/area clusterctl

@k8s-ci-robot k8s-ci-robot added area/clusterctl Issues or PRs related to clusterctl and removed do-not-merge/needs-area PR is missing an area label labels Sep 11, 2024
@dlipovetsky
Copy link
Contributor Author

Per feedback in #11065 (comment), I'll implement a warning handler that can hide specific warnings, and use it here. We'll also be able to use it to address #11065.

@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 Sep 12, 2024
@dlipovetsky
Copy link
Contributor Author

This now depends on #11179. I'll keep it as a draft until that is merged.

@dlipovetsky dlipovetsky force-pushed the move-suppress-api-warnings branch 2 times, most recently from ad1b622 to 1be7d4a Compare September 23, 2024 17:24
@dlipovetsky dlipovetsky changed the title ✨ clusterctl: Suppress API warnings in "move" command ✨ clusterctl: Suppress "finalizer format" API warnings in "move" command Sep 23, 2024
@dlipovetsky dlipovetsky changed the title ✨ clusterctl: Suppress "finalizer format" API warnings in "move" command ✨ clusterctl: Suppress "finalizer name" API warnings in "move" command Sep 23, 2024
@sbueringer
Copy link
Member

I'll take a look once rebased (merging the other PR right now)

@dlipovetsky dlipovetsky marked this pull request as ready for review September 24, 2024 16:09
@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 Sep 24, 2024
Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

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

one nit

cmd/clusterctl/cmd/move.go Outdated Show resolved Hide resolved
Move all handlers to one file, expressions to another
Allow user to choose which warnings to hide
@sbueringer sbueringer added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Sep 26, 2024
Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

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

One last nit from my side

util/apiwarnings/expressions.go Outdated Show resolved Hide resolved
@sbueringer
Copy link
Member

/test pull-cluster-api-e2e-main

(to verify via e2e test artifacts)

Add LogAllHandler for consistent prefix, and DiscardAllHandler for convenience
@dlipovetsky
Copy link
Contributor Author

I realized that we showed a different log message prefix (KubeAPIWarningLogger) when the user chose to show all warnings, because we would delegate to controller-runtime's default warning handler. I added a handler (and test) that shows all warnings, and that's what we'll use, instead.

@dlipovetsky
Copy link
Contributor Author

Output examples

Default (hide only some warnings)

> bin/clusterctl move --kubeconfig=capi-quickstart.conf --to-kubeconfig=$HOME/.kube/config --hide-api-warnings=default
Performing move...
Discovering Cluster API objects
Moving Cluster API objects Clusters=1
Moving Cluster API objects ClusterClasses=1
Waiting for all resources to be ready to move
Creating objects in the target cluster
[API Server Warning] Cluster refers to ClusterClass default/quick-start, but this ClusterClass hasn't been successfully reconciled. Cluster topology has not been fully validated. Please take a look at the ClusterClass status
[API Server Warning] Cluster refers to ClusterClass default/quick-start, but this ClusterClass hasn't been successfully reconciled. Cluster topology has not been fully validated. Please take a look at the ClusterClass status
Deleting objects from the source cluster

Note we log warnings not related to the finalizer name.

Hide no warnings

> bin/clusterctl move --to-kubeconfig=capi-quickstart.conf --hide-api-warnings=none
Performing move...
Discovering Cluster API objects
Moving Cluster API objects Clusters=1
Moving Cluster API objects ClusterClasses=1
Waiting for all resources to be ready to move
Creating objects in the target cluster
[API Server Warning] metadata.finalizers: "cluster.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[API Server Warning] Cluster refers to ClusterClass default/quick-start, but this ClusterClass hasn't been successfully reconciled. Cluster topology has not been fully validated. Please take a look at the ClusterClass status
[API Server Warning] Cluster refers to ClusterClass default/quick-start, but this ClusterClass hasn't been successfully reconciled. Cluster topology has not been fully validated. Please take a look at the ClusterClass status
[API Server Warning] metadata.finalizers: "dockercluster.infrastructure.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[API Server Warning] metadata.finalizers: "kubeadm.controlplane.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[API Server Warning] metadata.finalizers: "machinepool.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with otherfinalizer writers
[API Server Warning] metadata.finalizers: "machinedeployment.topology.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[API Server Warning] metadata.finalizers: "machineset.topology.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[API Server Warning] metadata.finalizers: "machine.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[API Server Warning] metadata.finalizers: "dockermachinepool.infrastructure.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidentalconflicts with other finalizer writers
[API Server Warning] metadata.finalizers: "machine.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[API Server Warning] metadata.finalizers: "dockermachine.infrastructure.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
[API Server Warning] metadata.finalizers: "dockermachine.infrastructure.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers
Deleting objects from the source cluster

Hide all warnings

> bin/clusterctl move --kubeconfig=capi-quickstart.conf --to-kubeconfig=$HOME/.kube/config --hide-api-warnings=all
Performing move...
Discovering Cluster API objects
Moving Cluster API objects Clusters=1
Moving Cluster API objects ClusterClasses=1
Waiting for all resources to be ready to move
Creating objects in the target cluster
Deleting objects from the source cluster

@sbueringer
Copy link
Member

Perfect! Thank you very much :)

/lgtm
/approve

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

LGTM label has been added.

Git tree hash: f85436577430959ac6d6c34a26e3c2ccff1b0d4a

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbueringer

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 Sep 27, 2024
@k8s-ci-robot k8s-ci-robot merged commit 274d7e2 into kubernetes-sigs:main Sep 27, 2024
18 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.9 milestone Sep 27, 2024
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/clusterctl Issues or PRs related to clusterctl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants