Skip to content

Define multi-stage commands as subcommands#2772

Merged
siggy merged 1 commit intomasterfrom
siggy/multi-stage-subcommands
May 2, 2019
Merged

Define multi-stage commands as subcommands#2772
siggy merged 1 commit intomasterfrom
siggy/multi-stage-subcommands

Conversation

@siggy
Copy link
Member

@siggy siggy commented Apr 30, 2019

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]

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]>
@siggy siggy requested review from alpeb and ihcsim April 30, 2019 16:52
@siggy siggy self-assigned this Apr 30, 2019
@l5d-bot
Copy link
Collaborator

l5d-bot commented Apr 30, 2019

Copy link
Contributor

@ihcsim ihcsim left a comment

Choose a reason for hiding this comment

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

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 {
Copy link
Contributor

@ihcsim ihcsim May 1, 2019

Choose a reason for hiding this comment

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

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@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.

Copy link
Member

Choose a reason for hiding this comment

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

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-checks skips 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 that install config ran successfully like checking that CRDs, ClusterRoles, and ClusterRoleBindings were created.
  • --ignore-cluster disregards 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?

Copy link
Member Author

Choose a reason for hiding this comment

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

@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.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha, this all makes sense to me. Thanks for clarifying!

Copy link
Member Author

Choose a reason for hiding this comment

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

Filed #2782 to track followup RBAC/CRD checks.

Copy link
Contributor

@ihcsim ihcsim left a comment

Choose a reason for hiding this comment

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

@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.

Copy link
Member

@alpeb alpeb left a comment

Choose a reason for hiding this comment

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

This looks good to me 👍

@siggy siggy merged commit 266e882 into master May 2, 2019
@siggy siggy deleted the siggy/multi-stage-subcommands branch May 2, 2019 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

explicit flag support for multi-stage install

5 participants