From 41ac2992cb2e607028e2eaedfa2e0a8b91dee6bd Mon Sep 17 00:00:00 2001 From: Chris Hill Date: Fri, 3 May 2019 12:32:35 -0600 Subject: [PATCH 1/2] Fix orphaned /tmp/drone directories in kubernetes --- scheduler/kube/kube.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scheduler/kube/kube.go b/scheduler/kube/kube.go index 74ef68ca..4da0a712 100644 --- a/scheduler/kube/kube.go +++ b/scheduler/kube/kube.go @@ -10,6 +10,7 @@ import ( "context" "errors" "fmt" + "path/filepath" "strings" "time" @@ -104,6 +105,24 @@ func (s *kubeScheduler) Schedule(ctx context.Context, stage *core.Stage) error { rand := strings.ToLower(uniuri.NewLen(12)) name := fmt.Sprintf("drone-job-%d-%s", stage.ID, rand) + var mounts []v1.VolumeMount + mount := v1.VolumeMount{ + Name: "local", + MountPath: filepath.Join("/tmp", "drone"), + } + mounts = append(mounts, mount) + + var volumes []v1.Volume + source := v1.HostPathDirectoryOrCreate + volume := v1.Volume{ + Name: "local", + } + volume.HostPath = &v1.HostPathVolumeSource{ + Path: filepath.Join("/tmp", "drone"), + Type: &source, + } + volumes = append(volumes, volume) + job := &batchv1.Job{ ObjectMeta: metav1.ObjectMeta{ GenerateName: name, @@ -131,7 +150,9 @@ func (s *kubeScheduler) Schedule(ctx context.Context, stage *core.Stage) error { Image: internal.DefaultImage(s.config.Image), ImagePullPolicy: pull, Env: env, + VolumeMounts: mounts, }}, + Volumes: volumes, }, }, }, From fbdf837f8cc298fb90d4422ef549870ed5f0ea43 Mon Sep 17 00:00:00 2001 From: Chris Hill Date: Thu, 16 May 2019 13:37:59 -0600 Subject: [PATCH 2/2] Update the local volume name to be unique and more descriptive --- scheduler/kube/kube.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/scheduler/kube/kube.go b/scheduler/kube/kube.go index 4da0a712..e6fad4ee 100644 --- a/scheduler/kube/kube.go +++ b/scheduler/kube/kube.go @@ -10,7 +10,7 @@ import ( "context" "errors" "fmt" - "path/filepath" + "path/filepath" "strings" "time" @@ -106,22 +106,24 @@ func (s *kubeScheduler) Schedule(ctx context.Context, stage *core.Stage) error { name := fmt.Sprintf("drone-job-%d-%s", stage.ID, rand) var mounts []v1.VolumeMount - mount := v1.VolumeMount{ - Name: "local", + mount := v1.VolumeMount{ + Name: name + "-local", MountPath: filepath.Join("/tmp", "drone"), } - mounts = append(mounts, mount) + mounts = append(mounts, mount) var volumes []v1.Volume - source := v1.HostPathDirectoryOrCreate - volume := v1.Volume{ - Name: "local", + source := v1.HostPathDirectoryOrCreate + volume := v1.Volume{ + Name: name + "-local", + VolumeSource: v1.VolumeSource{ + HostPath: &v1.HostPathVolumeSource{ + Path: filepath.Join("/tmp", "drone"), + Type: &source, + }, + }, } - volume.HostPath = &v1.HostPathVolumeSource{ - Path: filepath.Join("/tmp", "drone"), - Type: &source, - } - volumes = append(volumes, volume) + volumes = append(volumes, volume) job := &batchv1.Job{ ObjectMeta: metav1.ObjectMeta{