Skip to content

Commit

Permalink
Merge pull request moby#30967 from adshmh/24631-service-without-label…
Browse files Browse the repository at this point in the history
…s-returns-empty-map

Inspect output on service without labels is an empty map instead of null, fixes moby#24631
  • Loading branch information
LK4D4 authored Feb 17, 2017
2 parents f00514a + 1b347cf commit 0de867b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion api/types/swarm/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
3 changes: 1 addition & 2 deletions daemon/cluster/convert/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions daemon/cluster/convert/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions daemon/cluster/convert/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down
19 changes: 14 additions & 5 deletions daemon/cluster/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions daemon/cluster/convert/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 5 additions & 8 deletions daemon/cluster/convert/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 0de867b

Please sign in to comment.