-
Notifications
You must be signed in to change notification settings - Fork 435
Change NodePool CLI to have platform sub command #832
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
Change NodePool CLI to have platform sub command #832
Conversation
|
This PR is opened as continue to the discussion here #779 (comment) |
cmd/nodepool/core/create.go
Outdated
| Render bool | ||
| } | ||
|
|
||
| // ApplyPlatformSpecifics can be used to create platform specific values as well as enriching the fixure with additional values |
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.
This comment seems to refer to a different function.
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.
Fixed
| @@ -0,0 +1,114 @@ | |||
| package aws | |||
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.
please update the docs getting starting guide to reflect this changes
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.
Updated the docs (added aws option)
cmd/nodepool/aws/log.go
Outdated
| @@ -0,0 +1,7 @@ | |||
| package aws | |||
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.
I'm not sure where this pattern of having a single file for this variable is coming from?
I question we should keep perpetuating it? may @ironcladlou knows better where this is coming from/why we need it?
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.
I think it's just a combination of organic changes and cargo culting. Quick analysis:
In the CLI we're relying on a package variable for the logging singleton (util.Log). Authors might use util.Log.Error(...) (for example) directly. Or alias it to a local so it would read more like log.Error(...) (what this PR is doing).
If we're okay fundamentally with the package variable for logger state (instead of e.g. passing logger instances around), we could move the package variable to a log package so that users get the concise log.Error(...) call semantics without doing aliasing.
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.
I agree with the last suggestion
I can create new log package under cmd, to be used from all cmd sub packages
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.
Changed it
Need to change also the other packages to use this new log package (another PR?)
cmd/nodepool/kubevirt/create.go
Outdated
| // As long as there is no official container image | ||
| // The image must be provided by user | ||
| // Otherwise it must fail | ||
| if o.ContainerDiskImage == "" { |
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.
why do we have this here instead of making the field built-in required in the cli?
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.
Fixed
cmd/nodepool/core/create.go
Outdated
| } | ||
|
|
||
| // ApplyPlatformSpecifics can be used to create platform specific values as well as enriching the fixure with additional values | ||
| type CreateNodePoolPlatformOptions interface { |
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.
naming seems redundant given we are in nodepool/core/create, may be just
type PlatformOptions interface { Update() type() }
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.
Renaming CreateNodePoolPlatformOptions to PlatformOptions and platformType to Type sound good to me, but I'm not sure about renaming UpdatePlatformParams to Update, because it can be interpreted as we this function is updating the PlatformOptions itself
What do you think about changing it to UpdateNodePool?
type PlatformOptions interface {
// UpdateNodePool is used to update the platform specific values in the NodePool
UpdateNodePool(ctx context.Context, nodePool *hyperv1.NodePool, hcluster *hyperv1.HostedCluster, client crclient.Client) error
// Type returns the platform type
Type() hyperv1.PlatformType
}
cmd/nodepool/core/create.go
Outdated
| return fmt.Errorf("failed to get HostedCluster %s/%s: %w", o.Namespace, o.Name, err) | ||
| } | ||
|
|
||
| if platformOpts != nil { |
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.
do we need this check? when would this be nil?
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.
You right, it never should be nil, removed the validation
cmd/nodepool/aws/create.go
Outdated
| func CreateNodePool(ctx context.Context, coreOpts core.CreateNodePoolOptions, platformOpts AWSPlatformCreateOptions) error { | ||
| return coreOpts.CreateNodePool(ctx, platformOpts) | ||
| } | ||
|
|
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.
can we add the lines to validate each platform type implements the interface?
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.
Can you please elaborate on this? how do you suggest to add this validation?
Not all platform types implement the interface (Agent and None weren't added to the NodePool CLI)
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.
Any platform implementing PlatformOptions i.e within cmd/nodepool/* needs to validate it satisfy the interface a build time, e.g https://github.com/openshift/hypershift/blob/main/hypershift-operator/controllers/hostedcluster/internal/platform/platform.go#L19-L22
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.
Ok, I will add this
But why do we need it, as already we have the assigment of the implementation on the interface, which fail on build time if the implementation doesn't satisfy the interface
In this case, the call to the function this comment points to would fail in build time
|
PTAL @rmohr |
2117cb0 to
f66c396
Compare
|
✔️ Deploy Preview for hypershift-docs ready! 🔨 Explore the source changes: ae6859e 🔍 Inspect the deploy log: https://app.netlify.com/sites/hypershift-docs/deploys/61e6a39911c6bf0007489f83 😎 Browse the preview: https://deploy-preview-832--hypershift-docs.netlify.app |
|
|
||
| hypershift create nodepool --cluster-name $CLUSTER_NAME \ | ||
| hypershift create nodepool aws \ | ||
| --cluster-name $CLUSTER_NAME \ |
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.
@enxebre is it valid for a NodePool's platform to differ from its owning HostedCluster?
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.
Nope, today that's not valid as a design invariant, it's validated here and it'll fail if you try to https://github.com/openshift/hypershift/pull/832/files#diff-d2048aaf4e4de5ddfc058be0d46748ec7e8ab85ad4bc9d62b97dae0a41138020R42-R44
In a way having "platform" --cluster-name $CLUSTER_NAME is redundant though I think being explicit provides a consistent better UX and helper output than implementing some CLUSTER_NAME inferring magic would do. Let me known if you think otherwise.
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.
I had a similar thought about how it seems weird to have to repeat the platform here given the system already knows the platform of --cluster-name... the validation you mentioned helps though. I was thinking repeating the platform here would only leave room for user error, but if it fails fast with a validation error, sounds fine to me.
Plus without subcommands, I'm not sure how we would sanely have per-platform arguments.
Thanks, I think it will be good!
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.
Plus without subcommands, I'm not sure how we would sanely have per-platform arguments.
This is also floating around in my head for some time. In theory we could have a two-stage phase here, where we first determine the cluster type based on the name, and based on the detection register the right cobra commands.
That could for instance work by first doing minimal pflag parsing where only platform independend flags are recognized. Then when we know the platform we could just "register" the corresponding sub-program.
Apart from the fact that it may a little bit over-engineered, the downside with this is that --help could only provide helpful flag output if one would point it against a valid cluster, which sounds wrong.
That may still be overcome, by providing a kubectl-like help message. Where the help message would indicate that to see the corresponsing flags, one has to provide the cluster-type. For example:
$ hypershift nodepool --help
Usage:
The cluster and the commadnline flags are automatically detected based on the discovered cluster type.
To see platform specific commandline flags run
hypershift nodepool help aws
hypershift nodepool help none
[...]
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.
I don't know about over-engineered, but it's a really interesting idea. The nodepool subcommand as currently designed is only intended to be used in the context of an existing hostedcluster, so making the CLI "adaptive" to the target hostedcluster is pretty interesting and clever...
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.
I don't know about over-engineered, but it's a really interesting idea. The nodepool subcommand as currently designed is only intended to be used in the context of an existing hostedcluster, so making the CLI "adaptive" to the target hostedcluster is pretty interesting and clever...
Thinking it through again, it may indeed not even be complex to do. @ironcladlou @nirarg , what do you think?
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.
to keep PR size and changes from existing code to a reasonable size I'd suggest we merge keeping existing approach and have a follow up PR to discuss this concretely?
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.
Works for me.
cmd/nodepool/aws/create.go
Outdated
|
|
||
| func NewCreateCommand(coreOpts core.CreateNodePoolOptions) *cobra.Command { | ||
| platformOpts := AWSPlatformCreateOptions{ | ||
| InstanceType: "m4.large", |
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.
Let's update as in #850
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.
Also #852
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.
Done
f66c396 to
925287d
Compare
cmd/nodepool/core/create.go
Outdated
| return err | ||
| } | ||
|
|
||
| if o.Render { |
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.
how is this code run? if o.Render { wouldn't this func return in l92?
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.
You right, this is never called
This code was already exists before my change
It seems that the "Render" code (writing bytes to os.Stdout) was written twice and the second call is unnecessary and can be removed
Am I right?
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.
Removed this code
|
lgtm other than #832 (comment) |
925287d to
7da4d3c
Compare
7da4d3c to
cc25ba3
Compare
|
/lgtm |
|
Can you please add a PR/commit desc elaborating "why"? e.g Since we introduced multi platform support we want the CLI to be able to provide granular platform specific UX where needed" |
cc25ba3 to
444ab43
Compare
Done |
Change the NodePool CLI to be platform aware This change is done as part of the multy platform support, to allow the CLI to provide platform specific UX where needed
444ab43 to
ae6859e
Compare
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: enxebre, nirarg The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/lgtm |
|
@nirarg: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions 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. |
Fix three issues added in PR openshift#832: * Fix Global flags to use PersistentFlag insead Flag * Change all objects to be passed as pointers in order to have command values passed * In cmd/log the way passing keysAndValues parameter
Fix three issues added in PR openshift#832: * Fix Global flags to use PersistentFlag insead Flag * Change all objects to be passed as pointers in order to have command values passed * In cmd/log the way passing keysAndValues parameter
cmd/log/log.go was added in PR openshift#832 Change all cmd modules to use this cmd logger This is done following to the discussion here: openshift#832 (comment)
Since changed the NodePool to be platform aware (PR openshift#832) In order to create NodePool for specific platform, the platform must implement specific sub command Therfore add the subcommands for None and Agent platforms, although the NodePool platformSpec is empty for those platforms
Since changed the NodePool to be platform aware (PR openshift#832) In order to create NodePool for specific platform, the platform must implement specific sub command Therfore add the subcommands for Agent platform, although the NodePool platformSpec is empty for those platforms
Since changed the NodePool to be platform aware (PR openshift#832) In order to create NodePool for specific platform, the platform must implement specific sub command Therfore add the subcommands for Agent platform, although the NodePool platformSpec is empty for those platforms
Since changed the NodePool to be platform aware (PR openshift#832) In order to create NodePool for specific platform, the platform must implement specific sub command Therfore add the subcommands for Agent platform, although the NodePool platformSpec is empty for those platforms
Since changed the NodePool to be platform aware (PR openshift#832) In order to create NodePool for specific platform, the platform must implement specific sub command Therfore add the subcommands for Agent platform, although the NodePool platformSpec is empty for those platforms
cmd/log/log.go was added in PR openshift#832 Change all cmd modules to use this cmd logger This is done following to the discussion here: openshift#832 (comment)
cmd/log/log.go was added in PR openshift#832 Change all cmd modules to use this cmd logger This is done following to the discussion here: openshift#832 (comment)
Change the NodePool CLI to be platform aware
This change is done as part of the multy platform support,
to allow the CLI to provide platform specific UX where needed