فهرست منبع

Fixing #24631, inspect output on swarm object types without labels is empty object {}

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
Arash Deshmeh 8 سال پیش
والد
کامیت
1b347cfc79

+ 1 - 1
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).

+ 1 - 2
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 {

+ 1 - 2
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 {

+ 2 - 5
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,
 		},
 	}
 

+ 14 - 5
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 {

+ 1 - 2
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
 }

+ 5 - 8
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),