-
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
Add kubernetes support to docker/cli #721
Changes from all commits
8417e49
1ff277a
f960d2d
0508c09
dedd0db
b5170bd
0b5883f
f5073f8
3a01d6a
61713c4
ba5d0d8
1a2244e
12c0825
5d375b3
ad40976
f1b1161
18c44e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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") | ||
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 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 | ||
} | ||
|
||
|
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.