Skip to content

Commit

Permalink
Add an orchestrator column in the docker stack ls command
Browse files Browse the repository at this point in the history
Signed-off-by: Silvin Lubecki <[email protected]>
  • Loading branch information
silvin-lubecki committed Mar 27, 2018
1 parent 8023cba commit 8b27b4b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
16 changes: 12 additions & 4 deletions cli/command/formatter/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
)

const (
defaultStackTableFormat = "table {{.Name}}\t{{.Services}}"
defaultStackTableFormat = "table {{.Name}}\t{{.Services}}\t{{.Orchestrator}}"

stackServicesHeader = "SERVICES"
stackServicesHeader = "SERVICES"
stackOrchestrastorHeader = "ORCHESTRATOR"
)

// Stack contains deployed stack information.
Expand All @@ -16,6 +17,8 @@ type Stack struct {
Name string
// Services is the number of the services
Services int
// Orchestratort is the platform on which the stack is deployed
Orchestrator string
}

// NewStackFormat returns a format for use with a stack Context
Expand Down Expand Up @@ -48,8 +51,9 @@ type stackContext struct {
func newStackContext() *stackContext {
stackCtx := stackContext{}
stackCtx.header = map[string]string{
"Name": nameHeader,
"Services": stackServicesHeader,
"Name": nameHeader,
"Services": stackServicesHeader,
"Orchestrator": stackOrchestrastorHeader,
}
return &stackCtx
}
Expand All @@ -65,3 +69,7 @@ func (s *stackContext) Name() string {
func (s *stackContext) Services() string {
return strconv.Itoa(s.s.Services)
}

func (s *stackContext) Orchestrator() string {
return s.s.Orchestrator
}
10 changes: 5 additions & 5 deletions cli/command/formatter/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func TestStackContextWrite(t *testing.T) {
// Table format
{
Context{Format: NewStackFormat("table")},
`NAME SERVICES
baz 2
bar 1
`NAME SERVICES ORCHESTRATOR
baz 2 orchestrator1
bar 1 orchestrator2
`,
},
{
Expand All @@ -49,8 +49,8 @@ bar
}

stacks := []*Stack{
{Name: "baz", Services: 2},
{Name: "bar", Services: 1},
{Name: "baz", Services: 2, Orchestrator: "orchestrator1"},
{Name: "bar", Services: 1, Orchestrator: "orchestrator2"},
}
for _, testcase := range cases {
out := bytes.NewBufferString("")
Expand Down
5 changes: 3 additions & 2 deletions cli/command/stack/kubernetes/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ func getStacks(kubeCli *KubeCli) ([]*formatter.Stack, error) {
var formattedStacks []*formatter.Stack
for _, stack := range stacks {
formattedStacks = append(formattedStacks, &formatter.Stack{
Name: stack.name,
Services: len(stack.getServices()),
Name: stack.name,
Services: len(stack.getServices()),
Orchestrator: "Kubernetes",
})
}
return formattedStacks, nil
Expand Down
5 changes: 3 additions & 2 deletions cli/command/stack/swarm/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ func getStacks(ctx context.Context, apiclient client.APIClient) ([]*formatter.St
ztack, ok := m[name]
if !ok {
m[name] = &formatter.Stack{
Name: name,
Services: 1,
Name: name,
Services: 1,
Orchestrator: "Swarm",
}
} else {
ztack.Services++
Expand Down

0 comments on commit 8b27b4b

Please sign in to comment.