1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #30967 from adshmh/24631-service-without-labels-returns-empty-map

Inspect output on service without labels is an empty map instead of null, fixes #24631
This commit is contained in:
Alexander Morozov 2017-02-17 08:49:32 -08:00 committed by GitHub
commit 0de867b315
7 changed files with 25 additions and 25 deletions

View file

@ -17,7 +17,7 @@ type Meta struct {
// Annotations represents how to describe an object. // Annotations represents how to describe an object.
type Annotations struct { type Annotations struct {
Name string `json:",omitempty"` Name string `json:",omitempty"`
Labels map[string]string `json:",omitempty"` Labels map[string]string `json:"Labels"`
} }
// Driver represents a driver (network, logging). // Driver represents a driver (network, logging).

View file

@ -39,8 +39,7 @@ func networkFromGRPC(n *swarmapi.Network) types.Network {
network.UpdatedAt, _ = gogotypes.TimestampFromProto(n.Meta.UpdatedAt) network.UpdatedAt, _ = gogotypes.TimestampFromProto(n.Meta.UpdatedAt)
//Annotations //Annotations
network.Spec.Name = n.Spec.Annotations.Name network.Spec.Annotations = annotationsFromGRPC(n.Spec.Annotations)
network.Spec.Labels = n.Spec.Annotations.Labels
//DriverConfiguration //DriverConfiguration
if n.Spec.DriverConfig != nil { if n.Spec.DriverConfig != nil {

View file

@ -30,8 +30,7 @@ func NodeFromGRPC(n swarmapi.Node) types.Node {
node.UpdatedAt, _ = gogotypes.TimestampFromProto(n.Meta.UpdatedAt) node.UpdatedAt, _ = gogotypes.TimestampFromProto(n.Meta.UpdatedAt)
//Annotations //Annotations
node.Spec.Name = n.Spec.Annotations.Name node.Spec.Annotations = annotationsFromGRPC(n.Spec.Annotations)
node.Spec.Labels = n.Spec.Annotations.Labels
//Description //Description
if n.Description != nil { if n.Description != nil {

View file

@ -11,11 +11,8 @@ func SecretFromGRPC(s *swarmapi.Secret) swarmtypes.Secret {
secret := swarmtypes.Secret{ secret := swarmtypes.Secret{
ID: s.ID, ID: s.ID,
Spec: swarmtypes.SecretSpec{ Spec: swarmtypes.SecretSpec{
Annotations: swarmtypes.Annotations{ Annotations: annotationsFromGRPC(s.Spec.Annotations),
Name: s.Spec.Annotations.Name, Data: s.Spec.Data,
Labels: s.Spec.Annotations.Labels,
},
Data: s.Spec.Data,
}, },
} }

View file

@ -70,11 +70,7 @@ func serviceSpecFromGRPC(spec *swarmapi.ServiceSpec) *types.ServiceSpec {
containerConfig := spec.Task.Runtime.(*swarmapi.TaskSpec_Container).Container containerConfig := spec.Task.Runtime.(*swarmapi.TaskSpec_Container).Container
convertedSpec := &types.ServiceSpec{ convertedSpec := &types.ServiceSpec{
Annotations: types.Annotations{ Annotations: annotationsFromGRPC(spec.Annotations),
Name: spec.Annotations.Name,
Labels: spec.Annotations.Labels,
},
TaskTemplate: types.TaskSpec{ TaskTemplate: types.TaskSpec{
ContainerSpec: containerSpecFromGRPC(containerConfig), ContainerSpec: containerSpecFromGRPC(containerConfig),
Resources: resourcesFromGRPC(spec.Task.Resources), Resources: resourcesFromGRPC(spec.Task.Resources),
@ -236,6 +232,19 @@ func ServiceSpecToGRPC(s types.ServiceSpec) (swarmapi.ServiceSpec, error) {
return spec, nil 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 { func resourcesFromGRPC(res *swarmapi.ResourceRequirements) *types.ResourceRequirements {
var resources *types.ResourceRequirements var resources *types.ResourceRequirements
if res != nil { if res != nil {

View file

@ -56,8 +56,7 @@ func SwarmFromGRPC(c swarmapi.Cluster) types.Swarm {
swarm.UpdatedAt, _ = gogotypes.TimestampFromProto(c.Meta.UpdatedAt) swarm.UpdatedAt, _ = gogotypes.TimestampFromProto(c.Meta.UpdatedAt)
// Annotations // Annotations
swarm.Spec.Name = c.Spec.Annotations.Name swarm.Spec.Annotations = annotationsFromGRPC(c.Spec.Annotations)
swarm.Spec.Labels = c.Spec.Annotations.Labels
return swarm return swarm
} }

View file

@ -21,14 +21,11 @@ func TaskFromGRPC(t swarmapi.Task) types.Task {
} }
task := types.Task{ task := types.Task{
ID: t.ID, ID: t.ID,
Annotations: types.Annotations{ Annotations: annotationsFromGRPC(t.Annotations),
Name: t.Annotations.Name, ServiceID: t.ServiceID,
Labels: t.Annotations.Labels, Slot: int(t.Slot),
}, NodeID: t.NodeID,
ServiceID: t.ServiceID,
Slot: int(t.Slot),
NodeID: t.NodeID,
Spec: types.TaskSpec{ Spec: types.TaskSpec{
ContainerSpec: containerSpecFromGRPC(containerConfig), ContainerSpec: containerSpecFromGRPC(containerConfig),
Resources: resourcesFromGRPC(t.Spec.Resources), Resources: resourcesFromGRPC(t.Spec.Resources),