-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Fix broken swarm commands with Kubernetes defined as orchestrator #1137
Conversation
Please review with attention stack/cmd.go, and if you can make some manual tests too, it would be great 😄 |
0e358b6
to
ba06122
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.
A few comments!
cli/command/stack/cmd.go
Outdated
return | ||
} | ||
if _, ok := f.Annotations["kubernetes"]; ok && !orchestrator.HasKubernetes() { | ||
errs = append(errs, fmt.Sprintf("\"--%s\" is only supported on a Docker cli with kubernetes features enabled", f.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.
nit: back quotes would remove the need to escape the double quotes:
errs = append(errs, fmt.Sprintf(`"--%s" is only supported on a Docker cli with kubernetes features enabled`, f.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.
Yep, I just moved the code but you're right I'll fix it.
@@ -10,7 +10,7 @@ import ( | |||
"github.com/spf13/cobra" | |||
) | |||
|
|||
func newPsCommand(dockerCli command.Cli) *cobra.Command { | |||
func newPsCommand(dockerCli command.Cli, common *commonOptions) *cobra.Command { |
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 think common
needs to be a pointer here as it's always non-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.
Well, it's because newPsCommand is called during command instantiation, but the common.orchestrator value will be updated in the stack/cmd.go:PersistentPreRunE. That's why it is passed as a pointer and not as a copied value.
@@ -13,7 +13,7 @@ import ( | |||
"vbom.ml/util/sortorder" | |||
) | |||
|
|||
func newListCommand(dockerCli command.Cli) *cobra.Command { | |||
func newListCommand(dockerCli command.Cli, common *commonOptions) *cobra.Command { |
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.
Same here, it doesn't seem common
can ever be nil
.
) | ||
|
||
var errUnsupportedAllOrchestrator = fmt.Errorf(`no orchestrator specified: use either "kubernetes" or "swarm"`) | ||
|
||
type commonOptions struct { | ||
orchestrator command.Orchestrator | ||
} |
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 need this type? Can't we use command.Orchestrator
directly?
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 need to update the value while resolving the orchestrator (conf file -> env -> flag), but we need to wait for the PersistentPreRun to be able to read the orchestrator flag value.
@@ -14,6 +15,10 @@ import ( | |||
"gotest.tools/golden" | |||
) | |||
|
|||
var ( | |||
orchestrator = commonOptions{orchestrator: command.OrchestratorSwarm} |
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.
orchestrator
is actually a commonOptions
?
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.
Yes I know, I was lazy... It was a first attempt with orchestrator, didn't want to rename 😅
cli/command/system/version.go
Outdated
@@ -121,13 +121,19 @@ func reformatDate(buildTime string) string { | |||
return buildTime | |||
} | |||
|
|||
// nolint: gocyclo |
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.
Really? :p
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.
Yeah, don't know why...
kubeVersion := getKubernetesVersion(dockerCli, opts.kubeConfig) | ||
var kubeVersion *kubernetesVersion | ||
if orchestrator.HasKubernetes() { | ||
kubeVersion = getKubernetesVersion(opts.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.
nit: or we could pass orchestrator
to getKubernetesVersion
instead of 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.
Why instead of? I think getKubernetesVersion needs the kubeConfig to instantiate the kube client.
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.
Sorry got mixed up, I meant instead of the dockerCli
which was passed before.
cli/command/stack/kubernetes/cli.go
Outdated
@@ -46,7 +46,7 @@ func AddNamespaceFlag(flags *flag.FlagSet) { | |||
} | |||
|
|||
// WrapCli wraps command.Cli with kubernetes specifics | |||
func WrapCli(dockerCli command.Cli, opts Options) (*KubeCli, error) { | |||
func WrapCli(dockerCli command.Cli, opts Options, orchestrator command.Orchestrator) (*KubeCli, error) { |
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't orchestrator
be put inside Options
somehow?
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'll try that!
The metalinter is not happy, nor the unit testing... I'll fix this! |
8c67022
to
a935af8
Compare
PTAL |
I see all those testOrchestrator being removed but nothing replacing them... or am I missing something? |
Tests were moved 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.
left some comments for discussion; trying to give it a spin, but nuked my k8s, lol
@@ -17,10 +17,25 @@ const ( | |||
OrchestratorAll = Orchestrator("all") |
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.
Looks like these constants can be un-exported? (and the GoDoc removed)
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.
Nevermind; I see they're used in a test; can be fixed, but no urgency
return command.GetStackOrchestrator(orchestratorFlag, config.StackOrchestrator) | ||
} | ||
|
||
func hideFlag(cmd *cobra.Command, orchestrator command.Orchestrator) { |
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.
hideOrchestrationFlags
perhaps
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
Built: Wed May 30 22:21:05 2018 | ||
OS/Arch: linux/amd64 | ||
Experimental: true | ||
Stack Orchestrator: swarm |
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.
Looking at this now, a bit concerned how this will scale if support for more options is added 😞
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.
Talked with @thaJeztah @dhiltgen and it seems more desirable to just get rid of the Orchestrator
line for now and revisit.
@@ -17,10 +17,25 @@ const ( | |||
OrchestratorAll = Orchestrator("all") | |||
orchestratorUnset = Orchestrator("unset") | |||
|
|||
defaultOrchestrator = OrchestratorSwarm | |||
envVarDockerOrchestrator = "DOCKER_ORCHESTRATOR" |
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 may have to think about printing a warning if someone has this variable set.
I realize so far it's been experimental, so we're allowed to change things, but it's definitely possible people had this option set, and now it's being ignored.
Of course, to further complicate stuff; some day it may find its way back, once k8s integration on the cli is complete 😅
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.
Just added the warning!
newPsCommand(dockerCli), | ||
newRemoveCommand(dockerCli), | ||
newServicesCommand(dockerCli), | ||
newDeployCommand(dockerCli, &opts), |
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.
It's a pity the change has such a deep impact. Don't see another solution at this time though 😕
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.
oh 😓
cli/command/system/version.go
Outdated
@@ -29,7 +29,7 @@ Client:{{if ne .Platform.Name ""}} {{.Platform.Name}}{{end}} | |||
Built: {{.BuildTime}} | |||
OS/Arch: {{.Os}}/{{.Arch}} | |||
Experimental: {{.Experimental}} | |||
Orchestrator: {{.Orchestrator}} | |||
Stack Orchestrator: {{.StackOrchestrator}} |
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.
Still on the fence wether we should always print this, or only if any orchestrator is enabled
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.
Looks like we may want to; here's against a host that doesn't have swarm (or kube) enabled;
Client:
Version: 18.06.0-dev
API version: 1.37 (downgraded from 1.38)
Go version: go1.10.3
Git commit: ba061224
Built: Thu Jun 21 20:48:25 2018
OS/Arch: linux/amd64
Experimental: false
Stack Orchestrator: swarm
Server:
Engine:
Version: 18.05.0-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.10.1
Git commit: f150324
Built: Wed May 9 22:20:16 2018
OS/Arch: linux/amd64
Experimental: true
Output for all
may be a bit confusing as well, but don't have better suggestions for that at this point
Stack Orchestrator: all
Giving this a spin; Using
This is something we can improve (i.e.; if it's non-ambiguous, show the result);
(actually curious how we deal with overlaps in published ports)
|
* Renaming DOCKER_ORCHESTRATOR to DOCKER_STACK_ORCHESTRATOR * Renaming config file option "orchestrator" to "stackOrchestrator" * "--orchestrator" flag is no more global but local to stack command and subcommands * Cleaning all global orchestrator code * Replicating Hidden flags in help and Supported flags from root command to stack command Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
312408d
to
87c39da
Compare
I squashed @silvin-lubecki's commits, and added an extra commit that (at least for now) removes the "Orchestration" information from ping @dhiltgen @andrewhsu @vdemeester PTAL |
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
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
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
cli/command/system/version.go
Outdated
@@ -78,7 +77,7 @@ type clientVersion struct { | |||
Arch string | |||
BuildTime string `json:",omitempty"` | |||
Experimental bool | |||
Orchestrator string `json:",omitempty"` | |||
StackOrchestrator string `json:",omitempty"` |
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.
@thaJeztah it looks like this got left in (presumably to keep the changes to a minimum) - seems OK, but we should clean this up as part of a follow up pass.
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.
Good one; was actually doubting whether or not we wanted to keep it; perhaps better to remove it yes, as it will show up in docker version --format '{{json .}}'
I'll grab my laptop and update
The output of this information can be confusing, so removing until we have a better design for this. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The `-k` shorthand was alreaady removed from other commands, so best to be consistent. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
87c39da
to
f0a8598
Compare
@dhiltgen @silvin-lubecki @vdemeester I pushed some additional updates;
Remaining changes
|
cmd := &cobra.Command{ | ||
Use: "stack", | ||
Use: "stack [OPTIONS]", |
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 output isn't actually used for commands that have subcommands, but good to have in case that situation changes in future
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.
SGTM 💦
@@ -102,7 +102,7 @@ func managementSubCommands(cmd *cobra.Command) []*cobra.Command { | |||
var usageTemplate = `Usage: | |||
|
|||
{{- if not .HasSubCommands}} {{.UseLine}}{{end}} | |||
{{- if .HasSubCommands}} {{ .CommandPath}} COMMAND{{end}} | |||
{{- if .HasSubCommands}} {{ .CommandPath}}{{- if .HasAvailableFlags}} [OPTIONS]{{end}} COMMAND{{end}} |
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.
nit: Isn't this change unrelated ? 😝
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.
The docker stack
command itself now has options, but there was no [OPTIONS]
printed 😞
newPsCommand(dockerCli), | ||
newRemoveCommand(dockerCli), | ||
newServicesCommand(dockerCli), | ||
newDeployCommand(dockerCli, &opts), |
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.
oh 😓
PTAL |
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.
SGTM 🐸
@silvin-lubecki talked with @dhiltgen and @thaJeztah ... would prefer to have this PR without 8fb2e7d. the if still strongly desired for inclusion, i'd suggest putting into a new PR. |
8fb2e7d
to
c2c317c
Compare
cli/command/stack/cmd.go
Outdated
@@ -43,13 +42,7 @@ func NewStackCommand(dockerCli command.Cli) *cobra.Command { | |||
} | |||
defaultHelpFunc := cmd.HelpFunc() | |||
cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) { | |||
config := cliconfig.LoadDefaultConfigFile(dockerCli.Err()) // dockerCli is not yet initialized, but we only need config file 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.
Modified the last commit, and removed the warning, but kept these 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.
Moved the warning to #1139 |
c2c317c
to
f0a8598
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.
lgtm
- What I did
All swarm commands (node, service, etc...) were erroring out if the orchestrator was defined as Kubernetes. I moved the
orchestrator
flag, the environment variable and the config file value to more locally values regarding stack command.- How I did it
- How to verify it
$ DOCKER_STACK_ORCHESTRATOR=kubernetes docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION 1u26o5yll4mdqxfr1o86xphb5 * linuxkit-025000000001 Ready Active Leader 18.06.0-ce-dev
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)