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

✨ Make Clusterclass webhook Cluster-aware #5717

Conversation

killianmuldoon
Copy link
Contributor

@killianmuldoon killianmuldoon commented Nov 22, 2021

Add cluster aware checks to the clusterClass webhook that:

  1. Disallow clusterClass deletion if any clusters using the clusterClass still exist
  2. Allow removing a MachineDeploymentClass from a Cluster as long as the MachineDeploymentClass is not in use by an existing MachineDeployment does not exist.

Previously:

  • any clusterclass would be deleted even if it was in use.
  • MachineDeploymentClasses were not ever allowed to be removed from an existing clusterClass.

Note this is built on top of #5318 and should not be merged until after that PR is merged. Changes introduced in this PR are in the second commit.

Fixes: #5498

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 22, 2021
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Nov 22, 2021
@killianmuldoon killianmuldoon force-pushed the webhooks/additional-clusterclass-checks branch from f88ff15 to ca2b241 Compare November 22, 2021 14:29
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 22, 2021
internal/builder/builders.go Outdated Show resolved Hide resolved
internal/topology/check/compatibility.go Show resolved Hide resolved
internal/topology/check/compatibility_test.go Show resolved Hide resolved
webhooks/cluster_test.go Outdated Show resolved Hide resolved
webhooks/clusterclass.go Outdated Show resolved Hide resolved
webhooks/clusterclass.go Outdated Show resolved Hide resolved
webhooks/clusterclass.go Outdated Show resolved Hide resolved
webhooks/clusterclass.go Outdated Show resolved Hide resolved
webhooks/clusterclass.go Outdated Show resolved Hide resolved
webhooks/clusterclass.go Outdated Show resolved Hide resolved
@killianmuldoon killianmuldoon changed the title ✨ [WIP] Make Clusterclass webhook Cluster-aware ✨ Make Clusterclass webhook Cluster-aware Nov 22, 2021
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 22, 2021
@killianmuldoon killianmuldoon force-pushed the webhooks/additional-clusterclass-checks branch from 6230e28 to f2fc925 Compare November 22, 2021 18:06
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 22, 2021
internal/webhooks/clusterclass.go Outdated Show resolved Hide resolved
internal/webhooks/clusterclass.go Outdated Show resolved Hide resolved
internal/webhooks/clusterclass.go Outdated Show resolved Hide resolved
internal/webhooks/clusterclass.go Outdated Show resolved Hide resolved
internal/webhooks/clusterclass.go Outdated Show resolved Hide resolved
internal/webhooks/clusterclass.go Show resolved Hide resolved
@sbueringer
Copy link
Member

sbueringer commented Nov 23, 2021

Please let me know when I should do another review and please resolve the straightforward findings (i.e. the conversations) which have been fixed.

@killianmuldoon killianmuldoon force-pushed the webhooks/additional-clusterclass-checks branch 3 times, most recently from 8e228de to 3692624 Compare November 23, 2021 11:06
internal/webhooks/clusterclass.go Outdated Show resolved Hide resolved
internal/webhooks/clusterclass.go Outdated Show resolved Hide resolved
internal/webhooks/clusterclass.go Outdated Show resolved Hide resolved
internal/webhooks/clusterclass.go Show resolved Hide resolved
internal/webhooks/clusterclass_test.go Outdated Show resolved Hide resolved
internal/webhooks/clusterclass_test.go Outdated Show resolved Hide resolved
internal/webhooks/clusterclass_test.go Outdated Show resolved Hide resolved
}

// Retrieve all clusters using the ClusterClass.
clusters, err := webhook.getClustersUsingClusterClass(old)
Copy link
Member

Choose a reason for hiding this comment

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

In this case we will now have an apierror wrapped into an field error wrapped into an apierror. I'm not sure what the error for users will look like.

My intention was to suggest the following:

  • return a regular error in getClustersUsingClusterClass
  • ValidateDelete:
    • Take the error and wrap it into an apierror in ValidateDelete
  • ValidateCreate/Update
    • Call getClustersUsingClusterClass directly in validate instead of in validateRemovedMachineDeploymentClassesAreNotUsed, if there is an error wrap it into an apierror and return it
      • If I understood it correctly we have to move getClustersUsingClusterClass that level up anyway sooner or later to avoid calling this func multiple times.

WDYT?

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 think we're going to have to wrap the client error into a field.ErrorList at that level anyway in order to retain the errors from earlier in validate. I'll update with what I have, but I don't see any direct and clean way to wrap all of these errors into something that will be perfect in every case.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure but when getClustersUsingClusterClass is called directly in validate I would have thought that we can just return the error we want, but maybe I'm missing something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Validate will already have some errors wrapped in field.ErrorList by the time getClustersUsingClusterClass is called so we should wrap that error in the same way.

Copy link
Member

Choose a reason for hiding this comment

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

As discussed, we now have one api error which contains a list of field errors and that's fine (as we still want to return the field errors)

@killianmuldoon killianmuldoon force-pushed the webhooks/additional-clusterclass-checks branch from 97e1a69 to 350f5ec Compare November 23, 2021 17:23
@sbueringer
Copy link
Member

/retest

@killianmuldoon killianmuldoon force-pushed the webhooks/additional-clusterclass-checks branch from 350f5ec to 794e1a6 Compare November 23, 2021 17:54
@killianmuldoon killianmuldoon force-pushed the webhooks/additional-clusterclass-checks branch from 794e1a6 to ac639c2 Compare November 23, 2021 17:59
@sbueringer
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 23, 2021
Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini

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 24, 2021
@k8s-ci-robot k8s-ci-robot merged commit 167a7bd into kubernetes-sigs:main Nov 24, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.1 milestone Nov 24, 2021
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. 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

handle ClusterClass deletion
4 participants