From 1b347cfc795407ced5eae60cb3ceadfdab8a8f4f Mon Sep 17 00:00:00 2001 From: Arash Deshmeh Date: Mon, 13 Feb 2017 03:07:03 -0500 Subject: [PATCH] Fixing #24631, inspect output on swarm object types without labels is empty object {} Signed-off-by: Arash Deshmeh --- api/types/swarm/common.go | 2 +- daemon/cluster/convert/network.go | 3 +-- daemon/cluster/convert/node.go | 3 +-- daemon/cluster/convert/secret.go | 7 ++----- daemon/cluster/convert/service.go | 19 ++++++++++++++----- daemon/cluster/convert/swarm.go | 3 +-- daemon/cluster/convert/task.go | 13 +++++-------- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/api/types/swarm/common.go b/api/types/swarm/common.go index 64a648bad1..dc76a146bb 100644 --- a/api/types/swarm/common.go +++ b/api/types/swarm/common.go @@ -17,7 +17,7 @@ type Meta struct { // Annotations represents how to describe an object. type Annotations struct { Name string `json:",omitempty"` - Labels map[string]string `json:",omitempty"` + Labels map[string]string `json:"Labels"` } // Driver represents a driver (network, logging). diff --git a/daemon/cluster/convert/network.go b/daemon/cluster/convert/network.go index c28bc2b503..6bc19543a7 100644 --- a/daemon/cluster/convert/network.go +++ b/daemon/cluster/convert/network.go @@ -39,8 +39,7 @@ func networkFromGRPC(n *swarmapi.Network) types.Network { network.UpdatedAt, _ = gogotypes.TimestampFromProto(n.Meta.UpdatedAt) //Annotations - network.Spec.Name = n.Spec.Annotations.Name - network.Spec.Labels = n.Spec.Annotations.Labels + network.Spec.Annotations = annotationsFromGRPC(n.Spec.Annotations) //DriverConfiguration if n.Spec.DriverConfig != nil { diff --git a/daemon/cluster/convert/node.go b/daemon/cluster/convert/node.go index 1c2eba4bfa..fe6cdfee9e 100644 --- a/daemon/cluster/convert/node.go +++ b/daemon/cluster/convert/node.go @@ -30,8 +30,7 @@ func NodeFromGRPC(n swarmapi.Node) types.Node { node.UpdatedAt, _ = gogotypes.TimestampFromProto(n.Meta.UpdatedAt) //Annotations - node.Spec.Name = n.Spec.Annotations.Name - node.Spec.Labels = n.Spec.Annotations.Labels + node.Spec.Annotations = annotationsFromGRPC(n.Spec.Annotations) //Description if n.Description != nil { diff --git a/daemon/cluster/convert/secret.go b/daemon/cluster/convert/secret.go index f0afd4d2ec..91d67736ad 100644 --- a/daemon/cluster/convert/secret.go +++ b/daemon/cluster/convert/secret.go @@ -11,11 +11,8 @@ func SecretFromGRPC(s *swarmapi.Secret) swarmtypes.Secret { secret := swarmtypes.Secret{ ID: s.ID, Spec: swarmtypes.SecretSpec{ - Annotations: swarmtypes.Annotations{ - Name: s.Spec.Annotations.Name, - Labels: s.Spec.Annotations.Labels, - }, - Data: s.Spec.Data, + Annotations: annotationsFromGRPC(s.Spec.Annotations), + Data: s.Spec.Data, }, } diff --git a/daemon/cluster/convert/service.go b/daemon/cluster/convert/service.go index 3adba146ee..a22e0b012a 100644 --- a/daemon/cluster/convert/service.go +++ b/daemon/cluster/convert/service.go @@ -70,11 +70,7 @@ func serviceSpecFromGRPC(spec *swarmapi.ServiceSpec) *types.ServiceSpec { containerConfig := spec.Task.Runtime.(*swarmapi.TaskSpec_Container).Container convertedSpec := &types.ServiceSpec{ - Annotations: types.Annotations{ - Name: spec.Annotations.Name, - Labels: spec.Annotations.Labels, - }, - + Annotations: annotationsFromGRPC(spec.Annotations), TaskTemplate: types.TaskSpec{ ContainerSpec: containerSpecFromGRPC(containerConfig), Resources: resourcesFromGRPC(spec.Task.Resources), @@ -236,6 +232,19 @@ func ServiceSpecToGRPC(s types.ServiceSpec) (swarmapi.ServiceSpec, error) { return spec, nil } +func annotationsFromGRPC(ann swarmapi.Annotations) types.Annotations { + a := types.Annotations{ + Name: ann.Name, + Labels: ann.Labels, + } + + if a.Labels == nil { + a.Labels = make(map[string]string) + } + + return a +} + func resourcesFromGRPC(res *swarmapi.ResourceRequirements) *types.ResourceRequirements { var resources *types.ResourceRequirements if res != nil { diff --git a/daemon/cluster/convert/swarm.go b/daemon/cluster/convert/swarm.go index 3cbfbeb129..98e0ce25e6 100644 --- a/daemon/cluster/convert/swarm.go +++ b/daemon/cluster/convert/swarm.go @@ -56,8 +56,7 @@ func SwarmFromGRPC(c swarmapi.Cluster) types.Swarm { swarm.UpdatedAt, _ = gogotypes.TimestampFromProto(c.Meta.UpdatedAt) // Annotations - swarm.Spec.Name = c.Spec.Annotations.Name - swarm.Spec.Labels = c.Spec.Annotations.Labels + swarm.Spec.Annotations = annotationsFromGRPC(c.Spec.Annotations) return swarm } diff --git a/daemon/cluster/convert/task.go b/daemon/cluster/convert/task.go index c9d62bd9ef..4efadaf670 100644 --- a/daemon/cluster/convert/task.go +++ b/daemon/cluster/convert/task.go @@ -21,14 +21,11 @@ func TaskFromGRPC(t swarmapi.Task) types.Task { } task := types.Task{ - ID: t.ID, - Annotations: types.Annotations{ - Name: t.Annotations.Name, - Labels: t.Annotations.Labels, - }, - ServiceID: t.ServiceID, - Slot: int(t.Slot), - NodeID: t.NodeID, + ID: t.ID, + Annotations: annotationsFromGRPC(t.Annotations), + ServiceID: t.ServiceID, + Slot: int(t.Slot), + NodeID: t.NodeID, Spec: types.TaskSpec{ ContainerSpec: containerSpecFromGRPC(containerConfig), Resources: resourcesFromGRPC(t.Spec.Resources),