Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.2k
Add kubernetes support to docker/cli#721
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
8417e491ff277af960d2d0508c09dedd0dbb5170bd0b5883ff5073f83a01d6a61713c4ba5d0d81a2244e12c08255d375b3ad40976f1b116118c44e0File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Diff view
Diff view
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package command | ||
| import ( | ||
| "fmt" | ||
| "os" | ||
| ) | ||
| // Orchestrator type acts as an enum describing supported orchestrators. | ||
| type Orchestrator string | ||
| const ( | ||
| // OrchestratorKubernetes orchestrator | ||
| OrchestratorKubernetes = Orchestrator("kubernetes") | ||
| // OrchestratorSwarm orchestrator | ||
| OrchestratorSwarm = Orchestrator("swarm") | ||
| orchestratorUnset = Orchestrator("unset") | ||
| defaultOrchestrator = OrchestratorSwarm | ||
| envVarDockerOrchestrator = "DOCKER_ORCHESTRATOR" | ||
| ) | ||
| func normalize(flag string) Orchestrator { | ||
| switch flag { | ||
| case "kubernetes", "k8s": | ||
| return OrchestratorKubernetes | ||
| case "swarm", "swarmkit": | ||
| return OrchestratorSwarm | ||
| default: | ||
| return orchestratorUnset | ||
| } | ||
| } | ||
| // GetOrchestrator checks DOCKER_ORCHESTRATOR environment variable and configuration file | ||
| // orchestrator value and returns user defined Orchestrator. | ||
| func GetOrchestrator(isExperimental bool, flagValue, value string) Orchestrator { | ||
| // Non experimental CLI has kubernetes disabled | ||
| if !isExperimental { | ||
| return defaultOrchestrator | ||
| } | ||
| // Check flag | ||
| if o := normalize(flagValue); o != orchestratorUnset { | ||
| return o | ||
| } | ||
| // Check environment variable | ||
| env := os.Getenv(envVarDockerOrchestrator) | ||
| if o := normalize(env); o != orchestratorUnset { | ||
| return o | ||
| } | ||
| // Check specified orchestrator | ||
| if o := normalize(value); o != orchestratorUnset { | ||
| return o | ||
| } | ||
| if value != "" { | ||
| fmt.Fprintf(os.Stderr, "Specified orchestrator %q is invalid. Please use either kubernetes or swarm\n", value) | ||
| } | ||
| // Nothing set, use default orchestrator | ||
| return defaultOrchestrator | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,10 +18,17 @@ func NewStackCommand(dockerCli command.Cli) *cobra.Command { | ||
| cmd.AddCommand( | ||
| newDeployCommand(dockerCli), | ||
| newListCommand(dockerCli), | ||
| newPsCommand(dockerCli), | ||
| newRemoveCommand(dockerCli), | ||
| newServicesCommand(dockerCli), | ||
| newPsCommand(dockerCli), | ||
| ) | ||
| flags := cmd.PersistentFlags() | ||
| flags.String("namespace", "default", "Kubernetes namespace to use") | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd probably be cleaner to have those flags in a Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't do that one, given how cobra works, we can just use | ||
| flags.SetAnnotation("namespace", "kubernetes", nil) | ||
| flags.SetAnnotation("namespace", "experimentalCLI", nil) | ||
| flags.String("kubeconfig", "", "Kubernetes config file") | ||
| flags.SetAnnotation("kubeconfig", "kubernetes", nil) | ||
| flags.SetAnnotation("kubeconfig", "experimentalCLI", nil) | ||
| return cmd | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
What are the plans with this annotation's value? Are we planning to do (e.g.)
"kubernetes": "1.9"(only available starting from a specific kubernetes version)? If not, would it make sense to use"orchestrator": "swarm"for this? (thinking out loud).edit: we do the same for "experimental", so I guess this is ok (version-check for k8s may still be something to consider using if we expect features to become available only from a certain version of k8s)
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 should also add the new annotations to the YAML generator for the documentation, so that they can be used there to add badges/labels in the documentation; https://github.com/docker/cli/blob/master/docs/yaml/yaml.go
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 am preparing a compose controller version negociation in a followup. I will consider the kubernetes version too.
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 for the YAML generator.