Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.2k
Services: use ServiceStatus on API v1.41 and up#2157
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
962015b228e0f57405ac520424e2File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -33,29 +33,37 @@ func TestServiceContextWrite(t *testing.T) { | ||
| // Table format | ||
| { | ||
| formatter.Context{Format: NewListFormat("table", false)}, | ||
| `ID NAME MODE REPLICAS IMAGE PORTS | ||
| id_baz baz global 2/4 *:80->8080/tcp | ||
| id_bar bar replicated 2/4 *:80->8080/tcp | ||
| `ID NAME MODE REPLICAS IMAGE PORTS | ||
| 02_bar bar replicated 2/4 *:80->8090/udp | ||
Contributor 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. Shouldn't this be sorted by service name? 🤔 Contributor 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. Ok just saw your comment below 👍 | ||
| 01_baz baz global 1/3 *:80->8080/tcp | ||
MemberAuthor 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. changed the replica-count to be unique for each service, to verify we're showing the correct status | ||
| 04_qux2 qux2 replicated 3/3 (max 2 per node) | ||
| 03_qux10 qux10 replicated 2/3 (max 1 per node) | ||
MemberAuthor 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. Added test-cases to test the | ||
| `, | ||
| }, | ||
| { | ||
| formatter.Context{Format: NewListFormat("table", true)}, | ||
| `id_baz | ||
| id_bar | ||
| `02_bar | ||
| 01_baz | ||
| 04_qux2 | ||
| 03_qux10 | ||
| `, | ||
| }, | ||
| { | ||
| formatter.Context{Format: NewListFormat("table {{.Name}}", false)}, | ||
| `NAME | ||
| baz | ||
| bar | ||
| formatter.Context{Format: NewListFormat("table {{.Name}}\t{{.Mode}}", false)}, | ||
| `NAME MODE | ||
| bar replicated | ||
| baz global | ||
| qux2 replicated | ||
| qux10 replicated | ||
MemberAuthor 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. Sorting moved to the formatter (see the PR description), which is why these tests now have their output in a different order. I added services named | ||
| `, | ||
| }, | ||
| { | ||
| formatter.Context{Format: NewListFormat("table {{.Name}}", true)}, | ||
| `NAME | ||
| baz | ||
| bar | ||
| baz | ||
| qux2 | ||
| qux10 | ||
| `, | ||
| }, | ||
| // Raw Format | ||
| @@ -65,25 +73,32 @@ bar | ||
| }, | ||
| { | ||
| formatter.Context{Format: NewListFormat("raw", true)}, | ||
| `id: id_baz | ||
| id: id_bar | ||
| `id: 02_bar | ||
| id: 01_baz | ||
| id: 04_qux2 | ||
| id: 03_qux10 | ||
| `, | ||
| }, | ||
| // Custom Format | ||
| { | ||
| formatter.Context{Format: NewListFormat("{{.Name}}", false)}, | ||
| `baz | ||
| bar | ||
| `bar | ||
| baz | ||
| qux2 | ||
| qux10 | ||
| `, | ||
| }, | ||
| } | ||
| for _, testcase := range cases { | ||
| services := []swarm.Service{ | ||
| { | ||
| ID: "id_baz", | ||
| ID: "01_baz", | ||
MemberAuthor 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. prefixing the ID's with numbers, so that we verify the list is sorted by the service name not the service ID | ||
| Spec: swarm.ServiceSpec{ | ||
| Annotations: swarm.Annotations{Name: "baz"}, | ||
| Mode: swarm.ServiceMode{ | ||
| Global: &swarm.GlobalService{}, | ||
| }, | ||
| }, | ||
| Endpoint: swarm.Endpoint{ | ||
| Ports: []swarm.PortConfig{ | ||
| @@ -95,37 +110,70 @@ bar | ||
| }, | ||
| }, | ||
| }, | ||
| ServiceStatus: &swarm.ServiceStatus{ | ||
| RunningTasks: 1, | ||
| DesiredTasks: 3, | ||
| }, | ||
| }, | ||
| { | ||
| ID: "id_bar", | ||
| ID: "02_bar", | ||
| Spec: swarm.ServiceSpec{ | ||
| Annotations: swarm.Annotations{Name: "bar"}, | ||
| Mode: swarm.ServiceMode{ | ||
| Replicated: &swarm.ReplicatedService{}, | ||
| }, | ||
| }, | ||
| Endpoint: swarm.Endpoint{ | ||
| Ports: []swarm.PortConfig{ | ||
| { | ||
| PublishMode: "ingress", | ||
| PublishedPort: 80, | ||
| TargetPort: 8080, | ||
| Protocol: "tcp", | ||
| TargetPort: 8090, | ||
| ||
| Protocol: "udp", | ||
| }, | ||
| }, | ||
| }, | ||
| ServiceStatus: &swarm.ServiceStatus{ | ||
| RunningTasks: 2, | ||
| DesiredTasks: 4, | ||
| }, | ||
| }, | ||
| } | ||
| info := map[string]ListInfo{ | ||
| "id_baz": { | ||
| Mode: "global", | ||
| Replicas: "2/4", | ||
| { | ||
| ID: "03_qux10", | ||
| Spec: swarm.ServiceSpec{ | ||
| Annotations: swarm.Annotations{Name: "qux10"}, | ||
| Mode: swarm.ServiceMode{ | ||
| Replicated: &swarm.ReplicatedService{}, | ||
| }, | ||
| TaskTemplate: swarm.TaskSpec{ | ||
| Placement: &swarm.Placement{MaxReplicas: 1}, | ||
| }, | ||
| }, | ||
| ServiceStatus: &swarm.ServiceStatus{ | ||
| RunningTasks: 2, | ||
| DesiredTasks: 3, | ||
| }, | ||
| }, | ||
| "id_bar": { | ||
| Mode: "replicated", | ||
| Replicas: "2/4", | ||
| { | ||
| ID: "04_qux2", | ||
| Spec: swarm.ServiceSpec{ | ||
| Annotations: swarm.Annotations{Name: "qux2"}, | ||
| Mode: swarm.ServiceMode{ | ||
| Replicated: &swarm.ReplicatedService{}, | ||
| }, | ||
| TaskTemplate: swarm.TaskSpec{ | ||
| Placement: &swarm.Placement{MaxReplicas: 2}, | ||
| }, | ||
| }, | ||
| ServiceStatus: &swarm.ServiceStatus{ | ||
| RunningTasks: 3, | ||
| DesiredTasks: 3, | ||
| }, | ||
| }, | ||
| } | ||
| out := bytes.NewBufferString("") | ||
| testcase.context.Output = out | ||
| err := ListFormatWrite(testcase.context, services, info) | ||
| err := ListFormatWrite(testcase.context, services) | ||
| if err != nil { | ||
| assert.Error(t, err, testcase.expected) | ||
| } else { | ||
| @@ -137,9 +185,12 @@ bar | ||
| func TestServiceContextWriteJSON(t *testing.T) { | ||
| services := []swarm.Service{ | ||
| { | ||
| ID: "id_baz", | ||
| ID: "01_baz", | ||
| Spec: swarm.ServiceSpec{ | ||
| Annotations: swarm.Annotations{Name: "baz"}, | ||
| Mode: swarm.ServiceMode{ | ||
| Global: &swarm.GlobalService{}, | ||
| }, | ||
| }, | ||
| Endpoint: swarm.Endpoint{ | ||
| Ports: []swarm.PortConfig{ | ||
| @@ -151,11 +202,18 @@ func TestServiceContextWriteJSON(t *testing.T) { | ||
| }, | ||
| }, | ||
| }, | ||
| ServiceStatus: &swarm.ServiceStatus{ | ||
| RunningTasks: 1, | ||
| DesiredTasks: 3, | ||
| }, | ||
| }, | ||
| { | ||
| ID: "id_bar", | ||
| ID: "02_bar", | ||
| Spec: swarm.ServiceSpec{ | ||
| Annotations: swarm.Annotations{Name: "bar"}, | ||
| Mode: swarm.ServiceMode{ | ||
| Replicated: &swarm.ReplicatedService{}, | ||
| }, | ||
| }, | ||
| Endpoint: swarm.Endpoint{ | ||
| Ports: []swarm.PortConfig{ | ||
| @@ -167,25 +225,19 @@ func TestServiceContextWriteJSON(t *testing.T) { | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| info := map[string]ListInfo{ | ||
| "id_baz": { | ||
| Mode: "global", | ||
| Replicas: "2/4", | ||
| }, | ||
| "id_bar": { | ||
| Mode: "replicated", | ||
| Replicas: "2/4", | ||
| ServiceStatus: &swarm.ServiceStatus{ | ||
| RunningTasks: 2, | ||
| DesiredTasks: 4, | ||
| }, | ||
| }, | ||
| } | ||
| expectedJSONs := []map[string]interface{}{ | ||
| {"ID": "id_baz", "Name": "baz", "Mode": "global", "Replicas": "2/4", "Image": "", "Ports": "*:80->8080/tcp"}, | ||
| {"ID": "id_bar", "Name": "bar", "Mode": "replicated", "Replicas": "2/4", "Image": "", "Ports": "*:80->8080/tcp"}, | ||
| {"ID": "02_bar", "Name": "bar", "Mode": "replicated", "Replicas": "2/4", "Image": "", "Ports": "*:80->8080/tcp"}, | ||
| {"ID": "01_baz", "Name": "baz", "Mode": "global", "Replicas": "1/3", "Image": "", "Ports": "*:80->8080/tcp"}, | ||
| } | ||
| out := bytes.NewBufferString("") | ||
| err := ListFormatWrite(formatter.Context{Format: "{{json .}}", Output: out}, services, info) | ||
| err := ListFormatWrite(formatter.Context{Format: "{{json .}}", Output: out}, services) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| @@ -199,21 +251,35 @@ func TestServiceContextWriteJSON(t *testing.T) { | ||
| } | ||
| func TestServiceContextWriteJSONField(t *testing.T) { | ||
| services := []swarm.Service{ | ||
| {ID: "id_baz", Spec: swarm.ServiceSpec{Annotations: swarm.Annotations{Name: "baz"}}}, | ||
| {ID: "id_bar", Spec: swarm.ServiceSpec{Annotations: swarm.Annotations{Name: "bar"}}}, | ||
| } | ||
| info := map[string]ListInfo{ | ||
| "id_baz": { | ||
| Mode: "global", | ||
| Replicas: "2/4", | ||
| { | ||
| ID: "01_baz", | ||
| Spec: swarm.ServiceSpec{ | ||
| Annotations: swarm.Annotations{Name: "baz"}, | ||
| Mode: swarm.ServiceMode{ | ||
| Global: &swarm.GlobalService{}, | ||
| }, | ||
| }, | ||
| ServiceStatus: &swarm.ServiceStatus{ | ||
| RunningTasks: 2, | ||
| DesiredTasks: 4, | ||
| }, | ||
| }, | ||
| "id_bar": { | ||
| Mode: "replicated", | ||
| Replicas: "2/4", | ||
| { | ||
| ID: "24_bar", | ||
| Spec: swarm.ServiceSpec{ | ||
| Annotations: swarm.Annotations{Name: "bar"}, | ||
| Mode: swarm.ServiceMode{ | ||
| Replicated: &swarm.ReplicatedService{}, | ||
| }, | ||
| }, | ||
| ServiceStatus: &swarm.ServiceStatus{ | ||
| RunningTasks: 2, | ||
| DesiredTasks: 4, | ||
| }, | ||
| }, | ||
| } | ||
| out := bytes.NewBufferString("") | ||
| err := ListFormatWrite(formatter.Context{Format: "{{json .Name}}", Output: out}, services, info) | ||
| err := ListFormatWrite(formatter.Context{Format: "{{json .Name}}", Output: out}, services) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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 want to export this one, so that it can be used in
--format, but keeping that separate to reduce the changes a bit