Merge pull request #31623 from aaronlehmann/dropped-taskspec-field
Fix dropped field in task translation from GRPC to REST
This commit is contained in:
commit
c430aea83c
2 changed files with 20 additions and 30 deletions
|
@ -69,24 +69,9 @@ func serviceSpecFromGRPC(spec *swarmapi.ServiceSpec) *types.ServiceSpec {
|
|||
serviceNetworks = append(serviceNetworks, types.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases})
|
||||
}
|
||||
|
||||
taskNetworks := make([]types.NetworkAttachmentConfig, 0, len(spec.Task.Networks))
|
||||
for _, n := range spec.Task.Networks {
|
||||
taskNetworks = append(taskNetworks, types.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases})
|
||||
}
|
||||
|
||||
containerConfig := spec.Task.Runtime.(*swarmapi.TaskSpec_Container).Container
|
||||
convertedSpec := &types.ServiceSpec{
|
||||
Annotations: annotationsFromGRPC(spec.Annotations),
|
||||
TaskTemplate: types.TaskSpec{
|
||||
ContainerSpec: containerSpecFromGRPC(containerConfig),
|
||||
Resources: resourcesFromGRPC(spec.Task.Resources),
|
||||
RestartPolicy: restartPolicyFromGRPC(spec.Task.Restart),
|
||||
Placement: placementFromGRPC(spec.Task.Placement),
|
||||
LogDriver: driverFromGRPC(spec.Task.LogDriver),
|
||||
Networks: taskNetworks,
|
||||
ForceUpdate: spec.Task.ForceUpdate,
|
||||
},
|
||||
|
||||
Annotations: annotationsFromGRPC(spec.Annotations),
|
||||
TaskTemplate: taskSpecFromGRPC(spec.Task),
|
||||
Networks: serviceNetworks,
|
||||
EndpointSpec: endpointSpecFromGRPC(spec.Endpoint),
|
||||
}
|
||||
|
@ -438,3 +423,20 @@ func updateConfigToGRPC(updateConfig *types.UpdateConfig) (*swarmapi.UpdateConfi
|
|||
|
||||
return converted, nil
|
||||
}
|
||||
|
||||
func taskSpecFromGRPC(taskSpec swarmapi.TaskSpec) types.TaskSpec {
|
||||
taskNetworks := make([]types.NetworkAttachmentConfig, 0, len(taskSpec.Networks))
|
||||
for _, n := range taskSpec.Networks {
|
||||
taskNetworks = append(taskNetworks, types.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases})
|
||||
}
|
||||
|
||||
return types.TaskSpec{
|
||||
ContainerSpec: containerSpecFromGRPC(taskSpec.GetContainer()),
|
||||
Resources: resourcesFromGRPC(taskSpec.Resources),
|
||||
RestartPolicy: restartPolicyFromGRPC(taskSpec.Restart),
|
||||
Placement: placementFromGRPC(taskSpec.Placement),
|
||||
LogDriver: driverFromGRPC(taskSpec.LogDriver),
|
||||
Networks: taskNetworks,
|
||||
ForceUpdate: taskSpec.ForceUpdate,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,12 +13,7 @@ func TaskFromGRPC(t swarmapi.Task) types.Task {
|
|||
if t.Spec.GetAttachment() != nil {
|
||||
return types.Task{}
|
||||
}
|
||||
containerConfig := t.Spec.Runtime.(*swarmapi.TaskSpec_Container).Container
|
||||
containerStatus := t.Status.GetContainer()
|
||||
networks := make([]types.NetworkAttachmentConfig, 0, len(t.Spec.Networks))
|
||||
for _, n := range t.Spec.Networks {
|
||||
networks = append(networks, types.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases})
|
||||
}
|
||||
|
||||
task := types.Task{
|
||||
ID: t.ID,
|
||||
|
@ -26,14 +21,7 @@ func TaskFromGRPC(t swarmapi.Task) types.Task {
|
|||
ServiceID: t.ServiceID,
|
||||
Slot: int(t.Slot),
|
||||
NodeID: t.NodeID,
|
||||
Spec: types.TaskSpec{
|
||||
ContainerSpec: containerSpecFromGRPC(containerConfig),
|
||||
Resources: resourcesFromGRPC(t.Spec.Resources),
|
||||
RestartPolicy: restartPolicyFromGRPC(t.Spec.Restart),
|
||||
Placement: placementFromGRPC(t.Spec.Placement),
|
||||
LogDriver: driverFromGRPC(t.Spec.LogDriver),
|
||||
Networks: networks,
|
||||
},
|
||||
Spec: taskSpecFromGRPC(t.Spec),
|
||||
Status: types.TaskStatus{
|
||||
State: types.TaskState(strings.ToLower(t.Status.State.String())),
|
||||
Message: t.Status.Message,
|
||||
|
|
Loading…
Reference in a new issue