Define multi-stage commands as subcommands#2772
Conversation
The multi-stage args used by install, upgrade, and check were implemented as positional arguments to their respective parent commands. This made the help documentation unclear, and the code ambiguous as to which flags corresponded to which stage. Define `config` and `control-plane` stages as subcommands. The help menus now explicitly state flags supported. Fixes #2729 Signed-off-by: Andrew Seigner <[email protected]>
|
Integration test results for 570a71a: success 🎉 |
ihcsim
left a comment
There was a problem hiding this comment.
Code change LGTM, with one comment on --ignore-cluster and --skip-checks. I'm gonna do some more testing on this.
Also, I am surprised by the behaviour of PersistentFlags where all the parent flags are converted into global flags in the sub-commands. Not a blocker, but it pushes flags like --from-manifest, --ignore-cluster, --expected-version, --wait etc. up to be global flags, which get mixed with the real global flags like --context, --linkerd-namespace. AFAICT, functionally, they are still the same, so I guess it's ok? The only way to get around that is to repeat cmd.Flags().AddFlagSet() in both commands and sub-commands. Other kinds of flags like InheritedFlags, LocalFlags etc. don't seem to help.
| exitIfClusterExists() | ||
| } | ||
| if !options.skipChecks && stage == controlPlaneStage { | ||
| if !options.skipChecks { |
There was a problem hiding this comment.
AFAICT, there is no difference between --ignore-cluster and --skip-checks, other than --skip-checks is
a subcommand flag, right?. Maybe we can consider replacing --ignore-cluster entirely with just --skip-checks in a future PR?
Currently,
# this works
$ bin/linkerd install config --ignore-cluster
# this doesn't
$ bin/linkerd install config --skip-checks
# this serves no purposes, even though the flag is available
# the command still fails
$ bin/linkerd install control-plane --ignore-cluster
# this works
$ bin/linkerd install control-plane --skip-checks
# this works
$ bin/linkerd install --ignore-cluster
# this doesn't
$ bin/linkerd install --skip-checks
There was a problem hiding this comment.
@ihcsim Thanks for all this testing!
Re: the install parent flags getting pushed up into the global flags when using a subcommand, yeah, it's how cobra works. i agree with you that it would be preferable to be more clear on what constitutes a truly global flag vs. a flag that is specific to install and its subcommands. i looked at repeating cmd.Flags().AddFlagSet() in the subcommands as you mentioned, but i think the current implementation expresses the functionality more explicitly, as install parent flags that are shared with subcommands.
re: --skip-checks vs. --ignore-cluster, i agree it's a bit confusing. have a look at #2719 (comment) for the motivation. /cc @adleong
--skip-checks is specific to the linkerd install control-plane subcommand, which requires a control plane namespace to exist to successfully be applied via kubectl.
--ignore-cluster applies to install and all subcommands, and is meant to override an existing control plane installation.
re:
# this serves no purposes, even though the flag is available
# the command still fails
$ bin/linkerd install control-plane --ignore-cluster... that command succeeds if the control plane namespace exists, similar in behavior to linkerd install.
this discussion probably implies we could at least do a better job documenting these commands in the help output. let me know what you think.
There was a problem hiding this comment.
Sorry for jumping into this discussion after this has already been merged, but I just want to make sure I understand correctly what we landed on here.
I would expect that --skip-checks and --ignore-cluster are both flags on install control-plane that do different things:
--skip-checksskips the check that the controller namespace exists which can be useful for grabbing the control plane yaml even if your cluster is not ready for it to be applied. I would also expect this to skip other checks that verify thatinstall configran successfully like checking that CRDs, ClusterRoles, and ClusterRoleBindings were created.--ignore-clusterdisregards the contents of the linkerd config configmap and can be used to completely override an existing control-plane instead of preserving existing config settings.
Furthermore, I would expect these flags to also be available on linkerd install as well since linkerd install includes linkerd install control-plane.
I would not expect either of those flags to be available on linkerd install config. What do they do for that command?
There was a problem hiding this comment.
@adleong All permutations of subcommands and flags:
linkerd install --ignore-cluster
linkerd install config --ignore-cluster
linkerd install control-plane --ignore-cluster
# don't check for namespace existence (adding RBAC and CRD checks is a good idea)
linkerd install control-plane --skip-checks
Having --ignore-cluster available on install and all subcommands makes consistent the idea that "linkerd install" doesn't work after installation. This makes the user experience consistent post-installation:
$ bin/go-run cli install [config|control-plane]
Linkerd has already been installed on your cluster in the linkerd namespace. Please run upgrade if you'd like to update this installation. Otherwise, use the --ignore-cluster flag.I'm not sure of the use case for linkerd install --skip-checks. That flag checks for namespace existence, and fails if the namespace (and perhaps eventually CRDs, etc) doesn't exist. I think that's specific to linkerd install control-plane.
There was a problem hiding this comment.
Gotcha, this all makes sense to me. Thanks for clarifying!
There was a problem hiding this comment.
Filed #2782 to track followup RBAC/CRD checks.
ihcsim
left a comment
There was a problem hiding this comment.
@siggy This branch works well for me 👍.
Thanks for the clarification on --ignore-cluster and --skip-checks. Essentially, --skip-checks is only useful before the control plane is installed.
As for the cobra flags, yeah, there are no good ways around it. There is something called command.TraverseChildren, which allows us to separate the parent and children flags, but still ensures the subcommand accounts for the parent flags. So something like linkerd install --admin-port 9000 --metric-ports 9001 control-plane --skip-checks. But I don't think it's necessary, since we don't have that many subcommands.
The multi-stage args used by install, upgrade, and check were
implemented as positional arguments to their respective parent commands.
This made the help documentation unclear, and the code ambiguous as to
which flags corresponded to which stage.
Define
configandcontrol-planestages as subcommands. The helpmenus now explicitly state flags supported.
Fixes #2729
Signed-off-by: Andrew Seigner [email protected]