Skip to content

Commit f1b1161

Browse files
Fix PR comments
- More strict on orchestrator flag - Make orchestrator flag more explicit as experimental - Add experimentalCLI annotation on kubernetes flags - Better kubeconfig error message - Prefix service name with stackname in ps and services stack subcommands - Fix yaml documentation - Fix code coverage ignoring generated code Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
1 parent ad40976 commit f1b1161

20 files changed

Lines changed: 83 additions & 52 deletions

File tree

cli/command/cli.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
140140
cli.clientInfo = ClientInfo{
141141
DefaultVersion: cli.client.ClientVersion(),
142142
HasExperimental: hasExperimental,
143-
HasKubernetes: hasExperimental && orchestrator == OrchestratorKubernetes,
144143
Orchestrator: orchestrator,
145144
}
146145
cli.initializeFromClient()
@@ -206,11 +205,15 @@ type ServerInfo struct {
206205
// ClientInfo stores details about the supported features of the client
207206
type ClientInfo struct {
208207
HasExperimental bool
209-
HasKubernetes bool
210208
DefaultVersion string
211209
Orchestrator Orchestrator
212210
}
213211

212+
// HasKubernetes checks if kubernetes orchestrator is enabled
213+
func (c ClientInfo) HasKubernetes() bool {
214+
return c.HasExperimental && c.Orchestrator == OrchestratorKubernetes
215+
}
216+
214217
// NewDockerCli returns a DockerCli instance with IO output and error streams set by in, out and err.
215218
func NewDockerCli(in io.ReadCloser, out, err io.Writer) *DockerCli {
216219
return &DockerCli{in: NewInStream(in), out: NewOutStream(out), err: err}

cli/command/cli_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func TestExperimentalCLI(t *testing.T) {
171171
}
172172

173173
func TestOrchestratorSwitch(t *testing.T) {
174-
defaultVersion := "v1.55"
174+
defaultVersion := "v0.00"
175175

176176
var testcases = []struct {
177177
doc string
@@ -268,7 +268,7 @@ func TestOrchestratorSwitch(t *testing.T) {
268268
}
269269
err := cli.Initialize(options)
270270
assert.NoError(t, err)
271-
assert.Equal(t, testcase.expectedKubernetes, cli.ClientInfo().HasKubernetes)
271+
assert.Equal(t, testcase.expectedKubernetes, cli.ClientInfo().HasKubernetes())
272272
assert.Equal(t, testcase.expectedOrchestrator, string(cli.ClientInfo().Orchestrator))
273273
})
274274
}

cli/command/orchestrator.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package command
33
import (
44
"fmt"
55
"os"
6-
"strings"
76
)
87

98
// Orchestrator type acts as an enum describing supported orchestrators.
@@ -16,12 +15,12 @@ const (
1615
OrchestratorSwarm = Orchestrator("swarm")
1716
orchestratorUnset = Orchestrator("unset")
1817

19-
defaultOrchestrator = OrchestratorSwarm
20-
dockerOrchestrator = "DOCKER_ORCHESTRATOR"
18+
defaultOrchestrator = OrchestratorSwarm
19+
envVarDockerOrchestrator = "DOCKER_ORCHESTRATOR"
2120
)
2221

2322
func normalize(flag string) Orchestrator {
24-
switch strings.ToLower(flag) {
23+
switch flag {
2524
case "kubernetes", "k8s":
2625
return OrchestratorKubernetes
2726
case "swarm", "swarmkit":
@@ -43,7 +42,7 @@ func GetOrchestrator(isExperimental bool, flagValue, value string) Orchestrator
4342
return o
4443
}
4544
// Check environment variable
46-
env := os.Getenv(dockerOrchestrator)
45+
env := os.Getenv(envVarDockerOrchestrator)
4746
if o := normalize(env); o != orchestratorUnset {
4847
return o
4948
}

cli/command/stack/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ func NewStackCommand(dockerCli command.Cli) *cobra.Command {
2525
flags := cmd.PersistentFlags()
2626
flags.String("namespace", "default", "Kubernetes namespace to use")
2727
flags.SetAnnotation("namespace", "kubernetes", nil)
28+
flags.SetAnnotation("namespace", "experimentalCLI", nil)
2829
flags.String("kubeconfig", "", "Kubernetes config file")
2930
flags.SetAnnotation("kubeconfig", "kubernetes", nil)
31+
flags.SetAnnotation("kubeconfig", "experimentalCLI", nil)
3032
return cmd
3133
}
3234

cli/command/stack/deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func newDeployCommand(dockerCli command.Cli) *cobra.Command {
1919
Args: cli.ExactArgs(1),
2020
RunE: func(cmd *cobra.Command, args []string) error {
2121
opts.Namespace = args[0]
22-
if dockerCli.ClientInfo().HasKubernetes {
22+
if dockerCli.ClientInfo().HasKubernetes() {
2323
kli, err := kubernetes.WrapCli(dockerCli, cmd)
2424
if err != nil {
2525
return err

cli/command/stack/kubernetes/cli.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package kubernetes
22

33
import (
4+
"fmt"
45
"os"
56
"path/filepath"
67

@@ -49,7 +50,7 @@ func WrapCli(dockerCli command.Cli, cmd *cobra.Command) (*KubeCli, error) {
4950

5051
config, err := clientcmd.BuildConfigFromFlags("", kubeConfig)
5152
if err != nil {
52-
return nil, err
53+
return nil, fmt.Errorf("Failed to load kubernetes configuration file '%s'", kubeConfig)
5354
}
5455
cli.kubeConfig = config
5556

cli/command/stack/kubernetes/conversion.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,16 @@ func replicasToServices(replicas *appsv1beta2.ReplicaSetList, services *apiv1.Se
126126
if !ok {
127127
return nil, nil, fmt.Errorf("could not find service '%s'", r.Labels[labels.ForServiceName])
128128
}
129+
stack, ok := service.Labels[labels.ForStackName]
130+
if ok {
131+
stack += "_"
132+
}
129133
uid := string(service.UID)
130134
s := swarm.Service{
131135
ID: uid,
132136
Spec: swarm.ServiceSpec{
133137
Annotations: swarm.Annotations{
134-
Name: service.Name,
138+
Name: stack + service.Name,
135139
},
136140
TaskTemplate: swarm.TaskSpec{
137141
ContainerSpec: &swarm.ContainerSpec{

cli/command/stack/kubernetes/deploy.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ func RunDeploy(dockerCli *KubeCli, opts options.Deploy) error {
2020
return errors.Errorf("Please specify a Compose file (with --compose-file).")
2121
}
2222
// Initialize clients
23-
stackInterface, err := dockerCli.stacks()
23+
stacks, err := dockerCli.stacks()
2424
if err != nil {
2525
return err
2626
}
2727
composeClient, err := dockerCli.composeClient()
2828
if err != nil {
2929
return err
3030
}
31-
configMapInterface := composeClient.ConfigMaps()
32-
secretInterface := composeClient.Secrets()
33-
serviceInterface := composeClient.Services()
34-
podInterface := composeClient.Pods()
31+
configMaps := composeClient.ConfigMaps()
32+
secrets := composeClient.Secrets()
33+
services := composeClient.Services()
34+
pods := composeClient.Pods()
3535
watcher := DeployWatcher{
36-
Pods: podInterface,
36+
Pods: pods,
3737
}
3838

3939
// Parse the compose file
@@ -43,28 +43,28 @@ func RunDeploy(dockerCli *KubeCli, opts options.Deploy) error {
4343
}
4444

4545
// FIXME(vdemeester) handle warnings server-side
46-
if err = IsColliding(serviceInterface, stack, cfg); err != nil {
46+
if err = IsColliding(services, stack, cfg); err != nil {
4747
return err
4848
}
4949

50-
if err = createFileBasedConfigMaps(stack.Name, cfg.Configs, configMapInterface); err != nil {
50+
if err = createFileBasedConfigMaps(stack.Name, cfg.Configs, configMaps); err != nil {
5151
return err
5252
}
5353

54-
if err = createFileBasedSecrets(stack.Name, cfg.Secrets, secretInterface); err != nil {
54+
if err = createFileBasedSecrets(stack.Name, cfg.Secrets, secrets); err != nil {
5555
return err
5656
}
5757

58-
if in, err := stackInterface.Get(stack.Name, metav1.GetOptions{}); err == nil {
58+
if in, err := stacks.Get(stack.Name, metav1.GetOptions{}); err == nil {
5959
in.Spec = stack.Spec
6060

61-
if _, err = stackInterface.Update(in); err != nil {
61+
if _, err = stacks.Update(in); err != nil {
6262
return err
6363
}
6464

6565
fmt.Printf("Stack %s was updated\n", stack.Name)
6666
} else {
67-
if _, err = stackInterface.Create(stack); err != nil {
67+
if _, err = stacks.Create(stack); err != nil {
6868
return err
6969
}
7070

@@ -76,7 +76,7 @@ func RunDeploy(dockerCli *KubeCli, opts options.Deploy) error {
7676
<-watcher.Watch(stack, serviceNames(cfg))
7777

7878
fmt.Fprintf(cmdOut, "Stack %s is stable and running\n\n", stack.Name)
79-
// fmt.Fprintf(cmdOut, "Read the logs with:\n $ %s stack logs %s\n", filepath.Base(os.Args[0]), stack.Name)
79+
// TODO: fmt.Fprintf(cmdOut, "Read the logs with:\n $ %s stack logs %s\n", filepath.Base(os.Args[0]), stack.Name)
8080

8181
return nil
8282
}

cli/command/stack/kubernetes/ps.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ func RunPS(dockerCli *KubeCli, options options.PS) error {
5555
for i, pod := range pods {
5656
tasks[i] = podToTask(pod)
5757
}
58-
return print(dockerCli, tasks, pods, nodeResolver, !options.NoTrunc, options.Quiet, format)
58+
return print(dockerCli, namespace, tasks, pods, nodeResolver, !options.NoTrunc, options.Quiet, format)
5959
}
6060

6161
type idResolver func(name string) (string, error)
6262

63-
func print(dockerCli command.Cli, tasks []swarm.Task, pods []apiv1.Pod, nodeResolver idResolver, trunc, quiet bool, format string) error {
63+
func print(dockerCli command.Cli, namespace string, tasks []swarm.Task, pods []apiv1.Pod, nodeResolver idResolver, trunc, quiet bool, format string) error {
6464
sort.Stable(tasksBySlot(tasks))
6565

6666
names := map[string]string{}
@@ -78,7 +78,7 @@ func print(dockerCli command.Cli, tasks []swarm.Task, pods []apiv1.Pod, nodeReso
7878
return err
7979
}
8080

81-
names[task.ID] = pods[i].Name
81+
names[task.ID] = fmt.Sprintf("%s_%s", namespace, pods[i].Name)
8282
nodes[task.ID] = nodeValue
8383
}
8484

cli/command/stack/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
1818
Short: "List stacks",
1919
Args: cli.NoArgs,
2020
RunE: func(cmd *cobra.Command, args []string) error {
21-
if dockerCli.ClientInfo().HasKubernetes {
21+
if dockerCli.ClientInfo().HasKubernetes() {
2222
kli, err := kubernetes.WrapCli(dockerCli, cmd)
2323
if err != nil {
2424
return err

0 commit comments

Comments
 (0)