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 alpha topology-dryrun #5893

Merged
merged 1 commit into from
Jan 18, 2022

Conversation

ykakarap
Copy link
Contributor

@ykakarap ykakarap commented Dec 30, 2021

What this PR does / why we need it:
This PR implements a alpha new command: clusterctl alpha topology-dryrun.
This command can be used to dry run ClusterClass and/or Cluster changes.

The command expects as input a file that includes the new or modified objects. Example: the file can contain a modified Cluster or a modified ClusterClass. The output lists all the Clusters and ClusterClasses that will be affected.

The following example shows the output when dry-running to create a Cluster that uses a pre-installed ClusterClass.
Screen Shot 2021-12-29 at 10 13 50 PM

Special thanks to @fabriziopandini for providing guidance for this feature. 🙂

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 #5319

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 30, 2021

CLA Signed

The committers are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Dec 30, 2021
@ykakarap ykakarap force-pushed the clusterctl-dry-run branch 3 times, most recently from 21028c8 to 88ec975 Compare December 30, 2021 05:14
go.mod Show resolved Hide resolved
@ykakarap
Copy link
Contributor Author

/retest

@ykakarap
Copy link
Contributor Author

/test pull-cluster-api-verify-main

@ykakarap
Copy link
Contributor Author

/retest

@ykakarap
Copy link
Contributor Author

ykakarap commented Dec 30, 2021

The verify pipeline failure seems to be unrelated to the code changes. the failure seems to be related to the pipeline execution.
Resolved.

@ykakarap
Copy link
Contributor Author

/retest

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.

This is great work!
first pass, mostly nits

cmd/clusterctl/client/cluster/internal/dryrun/client.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/internal/dryrun/client.go Outdated Show resolved Hide resolved
controllers/topology/cluster_controller.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/internal/dryrun/client.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/topology.go Show resolved Hide resolved
cmd/clusterctl/client/cluster/topology.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/topology.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/topology_test.go Outdated Show resolved Hide resolved
@ykakarap
Copy link
Contributor Author

ykakarap commented Jan 4, 2022

@fabriziopandini thank you for the review.
I am on PTO right now and will address the changes after I am back in a few days (probably next week).

@sbueringer
Copy link
Member

sbueringer commented Jan 7, 2022

I'll take a closer look on Monday.

controllers/topology/cluster_controller.go Outdated Show resolved Hide resolved
cmd/clusterctl/cmd/topology.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 8, 2022
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.

First round of review

go.mod Show resolved Hide resolved
cmd/clusterctl/cmd/topology.go Outdated Show resolved Hide resolved
cmd/clusterctl/cmd/topology.go Outdated Show resolved Hide resolved
cmd/clusterctl/cmd/topology.go Outdated Show resolved Hide resolved
cmd/clusterctl/cmd/topology.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/internal/dryrun/client.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/internal/dryrun/client.go Outdated Show resolved Hide resolved
@dlipovetsky
Copy link
Contributor

dlipovetsky commented Jan 12, 2022

Do create/update requests go through validation webhooks? That is, are they sent to a Kubernetes API? It looks like client/cluster/internal/dryrun/client.go uses a "fake" client.

If they do not, then I think it's worth making this explicitly a "client-side" dry-run, e.g.,

> kubectl create --help | grep dry
      --dry-run='none': Must be "none", "server", or "client". If client strategy, only print the object that would be sent, without sending it. If server strategy, submit server-side request without persisting the resource.

Copy link
Contributor Author

@ykakarap ykakarap left a comment

Choose a reason for hiding this comment

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

@dlipovetsky Within this dry run code we run validation and defaulting but only for Cluster and ClusterClass types. We do this not by running them through the webhooks, instead we run the validation and defaulting functions directly.

Ref: https://github.com/ykakarap/cluster-api/blob/clusterctl-dry-run/cmd/clusterctl/client/cluster/topology.go#L358-L383

Defaulting and Validation of any of the provider types is out of scope for this feature.

Copy link
Contributor Author

@ykakarap ykakarap left a comment

Choose a reason for hiding this comment

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

