Add an orchestrator column in the docker stack ls command

Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
This commit is contained in:
Silvin Lubecki 2018-03-27 16:38:47 +02:00 committed by Mathieu Champlon
parent 8963ab993e
commit 13d0c9c695
8 changed files with 40 additions and 29 deletions

View File

@ -5,9 +5,10 @@ import (
) )
const ( const (
defaultStackTableFormat = "table {{.Name}}\t{{.Services}}" defaultStackTableFormat = "table {{.Name}}\t{{.Services}}\t{{.Orchestrator}}"
stackServicesHeader = "SERVICES" stackServicesHeader = "SERVICES"
stackOrchestrastorHeader = "ORCHESTRATOR"
) )
// Stack contains deployed stack information. // Stack contains deployed stack information.
@ -16,6 +17,8 @@ type Stack struct {
Name string Name string
// Services is the number of the services // Services is the number of the services
Services int Services int
// Orchestratort is the platform on which the stack is deployed
Orchestrator string
} }
// NewStackFormat returns a format for use with a stack Context // NewStackFormat returns a format for use with a stack Context
@ -50,6 +53,7 @@ func newStackContext() *stackContext {
stackCtx.header = map[string]string{ stackCtx.header = map[string]string{
"Name": nameHeader, "Name": nameHeader,
"Services": stackServicesHeader, "Services": stackServicesHeader,
"Orchestrator": stackOrchestrastorHeader,
} }
return &stackCtx return &stackCtx
} }
@ -65,3 +69,7 @@ func (s *stackContext) Name() string {
func (s *stackContext) Services() string { func (s *stackContext) Services() string {
return strconv.Itoa(s.s.Services) return strconv.Itoa(s.s.Services)
} }
func (s *stackContext) Orchestrator() string {
return s.s.Orchestrator
}

View File

@ -27,9 +27,9 @@ func TestStackContextWrite(t *testing.T) {
// Table format // Table format
{ {
Context{Format: NewStackFormat("table")}, Context{Format: NewStackFormat("table")},
`NAME SERVICES `NAME SERVICES ORCHESTRATOR
baz 2 baz 2 orchestrator1
bar 1 bar 1 orchestrator2
`, `,
}, },
{ {
@ -49,8 +49,8 @@ bar
} }
stacks := []*Stack{ stacks := []*Stack{
{Name: "baz", Services: 2}, {Name: "baz", Services: 2, Orchestrator: "orchestrator1"},
{Name: "bar", Services: 1}, {Name: "bar", Services: 1, Orchestrator: "orchestrator2"},
} }
for _, testcase := range cases { for _, testcase := range cases {
out := bytes.NewBufferString("") out := bytes.NewBufferString("")

View File

@ -48,6 +48,7 @@ func getStacks(kubeCli *KubeCli) ([]*formatter.Stack, error) {
formattedStacks = append(formattedStacks, &formatter.Stack{ formattedStacks = append(formattedStacks, &formatter.Stack{
Name: stack.name, Name: stack.name,
Services: len(stack.getServices()), Services: len(stack.getServices()),
Orchestrator: "Kubernetes",
}) })
} }
return formattedStacks, nil return formattedStacks, nil

View File

@ -61,6 +61,7 @@ func getStacks(ctx context.Context, apiclient client.APIClient) ([]*formatter.St
m[name] = &formatter.Stack{ m[name] = &formatter.Stack{
Name: name, Name: name,
Services: 1, Services: 1,
Orchestrator: "Swarm",
} }
} else { } else {
ztack.Services++ ztack.Services++

View File

@ -1,4 +1,4 @@
NAME SERVICES NAME SERVICES ORCHESTRATOR
service-name-1-foo 1 service-name-1-foo 1 Swarm
service-name-2-foo 1 service-name-2-foo 1 Swarm
service-name-10-foo 1 service-name-10-foo 1 Swarm

View File

@ -1,3 +1,3 @@
NAME SERVICES NAME SERVICES ORCHESTRATOR
service-name-bar 1 service-name-bar 1 Swarm
service-name-foo 1 service-name-foo 1 Swarm

View File

@ -1,2 +1,2 @@
NAME SERVICES NAME SERVICES ORCHESTRATOR
service-name-foo 1 service-name-foo 1 Swarm

View File

@ -39,9 +39,9 @@ The following command shows all stacks and some additional information:
```bash ```bash
$ docker stack ls $ docker stack ls
ID SERVICES ID SERVICES ORCHESTRATOR
vossibility-stack 6 myapp 2 Kubernetes
myapp 2 vossibility-stack 6 Swarm
``` ```
### Formatting ### Formatting
@ -51,9 +51,10 @@ The formatting option (`--format`) pretty-prints stacks using a Go template.
Valid placeholders for the Go template are listed below: Valid placeholders for the Go template are listed below:
| Placeholder | Description | | Placeholder | Description |
| ----------- | ------------------ | | --------------- | ------------------ |
| `.Name` | Stack name | | `.Name` | Stack name |
| `.Services` | Number of services | | `.Services` | Number of services |
| `.Orchestrator` | Orchestrator name |
When using the `--format` option, the `stack ls` command either outputs When using the `--format` option, the `stack ls` command either outputs
the data exactly as the template declares or, when using the the data exactly as the template declares or, when using the