Skip to content

Commit

Permalink
only include pvc in volume mounts at stage restore of a pod
Browse files Browse the repository at this point in the history
  • Loading branch information
JaydipGabani committed Aug 5, 2021
1 parent 876132e commit 9aba4e9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions velero-plugins/common/types.go
Expand Up @@ -49,6 +49,8 @@ const (
// Designated as a `final` Restore.
// The value is the Task.UID().
FinalRestoreLabel = "migration-final-restore"
// Exclude PVCs if marked "move" or "snapshot" in the plan
ExcludePVCPodLabel = "migration.openshift.io/exclude-pvcs"
)

// PV selection annotations
Expand Down
34 changes: 34 additions & 0 deletions velero-plugins/pod/restore.go
Expand Up @@ -113,9 +113,43 @@ func (p *RestorePlugin) Execute(input *velero.RestoreItemActionExecuteInput) (*v
destStagePodImage := input.Restore.Annotations[common.StagePodImageAnnotation]
if len(pod.Labels[common.IncludedInStageBackupLabel]) > 0 && len(destStagePodImage) > 0 {
p.Log.Infof("[pod-restore] swapping stage pod images for pod %s", pod.Name)
pvcVolumes := []corev1API.Volume{}
exclude := []string{}
for _, volume := range pod.Spec.Volumes {
if volume.PersistentVolumeClaim == nil {
exclude = append(exclude, volume.Name)
continue
}
if len(pod.Labels[common.ExcludePVCPodLabel]) > 0 {
if strings.Contains(pod.Labels[common.ExcludePVCPodLabel], volume.Name) {
exclude = append(exclude, volume.Name)
continue
}
}
pvcVolumes = append(pvcVolumes, volume)
}
pod.Spec.Volumes = pvcVolumes
inVolumes := func(mount corev1API.VolumeMount) bool {
for _, volume := range pvcVolumes {
if volume.Name == mount.Name {
return true
}
}
return false
}

for n, container := range pod.Spec.Containers {
p.Log.Infof("[pod-restore] swapping stage pod image from %s to %s", container.Image, destStagePodImage)
pod.Spec.Containers[n].Image = destStagePodImage
pod.Spec.Containers[n].Command = []string{"sleep"}
pod.Spec.Containers[n].Args = []string{"infinity"}
volumeMount := []corev1API.VolumeMount{}
for _, vol := range container.VolumeMounts {
if inVolumes(vol) {
volumeMount = append(volumeMount, vol)
}
}
pod.Spec.Containers[n].VolumeMounts = volumeMount
}
}
var out map[string]interface{}
Expand Down

0 comments on commit 9aba4e9

Please sign in to comment.