From 7ebc436854bcc12fc9badb93ddd5629bc0fc9c7c Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Mon, 22 Apr 2019 17:53:34 +0200 Subject: [PATCH] runservice executor: generate pod id outside driver --- internal/services/runservice/executor/driver/docker.go | 7 ++----- internal/services/runservice/executor/driver/driver.go | 1 + internal/services/runservice/executor/executor.go | 4 ++++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/services/runservice/executor/driver/docker.go b/internal/services/runservice/executor/driver/docker.go index 7650cef..0ea0fb4 100644 --- a/internal/services/runservice/executor/driver/docker.go +++ b/internal/services/runservice/executor/driver/docker.go @@ -35,7 +35,6 @@ import ( "github.com/docker/docker/client" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/stdcopy" - uuid "github.com/satori/go.uuid" "go.uber.org/zap" ) @@ -143,15 +142,13 @@ func (d *DockerDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io. } io.Copy(out, reader) - podID := uuid.NewV4().String() - labels := map[string]string{} // prepend the podLabelPrefix to the labels' keys for k, v := range podConfig.Labels { labels[podLabelPrefix+k] = v } labels[agolaLabelKey] = agolaLabelValue - labels[podIDKey] = podID + labels[podIDKey] = podConfig.ID containerLabels := map[string]string{} for k, v := range labels { @@ -198,7 +195,7 @@ func (d *DockerDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io. } return &DockerPod{ - id: podID, + id: podConfig.ID, client: d.client, containers: containers, }, nil diff --git a/internal/services/runservice/executor/driver/driver.go b/internal/services/runservice/executor/driver/driver.go index c43c771..5add210 100644 --- a/internal/services/runservice/executor/driver/driver.go +++ b/internal/services/runservice/executor/driver/driver.go @@ -64,6 +64,7 @@ type ContainerExec interface { } type PodConfig struct { + ID string Containers []*ContainerConfig Labels map[string]string // The container dir where the init volume will be mounted diff --git a/internal/services/runservice/executor/executor.go b/internal/services/runservice/executor/executor.go index d058354..f3f4d22 100644 --- a/internal/services/runservice/executor/executor.go +++ b/internal/services/runservice/executor/executor.go @@ -742,6 +742,7 @@ func (e *Executor) executeTask(ctx context.Context, et *types.ExecutorTask) { } if err := e.setupTask(ctx, rt); err != nil { + log.Errorf("err: %+v", err) rt.et.Status.Phase = types.ExecutorTaskPhaseFailed et.Status.SetupStep.EndTime = util.TimePtr(time.Now()) et.Status.SetupStep.Phase = types.ExecutorTaskPhaseFailed @@ -802,6 +803,9 @@ func (e *Executor) setupTask(ctx context.Context, rt *runningTask) error { } 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), InitVolumeDir: toolboxContainerDir, DockerConfig: dockerConfig,