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:
commit
0de867b315
7 changed files with 25 additions and 25 deletions
|
@ -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).
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue