runservice executor: generate pod id outside driver

This commit is contained in:
Simone Gotti 2019-04-22 17:53:34 +02:00
parent 17f3dc89f2
commit 7ebc436854
3 changed files with 7 additions and 5 deletions

View File

@ -35,7 +35,6 @@ import (
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/stdcopy"
uuid "github.com/satori/go.uuid"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -143,15 +142,13 @@ func (d *DockerDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.
} }
io.Copy(out, reader) io.Copy(out, reader)
podID := uuid.NewV4().String()
labels := map[string]string{} labels := map[string]string{}
// prepend the podLabelPrefix to the labels' keys // prepend the podLabelPrefix to the labels' keys
for k, v := range podConfig.Labels { for k, v := range podConfig.Labels {
labels[podLabelPrefix+k] = v labels[podLabelPrefix+k] = v
} }
labels[agolaLabelKey] = agolaLabelValue labels[agolaLabelKey] = agolaLabelValue
labels[podIDKey] = podID labels[podIDKey] = podConfig.ID
containerLabels := map[string]string{} containerLabels := map[string]string{}
for k, v := range labels { for k, v := range labels {
@ -198,7 +195,7 @@ func (d *DockerDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.
} }
return &DockerPod{ return &DockerPod{
id: podID, id: podConfig.ID,
client: d.client, client: d.client,
containers: containers, containers: containers,
}, nil }, nil

View File

@ -64,6 +64,7 @@ type ContainerExec interface {
} }
type PodConfig struct { type PodConfig struct {
ID string
Containers []*ContainerConfig Containers []*ContainerConfig
Labels map[string]string Labels map[string]string
// The container dir where the init volume will be mounted // The container dir where the init volume will be mounted

View File

@ -742,6 +742,7 @@ func (e *Executor) executeTask(ctx context.Context, et *types.ExecutorTask) {
} }
if err := e.setupTask(ctx, rt); err != nil { if err := e.setupTask(ctx, rt); err != nil {
log.Errorf("err: %+v", err)
rt.et.Status.Phase = types.ExecutorTaskPhaseFailed rt.et.Status.Phase = types.ExecutorTaskPhaseFailed
et.Status.SetupStep.EndTime = util.TimePtr(time.Now()) et.Status.SetupStep.EndTime = util.TimePtr(time.Now())
et.Status.SetupStep.Phase = types.ExecutorTaskPhaseFailed et.Status.SetupStep.Phase = types.ExecutorTaskPhaseFailed
@ -802,6 +803,9 @@ func (e *Executor) setupTask(ctx context.Context, rt *runningTask) error {
} }
podConfig := &driver.PodConfig{ podConfig := &driver.PodConfig{
// generate a random pod id (don't use task id for future ability to restart
// tasks failed to start and don't clash with existing pods)
ID: uuid.NewV4().String(),
Labels: createTaskLabels(et.ID), Labels: createTaskLabels(et.ID),
InitVolumeDir: toolboxContainerDir, InitVolumeDir: toolboxContainerDir,
DockerConfig: dockerConfig, DockerConfig: dockerConfig,