This fix tries to address the issue related to 24108 and 24790, and also the case from 24620#issuecomment-233715656 The reason for the failure case in the above mentioned issues is that currently Task names are actually indexed by Service Name (`e.ServiceAnnotations.Name`) To fix it, a pull request in swarmkit (swarmkit/pull/1193) has been opened separately. This fix adds the integration tests for the above mentioned issues. Swarmkit revendoring is needed to completely fix the issues. This fix fixes 24108. This fix fixes 24790. This fix is related to 24620. Signed-off-by: Yong Tang <yong.tang.github@outlook.com> Upstream-commit: f676fc93c3791f72938a6be9c7517ac620c02d1c Component: engine
68 lines
2.0 KiB
Go
68 lines
2.0 KiB
Go
package convert
|
|
|
|
import (
|
|
"strings"
|
|
|
|
types "github.com/docker/docker/api/types/swarm"
|
|
swarmapi "github.com/docker/swarmkit/api"
|
|
"github.com/docker/swarmkit/protobuf/ptypes"
|
|
)
|
|
|
|
// TaskFromGRPC converts a grpc Task to a Task.
|
|
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,
|
|
Annotations: types.Annotations{
|
|
Name: t.Annotations.Name,
|
|
Labels: t.Annotations.Labels,
|
|
},
|
|
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,
|
|
},
|
|
Status: types.TaskStatus{
|
|
State: types.TaskState(strings.ToLower(t.Status.State.String())),
|
|
Message: t.Status.Message,
|
|
Err: t.Status.Err,
|
|
},
|
|
DesiredState: types.TaskState(strings.ToLower(t.DesiredState.String())),
|
|
}
|
|
|
|
// Meta
|
|
task.Version.Index = t.Meta.Version.Index
|
|
task.CreatedAt, _ = ptypes.Timestamp(t.Meta.CreatedAt)
|
|
task.UpdatedAt, _ = ptypes.Timestamp(t.Meta.UpdatedAt)
|
|
|
|
task.Status.Timestamp, _ = ptypes.Timestamp(t.Status.Timestamp)
|
|
|
|
if containerStatus != nil {
|
|
task.Status.ContainerStatus.ContainerID = containerStatus.ContainerID
|
|
task.Status.ContainerStatus.PID = int(containerStatus.PID)
|
|
task.Status.ContainerStatus.ExitCode = int(containerStatus.ExitCode)
|
|
}
|
|
|
|
// NetworksAttachments
|
|
for _, na := range t.Networks {
|
|
task.NetworksAttachments = append(task.NetworksAttachments, networkAttachementFromGRPC(na))
|
|
}
|
|
|
|
return task
|
|
}
|