There are a few more comments I need to address.
Resolving some conversations and replying to some comments in the mean time.

cmd/clusterctl/client/cluster/internal/dryrun/client.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/internal/dryrun/client.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/internal/dryrun/client.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/internal/dryrun/client.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/topology.go Show resolved Hide resolved
cmd/clusterctl/cmd/topology.go Outdated Show resolved Hide resolved
cmd/clusterctl/cmd/topology.go Show resolved Hide resolved
cmd/clusterctl/cmd/topology.go Show resolved Hide resolved
cmd/clusterctl/cmd/topology.go Outdated Show resolved Hide resolved
@ykakarap ykakarap force-pushed the clusterctl-dry-run branch 2 times, most recently from d63aec5 to e2d4237 Compare January 16, 2022 17:25
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 16, 2022
@ykakarap
Copy link
Contributor Author

FYI: The new size of the clusterctl binary on linux amd64 is ~60mb. Previously it was ~52mb.

cmd/clusterctl/cmd/topology.go Outdated Show resolved Hide resolved
cmd/clusterctl/cmd/topology.go Outdated Show resolved Hide resolved
cmd/clusterctl/cmd/topology.go Outdated Show resolved Hide resolved
cmd/clusterctl/cmd/topology.go Show resolved Hide resolved
cmd/clusterctl/client/topology.go Show resolved Hide resolved
cmd/clusterctl/client/cluster/topology.go Outdated Show resolved Hide resolved
Comment on lines 385 to 406
object := o.DeepCopyObject().(client.Object)
if err := localScheme.Convert(obj, object, nil); err != nil {
return errors.Wrapf(err, "failed to convert object to %s", obj.GetKind())
}
Copy link
Member

Choose a reason for hiding this comment

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

Q: why wo we have to do this. Couldn't we just use the obj directly?

If I'm right we might also don't need the back-conversion at the end of the loop

Copy link
Contributor Author

@ykakarap ykakarap Jan 18, 2022

Choose a reason for hiding this comment

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

we cant use obj directly. The defaulter and validator expect types like Cluster and ClusterClass and that is object. Hence we use convert to basically move data from unstructured to object (typed object) and then move back to unstructured.

cmd/clusterctl/client/cluster/topology.go Show resolved Hide resolved
cmd/clusterctl/client/cluster/internal/dryrun/client.go Outdated Show resolved Hide resolved
Copy link
Contributor

@killianmuldoon killianmuldoon left a comment

Choose a reason for hiding this comment

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

First part of the review - just a lot of nits 😄

cmd/clusterctl/client/cluster/internal/dryrun/client.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/internal/dryrun/client.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/internal/dryrun/client.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/internal/dryrun/client.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/topology.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/topology.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/topology.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/topology.go Outdated Show resolved Hide resolved
cmd/clusterctl/client/cluster/topology.go Show resolved Hide resolved
@sbueringer
Copy link
Member

Great work!!

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 18, 2022
@killianmuldoon
Copy link
Contributor

/lgtm

Code looks good! I'm going to spend some time playtesting but if anything comes up I can create an issue and we can patch.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 18, 2022
@k8s-ci-robot
Copy link
Contributor

@ykakarap: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-apidiff-main dcc22db link false /test pull-cluster-api-apidiff-main

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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/test-infra repository. I understand the commands that are listed here.

@sbueringer
Copy link
Member

/lgtm
to latest fixes

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 18, 2022
@fabriziopandini
Copy link
Member

This is a super powerful feature!
Let's make it a demo in the office hours and wait for feedback and ideas for further improvements
/lgtm

@vincepri
Copy link
Member

vincepri commented Jan 18, 2022

Overall this feature looks great, my only comment is about the UX for the command itself, consider to have something like

clusterctl alpha topology plan [...]

We can always follow-up for this, not a blocker for this PR, but release blocking

@fabriziopandini
Copy link
Member

/approve
@ykakarap to follow up on the name change before release

@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 Jan 18, 2022
@k8s-ci-robot k8s-ci-robot merged commit da03567 into kubernetes-sigs:main Jan 18, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.1 milestone Jan 18, 2022
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clusterctl topology dry run
7 participants