Skip to content

Commit 8108934

Browse files
Add an orchestrator column in the docker stack ls command
Signed-off-by: Silvin Lubecki <[email protected]>
1 parent 8023cba commit 8108934

7 files changed

Lines changed: 32 additions & 22 deletions

File tree

cli/command/formatter/stack.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import (
55
)
66

77
const (
8-
defaultStackTableFormat = "table {{.Name}}\t{{.Services}}"
8+
defaultStackTableFormat = "table {{.Name}}\t{{.Services}}\t{{.Orchestrator}}"
99

10-
stackServicesHeader = "SERVICES"
10+
stackServicesHeader = "SERVICES"
11+
stackOrchestrastorHeader = "ORCHESTRATOR"
1112
)
1213

1314
// Stack contains deployed stack information.
@@ -16,6 +17,8 @@ type Stack struct {
1617
Name string
1718
// Services is the number of the services
1819
Services int
20+
// Orchestratort is the platform on which the stack is deployed
21+
Orchestrator string
1922
}
2023

2124
// NewStackFormat returns a format for use with a stack Context
@@ -48,8 +51,9 @@ type stackContext struct {
4851
func newStackContext() *stackContext {
4952
stackCtx := stackContext{}
5053
stackCtx.header = map[string]string{
51-
"Name": nameHeader,
52-
"Services": stackServicesHeader,
54+
"Name": nameHeader,
55+
"Services": stackServicesHeader,
56+
"Orchestrator": stackOrchestrastorHeader,
5357
}
5458
return &stackCtx
5559
}
@@ -65,3 +69,7 @@ func (s *stackContext) Name() string {
6569
func (s *stackContext) Services() string {
6670
return strconv.Itoa(s.s.Services)
6771
}
72+
73+
func (s *stackContext) Orchestrator() string {
74+
return s.s.Orchestrator
75+
}

cli/command/formatter/stack_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ func TestStackContextWrite(t *testing.T) {
2727
// Table format
2828
{
2929
Context{Format: NewStackFormat("table")},
30-
`NAME SERVICES
31-
baz 2
32-
bar 1
30+
`NAME SERVICES ORCHESTRATOR
31+
baz 2 orchestrator1
32+
bar 1 orchestrator2
3333
`,
3434
},
3535
{
@@ -49,8 +49,8 @@ bar
4949
}
5050

5151
stacks := []*Stack{
52-
{Name: "baz", Services: 2},
53-
{Name: "bar", Services: 1},
52+
{Name: "baz", Services: 2, Orchestrator: "orchestrator1"},
53+
{Name: "bar", Services: 1, Orchestrator: "orchestrator2"},
5454
}
5555
for _, testcase := range cases {
5656
out := bytes.NewBufferString("")

cli/command/stack/kubernetes/list.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ func getStacks(kubeCli *KubeCli) ([]*formatter.Stack, error) {
4646
var formattedStacks []*formatter.Stack
4747
for _, stack := range stacks {
4848
formattedStacks = append(formattedStacks, &formatter.Stack{
49-
Name: stack.name,
50-
Services: len(stack.getServices()),
49+
Name: stack.name,
50+
Services: len(stack.getServices()),
51+
Orchestrator: "Kubernetes",
5152
})
5253
}
5354
return formattedStacks, nil

cli/command/stack/swarm/list.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ func getStacks(ctx context.Context, apiclient client.APIClient) ([]*formatter.St
5959
ztack, ok := m[name]
6060
if !ok {
6161
m[name] = &formatter.Stack{
62-
Name: name,
63-
Services: 1,
62+
Name: name,
63+
Services: 1,
64+
Orchestrator: "Swarm",
6465
}
6566
} else {
6667
ztack.Services++
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
NAME SERVICES
2-
service-name-1-foo 1
3-
service-name-2-foo 1
4-
service-name-10-foo 1
1+
NAME SERVICES ORCHESTRATOR
2+
service-name-1-foo 1 Swarm
3+
service-name-2-foo 1 Swarm
4+
service-name-10-foo 1 Swarm
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
NAME SERVICES
2-
service-name-bar 1
3-
service-name-foo 1
1+
NAME SERVICES ORCHESTRATOR
2+
service-name-bar 1 Swarm
3+
service-name-foo 1 Swarm
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
NAME SERVICES
2-
service-name-foo 1
1+
NAME SERVICES ORCHESTRATOR
2+
service-name-foo 1 Swarm

0 commit comments

Comments
 (0)