From 2416b006d5c1e0d06ff2dea51345ecc6f3b7dc4b Mon Sep 17 00:00:00 2001 From: Christopher Manzi Date: Thu, 26 Sep 2024 11:34:46 -0500 Subject: [PATCH] fix: change k8s job container creation logic to retain existing values from job manifest Fixes GoogleContainerTools/skaffold#9409 --- pkg/skaffold/actions/k8sjob/task.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/skaffold/actions/k8sjob/task.go b/pkg/skaffold/actions/k8sjob/task.go index ea4a03342b4..f2ffca44421 100644 --- a/pkg/skaffold/actions/k8sjob/task.go +++ b/pkg/skaffold/actions/k8sjob/task.go @@ -146,7 +146,26 @@ func (t Task) getK8SEnvVars(envVars []latest.VerifyEnvVar) (k8sEnvVar []corev1.E } func (t *Task) setManifestValues(c corev1.Container) { - t.jobManifest.Spec.Template.Spec.Containers = []corev1.Container{c} + if len(t.jobManifest.Spec.Template.Spec.Containers) == 0 { + t.jobManifest.Spec.Template.Spec.Containers = []corev1.Container{c} + } else { + if c.Name != "" { + t.jobManifest.Spec.Template.Spec.Containers[0].Name = c.Name + } + if c.Image != "" { + t.jobManifest.Spec.Template.Spec.Containers[0].Image = c.Image + } + if len(c.Command) > 0 { + t.jobManifest.Spec.Template.Spec.Containers[0].Command = c.Command + } + if len(c.Args) > 0 { + t.jobManifest.Spec.Template.Spec.Containers[0].Args = c.Args + } + if len(c.Env) > 0 { + t.jobManifest.Spec.Template.Spec.Containers[0].Env = c.Env + } + } + t.jobManifest.ObjectMeta.Name = t.Name() }