@@ -264,10 +264,8 @@ func CreateSidecarContainer(r *api.Restic, tag string, workload api.LocalTypedRe
264264 })
265265 }
266266 if r .Spec .Backend .Local != nil {
267- sidecar .VolumeMounts = append (sidecar .VolumeMounts , core.VolumeMount {
268- Name : LocalVolumeName ,
269- MountPath : r .Spec .Backend .Local .Path ,
270- })
267+ _ , mnt := r .Spec .Backend .Local .ToVolumeAndMount (LocalVolumeName )
268+ sidecar .VolumeMounts = append (sidecar .VolumeMounts , mnt )
271269 }
272270 return sidecar
273271}
@@ -311,10 +309,11 @@ func MergeLocalVolume(volumes []core.Volume, old, new *api.Restic) []core.Volume
311309 }
312310 }
313311 if new .Spec .Backend .Local != nil {
312+ vol , _ := new .Spec .Backend .Local .ToVolumeAndMount (LocalVolumeName )
314313 if oldPos != - 1 {
315- volumes [oldPos ] = core. Volume { Name : LocalVolumeName , VolumeSource : new . Spec . Backend . Local . VolumeSource }
314+ volumes [oldPos ] = vol
316315 } else {
317- volumes = core_util .UpsertVolume (volumes , core. Volume { Name : LocalVolumeName , VolumeSource : new . Spec . Backend . Local . VolumeSource } )
316+ volumes = core_util .UpsertVolume (volumes , vol )
318317 }
319318 } else {
320319 if oldPos != - 1 {
@@ -359,15 +358,9 @@ func CreateRecoveryJob(recovery *api.Recovery, tag string) *batch.Job {
359358 volumes := make ([]core.Volume , 0 )
360359 volumeMounts := make ([]core.VolumeMount , 0 )
361360 for i , recVol := range recovery .Spec .RecoveredVolumes {
362- volumes = append (volumes , core.Volume {
363- Name : fmt .Sprintf ("vol-%d" , i ),
364- VolumeSource : recVol .VolumeSource ,
365- })
366- volumeMounts = append (volumeMounts , core.VolumeMount {
367- Name : fmt .Sprintf ("vol-%d" , i ),
368- MountPath : recVol .MountPath ,
369- SubPath : recVol .SubPath ,
370- })
361+ vol , mnt := recVol .ToVolumeAndMount (fmt .Sprintf ("vol-%d" , i ))
362+ volumes = append (volumes , vol )
363+ volumeMounts = append (volumeMounts , mnt )
371364 }
372365
373366 job := & batch.Job {
@@ -421,18 +414,10 @@ func CreateRecoveryJob(recovery *api.Recovery, tag string) *batch.Job {
421414
422415 // local backend
423416 if recovery .Spec .Backend .Local != nil {
424- job .Spec .Template .Spec .Containers [0 ].VolumeMounts = append (job .Spec .Template .Spec .Containers [0 ].VolumeMounts ,
425- core.VolumeMount {
426- Name : LocalVolumeName ,
427- MountPath : recovery .Spec .Backend .Local .Path ,
428- })
429-
430- // user don't need to specify "stash-local" volume, we collect it from restic-spec
431- job .Spec .Template .Spec .Volumes = append (job .Spec .Template .Spec .Volumes ,
432- core.Volume {
433- Name : LocalVolumeName ,
434- VolumeSource : recovery .Spec .Backend .Local .VolumeSource ,
435- })
417+ vol , mnt := recovery .Spec .Backend .Local .ToVolumeAndMount (LocalVolumeName )
418+ job .Spec .Template .Spec .Containers [0 ].VolumeMounts = append (
419+ job .Spec .Template .Spec .Containers [0 ].VolumeMounts , mnt )
420+ job .Spec .Template .Spec .Volumes = append (job .Spec .Template .Spec .Volumes , vol )
436421 }
437422
438423 return job
@@ -557,19 +542,12 @@ func CreateCheckJob(restic *api.Restic, hostName string, smartPrefix string, tag
557542 }
558543
559544 // local backend
545+ // user don't need to specify "stash-local" volume, we collect it from restic-spec
560546 if restic .Spec .Backend .Local != nil {
561- job .Spec .Template .Spec .Containers [0 ].VolumeMounts = append (job .Spec .Template .Spec .Containers [0 ].VolumeMounts ,
562- core.VolumeMount {
563- Name : LocalVolumeName ,
564- MountPath : restic .Spec .Backend .Local .Path ,
565- })
566-
567- // user don't need to specify "stash-local" volume, we collect it from restic-spec
568- job .Spec .Template .Spec .Volumes = append (job .Spec .Template .Spec .Volumes ,
569- core.Volume {
570- Name : LocalVolumeName ,
571- VolumeSource : restic .Spec .Backend .Local .VolumeSource ,
572- })
547+ vol , mnt := restic .Spec .Backend .Local .ToVolumeAndMount (LocalVolumeName )
548+ job .Spec .Template .Spec .Containers [0 ].VolumeMounts = append (
549+ job .Spec .Template .Spec .Containers [0 ].VolumeMounts , mnt )
550+ job .Spec .Template .Spec .Volumes = append (job .Spec .Template .Spec .Volumes , vol )
573551 }
574552
575553 return job
0 commit comments