diff --git a/internal/controller/mantlebackupconfig_controller.go b/internal/controller/mantlebackupconfig_controller.go index 8150cc27..db13f966 100644 --- a/internal/controller/mantlebackupconfig_controller.go +++ b/internal/controller/mantlebackupconfig_controller.go @@ -234,15 +234,19 @@ func (r *MantleBackupConfigReconciler) createOrUpdateCronJob(ctx context.Context "--namespace", mbc.GetNamespace(), } container.ImagePullPolicy = corev1.PullIfNotPresent - container.Env = []corev1.EnvVar{ - { - Name: "JOB_NAME", ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "metadata.labels['batch.kubernetes.io/job-name']", - }, - }, - }, + + if len(container.Env) == 0 { + container.Env = append(container.Env, corev1.EnvVar{}) + } + env := &container.Env[0] + env.Name = "JOB_NAME" + if env.ValueFrom == nil { + env.ValueFrom = &corev1.EnvVarSource{} + } + if env.ValueFrom.FieldRef == nil { + env.ValueFrom.FieldRef = &corev1.ObjectFieldSelector{} } + env.ValueFrom.FieldRef.FieldPath = "metadata.labels['batch.kubernetes.io/job-name']" return nil })