Skip to content

Commit

Permalink
mbc: don't overwrite env of CronJob
Browse files Browse the repository at this point in the history
Signed-off-by: Ryotaro Banno <[email protected]>
  • Loading branch information
ushitora-anqou committed Jan 20, 2025
1 parent c7ae441 commit 273b96f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions internal/controller/mantlebackupconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down

0 comments on commit 273b96f

Please sign in to comment.