skip this if SnapshotMoveData
https://github.com/vmware-tanzu/velero/pull/7046/files#r1380708644 Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>pull/7046/head
parent
9311a4269b
commit
f9e716a8c9
|
@ -16,49 +16,52 @@ import (
|
||||||
|
|
||||||
// Common function to update the status of CSI snapshots
|
// Common function to update the status of CSI snapshots
|
||||||
// returns VolumeSnapshot, VolumeSnapshotContent, VolumeSnapshotClasses referenced
|
// returns VolumeSnapshot, VolumeSnapshotContent, VolumeSnapshotClasses referenced
|
||||||
func UpdateBackupCSISnapshotsStatus(client kbclient.Client, volumeSnapshotLister snapshotv1listers.VolumeSnapshotLister, backup *velerov1api.Backup, backupLog logrus.FieldLogger) ([]snapshotv1api.VolumeSnapshot, []snapshotv1api.VolumeSnapshotContent, []snapshotv1api.VolumeSnapshotClass) {
|
func UpdateBackupCSISnapshotsStatus(client kbclient.Client, volumeSnapshotLister snapshotv1listers.VolumeSnapshotLister, backup *velerov1api.Backup, backupLog logrus.FieldLogger) (volumeSnapshots []snapshotv1api.VolumeSnapshot, volumeSnapshotContents []snapshotv1api.VolumeSnapshotContent, volumeSnapshotClasses []snapshotv1api.VolumeSnapshotClass) {
|
||||||
var volumeSnapshots []snapshotv1api.VolumeSnapshot
|
if boolptr.IsSetToTrue(backup.Spec.SnapshotMoveData) {
|
||||||
var volumeSnapshotContents []snapshotv1api.VolumeSnapshotContent
|
backupLog.Info("backup SnapshotMoveData is set to true, skip VolumeSnapshot resource persistence.")
|
||||||
var volumeSnapshotClasses []snapshotv1api.VolumeSnapshotClass
|
} else {
|
||||||
selector := label.NewSelectorForBackup(backup.Name)
|
selector := label.NewSelectorForBackup(backup.Name)
|
||||||
vscList := &snapshotv1api.VolumeSnapshotContentList{}
|
vscList := &snapshotv1api.VolumeSnapshotContentList{}
|
||||||
|
|
||||||
if volumeSnapshotLister != nil {
|
if volumeSnapshotLister != nil {
|
||||||
tmpVSs, err := volumeSnapshotLister.List(label.NewSelectorForBackup(backup.Name))
|
tmpVSs, err := volumeSnapshotLister.List(label.NewSelectorForBackup(backup.Name))
|
||||||
|
if err != nil {
|
||||||
|
backupLog.Error(err)
|
||||||
|
}
|
||||||
|
for _, vs := range tmpVSs {
|
||||||
|
volumeSnapshots = append(volumeSnapshots, *vs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err := client.List(context.Background(), vscList, &kbclient.ListOptions{LabelSelector: selector})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
backupLog.Error(err)
|
backupLog.Error(err)
|
||||||
}
|
}
|
||||||
for _, vs := range tmpVSs {
|
if len(vscList.Items) >= 0 {
|
||||||
volumeSnapshots = append(volumeSnapshots, *vs)
|
volumeSnapshotContents = vscList.Items
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
vsClassSet := sets.NewString()
|
||||||
err := client.List(context.Background(), vscList, &kbclient.ListOptions{LabelSelector: selector})
|
for index := range volumeSnapshotContents {
|
||||||
if err != nil {
|
// persist the volumesnapshotclasses referenced by vsc
|
||||||
backupLog.Error(err)
|
if volumeSnapshotContents[index].Spec.VolumeSnapshotClassName != nil && !vsClassSet.Has(*volumeSnapshotContents[index].Spec.VolumeSnapshotClassName) {
|
||||||
}
|
vsClass := &snapshotv1api.VolumeSnapshotClass{}
|
||||||
if len(vscList.Items) >= 0 {
|
if err := client.Get(context.TODO(), kbclient.ObjectKey{Name: *volumeSnapshotContents[index].Spec.VolumeSnapshotClassName}, vsClass); err != nil {
|
||||||
volumeSnapshotContents = vscList.Items
|
backupLog.Error(err)
|
||||||
}
|
} else {
|
||||||
|
vsClassSet.Insert(*volumeSnapshotContents[index].Spec.VolumeSnapshotClassName)
|
||||||
vsClassSet := sets.NewString()
|
volumeSnapshotClasses = append(volumeSnapshotClasses, *vsClass)
|
||||||
for index := range volumeSnapshotContents {
|
}
|
||||||
// persist the volumesnapshotclasses referenced by vsc
|
|
||||||
if volumeSnapshotContents[index].Spec.VolumeSnapshotClassName != nil && !vsClassSet.Has(*volumeSnapshotContents[index].Spec.VolumeSnapshotClassName) {
|
|
||||||
vsClass := &snapshotv1api.VolumeSnapshotClass{}
|
|
||||||
if err := client.Get(context.TODO(), kbclient.ObjectKey{Name: *volumeSnapshotContents[index].Spec.VolumeSnapshotClassName}, vsClass); err != nil {
|
|
||||||
backupLog.Error(err)
|
|
||||||
} else {
|
|
||||||
vsClassSet.Insert(*volumeSnapshotContents[index].Spec.VolumeSnapshotClassName)
|
|
||||||
volumeSnapshotClasses = append(volumeSnapshotClasses, *vsClass)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
backup.Status.CSIVolumeSnapshotsAttempted = len(volumeSnapshots)
|
||||||
backup.Status.CSIVolumeSnapshotsAttempted = len(volumeSnapshots)
|
csiVolumeSnapshotsCompleted := 0
|
||||||
for _, vs := range volumeSnapshots {
|
for _, vs := range volumeSnapshots {
|
||||||
if vs.Status != nil && boolptr.IsSetToTrue(vs.Status.ReadyToUse) {
|
if vs.Status != nil && boolptr.IsSetToTrue(vs.Status.ReadyToUse) {
|
||||||
backup.Status.CSIVolumeSnapshotsCompleted++
|
csiVolumeSnapshotsCompleted++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
backup.Status.CSIVolumeSnapshotsCompleted = csiVolumeSnapshotsCompleted
|
||||||
}
|
}
|
||||||
return volumeSnapshots, volumeSnapshotContents, volumeSnapshotClasses
|
return volumeSnapshots, volumeSnapshotContents, volumeSnapshotClasses
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue