-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
🌱 Add generate yaml subcommand to clusterctl #3406
🌱 Add generate yaml subcommand to clusterctl #3406
Conversation
41d9fba
to
08255b5
Compare
@@ -58,6 +58,37 @@ func (c *clusterctlClient) GetProviderComponents(provider string, providerType c | |||
return components, nil | |||
} | |||
|
|||
type ProcessYAMLOptions struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future we can specify the following option if it is needed but for now this sub-command uses the SimpleProcessor
default.
// YamlProcessor defines the yaml processor to use for the cluster¬
// template processing. If not defined, SimpleProcessor will be used.¬
YamlProcessor Processor¬
08255b5
to
f881a45
Compare
// Technically we do not need to connect to the cluster. However, we are | ||
// leveraging the template client which exposes GetFromURL() is available | ||
// on the cluster client so we create a cluster client with default | ||
// configs to access it. | ||
cluster, err := c.clusterClientFactory( | ||
ClusterClientFactoryInput{ | ||
// use the default kubeconfig | ||
kubeconfig: Kubeconfig{}, | ||
}, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since GetFromURL
has nothing to do with a cluster, "ideally" we would refactor it out into a standalone template client but that is quite a decent amount of refactoring. I opted to do it this way to reuse as much of the existing logic and not blow this PR out of proportions.
/assign |
f881a45
to
057cc82
Compare
/test pull-cluster-api-verify |
057cc82
to
12a1960
Compare
/hold |
d313d6f
to
5cd0ba6
Compare
/hold cancel |
5cd0ba6
to
dc76005
Compare
dc76005
to
d7368fa
Compare
d7368fa
to
bac0fc4
Compare
/assign @CecileRobertMichon for another review |
Code changes and functionaliy lgtm so far 👍 |
mis-configurations or in managing day 2 operations such as upgrades. | ||
|
||
* use [`clusterctl init`](commands/init.md) to install Cluster API providers | ||
* use [`clusterctl upgrade`](commands/upgrade.md) to upgrade Cluster API providers | ||
* use [`clusterctl delete`](commands/delete.md) to delete Cluster API providers | ||
|
||
* use [`clusterctl config cluster`](commands/config-cluster.md) to spec out workload clusters | ||
* use [`clusterctl generate yaml`](commands/generate-yaml.md) to process yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the idea to consolidate generate and config later on? I imagine there is some overlap between the two (eg. --list-variables). It might be confusing to a user when to use one vs. the other
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have this issue documenting some of the refactors we'd like to have for the config sub-command. #3360
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Also in the issue for user story you wrote "As a developer I would like to have a sub-command in clusterctl that could process yaml using the built in yaml processor so that we can leverage clusterctl's internal yaml processor within scripts." I agree that the main audience for this command would be a developer, do you also foresee a user story for cluster api end users? If not, would it be confusing to users to include this one in the user documentation? Maybe we can add something like "for development purposes" in the description, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These could also be used in CI scripts and other custom pipelines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CecileRobertMichon Yes. That makes sense actually. I guess for this specific sub-command the main audience would be for developers or maintainers of cluster-api providers (from the use cases we've seen so far).
Unless there are users who have customized templates and want to use clusterctl's default variable processor as well.
I can try and add some more clarity towards this in the book documentation.
/test pull-cluster-api-e2e |
/cc @jackfrancis Jack has been experimenting with clusterctl recently and might have some thoughts on this as a new-ish user |
@CecileRobertMichon: GitHub didn't allow me to request PR reviews from the following users: jackfrancis. Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
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. |
@wfernandes I like the idea of having a "generic" yaml input interface (as opposed to just |
@jackfrancis This specific sub-command is meant to alleviate the need to know the internal implementation (i.e. clusterctl does a bunch of stuff for us internally as part of the
Regarding the spec to actually authoring the yaml, unfortunately I wasn't part of the original clusterctl redesign however I believe the idea was iterative. That is, we started out with simple variable substitution like Now, if for some reason we needed to deviate and introduce some special functionality into the templating, we can then either define a proposal for the spec that clusterctl should follow by default (as you suggested) OR it can be supported by injecting another yaml processor. Currently, injecting yaml processor is supported by the library. BUT if we do implement some kind of plugin system, we "could potentially" leverage that. Hope that clarifies some things. |
bac0fc4
to
d0e003b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
@wfernandes Squash commits? Over to @CecileRobertMichon for final lgtm 🎉
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: vincepri 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 |
lgtm pending rebase |
Currently, this only works with --from flag since that is the most generic and can be used for any template. It also provides the --list-variables flag to list variables present in the template By default, it supports reading in from stdin.
d0e003b
to
78c886c
Compare
@wfernandes: The following test failed, say
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
Currently, this only works with --from flag since that is the most generic and can be used for any template.
It also provides the --list-variables flag to list variables present in the template
What this PR does / why we need it:
This PR adds the
generate yaml
subcommand. It works as follows: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 #3379