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

✨ Refactor clusterctl config to clusterctl generate #4584

Merged

Conversation

shysank
Copy link
Contributor

@shysank shysank commented May 7, 2021

What this PR does / why we need it:
This pr refactors clusterct config cluster and cluster config provider to clusterctl generate cluster and clusterctl generate provider respectively. Some changes to be noted:

  • clusterctl generate provider -> generates a yaml template of the provider, this is equivalent to clusterctl config provider -o yaml
  • clusterctl generate provider --describe -> displays information about the provider in text, this is equivalent to clusterctl config provider

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

** There was an earlier PR that aimed to fix the same issue. Based on the discussion, we're splitting it into two prs, this is the first one.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 7, 2021
@shysank
Copy link
Contributor Author

shysank commented May 7, 2021

/cc @fabriziopandini

@@ -79,6 +79,7 @@ var configProviderCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
return runGetComponents()
},
Deprecated: "use `clusterctl generate provider` instead",
Copy link
Member

Choose a reason for hiding this comment

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

what is the plan for removal of the deprecated commands:

  • when would that happen?
  • is there an issue to track it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The plan is to support the old commands for 0.4 and to remove it in the subsequent release. I've created an issue for tracking it. Do you think we should add a warning about removing it in the Deprecated description string?

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/lgtm
/assign @fabriziopandini

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 11, 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.

Overall lgtm, a couple of nits

cmd/clusterctl/cmd/generate_cluster.go Outdated Show resolved Hide resolved
cmd/clusterctl/cmd/generate_provider.go Outdated Show resolved Hide resolved
@shysank shysank force-pushed the clusterctl_generate_part1 branch from 8fa9a46 to 4fe2aee Compare May 19, 2021 16:18
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 19, 2021
@shysank shysank force-pushed the clusterctl_generate_part1 branch from 4fe2aee to 8a34908 Compare May 19, 2021 16:20
@fabriziopandini
Copy link
Member

/retest
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 19, 2021
generateCmd.AddCommand(generateClusterClusterCmd)
}

func runGenerateClusterTemplate(cmd *cobra.Command, name string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

all of this seems to be duplicate code from cmd/clusterctl/cmd/config_cluster.go, can we instead reuse the same helper functions from generate_cluster into config_cluster.go so that the code is shared between the two commands?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we are going anyway to remove config_cluster.go in the next release, I thought it'd be okay to just copy over. Same for the config_provider.go as well.

Copy link
Member

Choose a reason for hiding this comment

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

If those are duplicates, let's start removing to existing methods in config_cluster.go/config_provider.go and have both the commands to point to the same internal function

Copy link
Member

Choose a reason for hiding this comment

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

+1 @shysank are you ok with the proposed changes above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The functions @CecileRobertMichon is talking about are runGetClusterTemplate and runGenerateClusterTemplate in config_cluster.go and generate_cluster.go respectively. They are almost similar with the difference being the options struct used: configClusterOptions vs generateClusterOptions which are both package level variables (this is the pattern we follow for all the commands). Both the command functions, and options structs are same for now, but will start to diverge in future (eg. with --raw option added). I'm not sure if we want to move them to a common function because it's very specific to the commands. The parts of code which are shareable (eg. printYamlOutput) is already in util.go. That was my rationale for not using the same function for both commands although happy to refactor if people think otherwise, we'll probably have to use the same options struct I think in that case.

Copy link
Member

Choose a reason for hiding this comment

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

Could we add a comment to that effect on the configClusterOptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One clarification on the above comment. The --raw is for generate_provider. But the idea is still the same given that we are planning to remove config_cluster in 0.5.x, and there may be new options added to generate_cluster.

Copy link
Member

Choose a reason for hiding this comment

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

given the context above (thanks for the explanation!), I'm fine with current implementation

Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, thanks for clarifying. We'll have to be diligent in reviews to make sure no changes are made to the config functions once this merges. It might be good to add a comment as well as Vince suggested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'll add comments. Thanks for the feedback!

@shysank shysank force-pushed the clusterctl_generate_part1 branch from 8a34908 to b535ff1 Compare May 20, 2021 19:21
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 20, 2021
@CecileRobertMichon
Copy link
Contributor

/lgtm

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

/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 May 21, 2021
@fabriziopandini
Copy link
Member

/retest

@k8s-ci-robot k8s-ci-robot merged commit 634a2d7 into kubernetes-sigs:master May 21, 2021
@k8s-ci-robot k8s-ci-robot added this to the v0.4 milestone May 21, 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/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.

[clusterctl] refactor config subcommand
6 participants