Skip to content

Commit 1b347cf

Browse files
committed
Fixing moby#24631, inspect output on swarm object types without labels is empty object {}
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
1 parent 3dc8771 commit 1b347cf

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

api/types/swarm/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Meta struct {
1717
// Annotations represents how to describe an object.
1818
type Annotations struct {
1919
Name string `json:",omitempty"`
20-
Labels map[string]string `json:",omitempty"`
20+
Labels map[string]string `json:"Labels"`
2121
}
2222

2323
// Driver represents a driver (network, logging).

daemon/cluster/convert/network.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ func networkFromGRPC(n *swarmapi.Network) types.Network {
3939
network.UpdatedAt, _ = gogotypes.TimestampFromProto(n.Meta.UpdatedAt)
4040

4141
//Annotations
42-
network.Spec.Name = n.Spec.Annotations.Name
43-
network.Spec.Labels = n.Spec.Annotations.Labels
42+
network.Spec.Annotations = annotationsFromGRPC(n.Spec.Annotations)
4443

4544
//DriverConfiguration
4645
if n.Spec.DriverConfig != nil {

daemon/cluster/convert/node.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ func NodeFromGRPC(n swarmapi.Node) types.Node {
3030
node.UpdatedAt, _ = gogotypes.TimestampFromProto(n.Meta.UpdatedAt)
3131

3232
//Annotations
33-
node.Spec.Name = n.Spec.Annotations.Name
34-
node.Spec.Labels = n.Spec.Annotations.Labels
33+
node.Spec.Annotations = annotationsFromGRPC(n.Spec.Annotations)
3534

3635
//Description
3736
if n.Description != nil {

daemon/cluster/convert/secret.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ func SecretFromGRPC(s *swarmapi.Secret) swarmtypes.Secret {
1111
secret := swarmtypes.Secret{
1212
ID: s.ID,
1313
Spec: swarmtypes.SecretSpec{
14-
Annotations: swarmtypes.Annotations{
15-
Name: s.Spec.Annotations.Name,
16-
Labels: s.Spec.Annotations.Labels,
17-
},
18-
Data: s.Spec.Data,
14+
Annotations: annotationsFromGRPC(s.Spec.Annotations),
15+
Data: s.Spec.Data,
1916
},
2017
}
2118

daemon/cluster/convert/service.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ func serviceSpecFromGRPC(spec *swarmapi.ServiceSpec) *types.ServiceSpec {
7070

7171
containerConfig := spec.Task.Runtime.(*swarmapi.TaskSpec_Container).Container
7272
convertedSpec := &types.ServiceSpec{
73-
Annotations: types.Annotations{
74-
Name: spec.Annotations.Name,
75-
Labels: spec.Annotations.Labels,
76-
},
77-
73+
Annotations: annotationsFromGRPC(spec.Annotations),
7874
TaskTemplate: types.TaskSpec{
7975
ContainerSpec: containerSpecFromGRPC(containerConfig),
8076
Resources: resourcesFromGRPC(spec.Task.Resources),
@@ -236,6 +232,19 @@ func ServiceSpecToGRPC(s types.ServiceSpec) (swarmapi.ServiceSpec, error) {
236232
return spec, nil
237233
}
238234

235+
func annotationsFromGRPC(ann swarmapi.Annotations) types.Annotations {
236+
a := types.Annotations{
237+
Name: ann.Name,
238+
Labels: ann.Labels,
239+
}
240+
241+
if a.Labels == nil {
242+
a.Labels = make(map[string]string)
243+
}
244+
245+
return a
246+
}
247+
239248
func resourcesFromGRPC(res *swarmapi.ResourceRequirements) *types.ResourceRequirements {
240249
var resources *types.ResourceRequirements
241250
if res != nil {

daemon/cluster/convert/swarm.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ func SwarmFromGRPC(c swarmapi.Cluster) types.Swarm {
5656
swarm.UpdatedAt, _ = gogotypes.TimestampFromProto(c.Meta.UpdatedAt)
5757

5858
// Annotations
59-
swarm.Spec.Name = c.Spec.Annotations.Name
60-
swarm.Spec.Labels = c.Spec.Annotations.Labels
59+
swarm.Spec.Annotations = annotationsFromGRPC(c.Spec.Annotations)
6160

6261
return swarm
6362
}

daemon/cluster/convert/task.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@ func TaskFromGRPC(t swarmapi.Task) types.Task {
2121
}
2222

2323
task := types.Task{
24-
ID: t.ID,
25-
Annotations: types.Annotations{
26-
Name: t.Annotations.Name,
27-
Labels: t.Annotations.Labels,
28-
},
29-
ServiceID: t.ServiceID,
30-
Slot: int(t.Slot),
31-
NodeID: t.NodeID,
24+
ID: t.ID,
25+
Annotations: annotationsFromGRPC(t.Annotations),
26+
ServiceID: t.ServiceID,
27+
Slot: int(t.Slot),
28+
NodeID: t.NodeID,
3229
Spec: types.TaskSpec{
3330
ContainerSpec: containerSpecFromGRPC(containerConfig),
3431
Resources: resourcesFromGRPC(t.Spec.Resources),

0 commit comments

Comments
 (0)