From 8989bd0e8e46a70c00640f8b0fd9b6d8b1ffc689 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Thu, 25 Apr 2019 13:42:34 +0200 Subject: [PATCH] runservice: pass arch to driver k8s driver: use the provided arch and set the related nodeselector label (`kubernetes.io/arch`) when not empty. --- internal/services/runservice/executor/driver/driver.go | 1 + internal/services/runservice/executor/driver/k8s.go | 6 ++++++ internal/services/runservice/executor/executor.go | 1 + internal/services/runservice/scheduler/scheduler.go | 1 + internal/services/runservice/types/types.go | 1 + 5 files changed, 10 insertions(+) diff --git a/internal/services/runservice/executor/driver/driver.go b/internal/services/runservice/executor/driver/driver.go index a2b5bc5..3d1fe60 100644 --- a/internal/services/runservice/executor/driver/driver.go +++ b/internal/services/runservice/executor/driver/driver.go @@ -75,6 +75,7 @@ type PodConfig struct { ID string TaskID string Containers []*ContainerConfig + Arch common.Arch // The container dir where the init volume will be mounted InitVolumeDir string DockerConfig *registry.DockerConfig diff --git a/internal/services/runservice/executor/driver/k8s.go b/internal/services/runservice/executor/driver/k8s.go index 007ffac..14e2449 100644 --- a/internal/services/runservice/executor/driver/k8s.go +++ b/internal/services/runservice/executor/driver/k8s.go @@ -362,6 +362,12 @@ func (d *K8sDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.Wri }, } + if podConfig.Arch != "" { + pod.Spec.NodeSelector = map[string]string{ + corev1.LabelArchStable: string(podConfig.Arch), + } + } + pod, err = podClient.Create(pod) if err != nil { return nil, err diff --git a/internal/services/runservice/executor/executor.go b/internal/services/runservice/executor/executor.go index 2a93619..b9077ff 100644 --- a/internal/services/runservice/executor/executor.go +++ b/internal/services/runservice/executor/executor.go @@ -835,6 +835,7 @@ func (e *Executor) setupTask(ctx context.Context, rt *runningTask) error { // tasks failed to start and don't clash with existing pods) ID: uuid.NewV4().String(), TaskID: et.ID, + Arch: et.Arch, InitVolumeDir: toolboxContainerDir, DockerConfig: dockerConfig, Containers: []*driver.ContainerConfig{ diff --git a/internal/services/runservice/scheduler/scheduler.go b/internal/services/runservice/scheduler/scheduler.go index 09d7489..f72a61e 100644 --- a/internal/services/runservice/scheduler/scheduler.go +++ b/internal/services/runservice/scheduler/scheduler.go @@ -329,6 +329,7 @@ func (s *Scheduler) genExecutorTask(ctx context.Context, r *types.Run, rt *types ID: rt.ID, RunID: r.ID, TaskName: rct.Name, + Arch: rct.Runtime.Arch, Containers: rct.Runtime.Containers, Environment: environment, WorkingDir: rct.WorkingDir, diff --git a/internal/services/runservice/types/types.go b/internal/services/runservice/types/types.go index 56d5377..b491285 100644 --- a/internal/services/runservice/types/types.go +++ b/internal/services/runservice/types/types.go @@ -502,6 +502,7 @@ type ExecutorTask struct { ID string `json:"id,omitempty"` RunID string `json:"run_id,omitempty"` TaskName string `json:"task_name,omitempty"` + Arch common.Arch `json:"arch,omitempty"` Containers []*Container `json:"containers,omitempty"` Environment map[string]string `json:"environment,omitempty"` WorkingDir string `json:"working_dir,omitempty"`