Merge pull request #9092 from blackpiglet/8116_fix
Run the E2E test on kind / build (push) Failing after 7m58s
Run the E2E test on kind / setup-test-matrix (push) Successful in 4s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
Main CI / Build (push) Failing after 37s
Close stale issues and PRs / stale (push) Successful in 18s
Trivy Nightly Scan / Trivy nightly scan (velero, main) (push) Failing after 2m1s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-aws, main) (push) Failing after 1m37s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-gcp, main) (push) Failing after 1m57s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-microsoft-azure, main) (push) Failing after 1m50s

Avoid checking the VS and VSC status in the backup finalizing phase.
This commit is contained in:
Xun Jiang/Bruce Jiang
2025-07-24 14:06:02 +08:00
committed by GitHub
5 changed files with 52 additions and 24 deletions
+1
View File
@@ -0,0 +1 @@
Avoid checking the VS and VSC status in the backup finalizing phase.
+10 -14
View File
@@ -95,6 +95,16 @@ func (p *volumeSnapshotBackupItemAction) Execute(
)
}
if backup.Status.Phase == velerov1api.BackupPhaseFinalizing ||
backup.Status.Phase == velerov1api.BackupPhaseFinalizingPartiallyFailed {
p.log.
WithField("Backup", fmt.Sprintf("%s/%s", backup.Namespace, backup.Name)).
WithField("BackupPhase", backup.Status.Phase).Debugf("Cleaning VolumeSnapshots.")
csi.DeleteReadyVolumeSnapshot(*vs, p.crClient, p.log)
return item, nil, "", nil, nil
}
p.log.Infof("Getting VolumesnapshotContent for Volumesnapshot %s/%s",
vs.Namespace, vs.Name)
@@ -109,20 +119,6 @@ func (p *volumeSnapshotBackupItemAction) Execute(
return nil, nil, "", nil, errors.WithStack(err)
}
if backup.Status.Phase == velerov1api.BackupPhaseFinalizing ||
backup.Status.Phase == velerov1api.BackupPhaseFinalizingPartiallyFailed {
p.log.
WithField("Backup", fmt.Sprintf("%s/%s", backup.Namespace, backup.Name)).
WithField("BackupPhase", backup.Status.Phase).Debugf("Cleaning VolumeSnapshots.")
if vsc == nil {
vsc = &snapshotv1api.VolumeSnapshotContent{}
}
csi.DeleteReadyVolumeSnapshot(*vs, *vsc, p.crClient, p.log)
return item, nil, "", nil, nil
}
annotations := make(map[string]string)
if vsc != nil {
@@ -118,6 +118,34 @@ func TestVSExecute(t *testing.T) {
},
},
},
{
name: "Backup in finalizing phase - skip VSC lookup",
backup: builder.ForBackup("velero", "backup").
Phase(velerov1api.BackupPhaseFinalizing).Result(),
vs: builder.ForVolumeSnapshot("velero", "vs").
ObjectMeta(builder.WithLabels(
velerov1api.BackupNameLabel, "backup")).
Status().
BoundVolumeSnapshotContentName("vsc").Result(),
vsc: nil, // VSC won't be created/fetched
expectedErr: "",
expectedAdditionalItems: nil,
expectedItemToUpdate: nil,
},
{
name: "Backup in finalizing partially failed phase - skip VSC lookup",
backup: builder.ForBackup("velero", "backup").
Phase(velerov1api.BackupPhaseFinalizingPartiallyFailed).Result(),
vs: builder.ForVolumeSnapshot("velero", "vs").
ObjectMeta(builder.WithLabels(
velerov1api.BackupNameLabel, "backup")).
Status().
BoundVolumeSnapshotContentName("vsc").Result(),
vsc: nil, // VSC won't be created/fetched
expectedErr: "",
expectedAdditionalItems: nil,
expectedItemToUpdate: nil,
},
}
for _, tc := range tests {
+11 -8
View File
@@ -489,16 +489,16 @@ func SetVolumeSnapshotContentDeletionPolicy(
vscName string,
crClient crclient.Client,
policy snapshotv1api.DeletionPolicy,
) error {
) (*snapshotv1api.VolumeSnapshotContent, error) {
vsc := new(snapshotv1api.VolumeSnapshotContent)
if err := crClient.Get(context.TODO(), crclient.ObjectKey{Name: vscName}, vsc); err != nil {
return err
return nil, err
}
originVSC := vsc.DeepCopy()
vsc.Spec.DeletionPolicy = policy
return crClient.Patch(context.TODO(), vsc, crclient.MergeFrom(originVSC))
return vsc, crClient.Patch(context.TODO(), vsc, crclient.MergeFrom(originVSC))
}
// CleanupVolumeSnapshot deletes the VolumeSnapshot and the associated VolumeSnapshotContent. It will make sure the
@@ -523,7 +523,7 @@ func CleanupVolumeSnapshot(
if vs.Status != nil && vs.Status.BoundVolumeSnapshotContentName != nil {
// we patch the DeletionPolicy of the VolumeSnapshotContent to set it to Delete.
// This ensures that the volume snapshot in the storage provider is also deleted.
err := SetVolumeSnapshotContentDeletionPolicy(
_, err := SetVolumeSnapshotContentDeletionPolicy(
*vs.Status.BoundVolumeSnapshotContentName,
crClient,
snapshotv1api.VolumeSnapshotContentDelete,
@@ -544,7 +544,6 @@ func CleanupVolumeSnapshot(
func DeleteReadyVolumeSnapshot(
vs snapshotv1api.VolumeSnapshot,
vsc snapshotv1api.VolumeSnapshotContent,
client crclient.Client,
logger logrus.FieldLogger,
) {
@@ -557,11 +556,15 @@ func DeleteReadyVolumeSnapshot(
return
}
var vsc *snapshotv1api.VolumeSnapshotContent
if vs.Status != nil && vs.Status.BoundVolumeSnapshotContentName != nil {
var err error
// Patch the DeletionPolicy of the VolumeSnapshotContent to set it to Retain.
// This ensures that the volume snapshot in the storage provider is kept.
if err := SetVolumeSnapshotContentDeletionPolicy(
vsc.Name,
if vsc, err = SetVolumeSnapshotContentDeletionPolicy(
*vs.Status.BoundVolumeSnapshotContentName,
client,
snapshotv1api.VolumeSnapshotContentRetain,
); err != nil {
@@ -570,7 +573,7 @@ func DeleteReadyVolumeSnapshot(
return
}
if err := client.Delete(context.TODO(), &vsc); err != nil {
if err := client.Delete(context.TODO(), vsc); err != nil {
logger.WithError(err).Warnf("Failed to delete the VolumeSnapshotContent %s", vsc.Name)
}
}
+2 -2
View File
@@ -1439,7 +1439,7 @@ func TestSetVolumeSnapshotContentDeletionPolicy(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
fakeClient := velerotest.NewFakeControllerRuntimeClient(t, tc.objs...)
err := SetVolumeSnapshotContentDeletionPolicy(tc.inputVSCName, fakeClient, tc.policy)
_, err := SetVolumeSnapshotContentDeletionPolicy(tc.inputVSCName, fakeClient, tc.policy)
if tc.expectError {
assert.Error(t, err)
} else {
@@ -1496,7 +1496,7 @@ func TestDeleteVolumeSnapshots(t *testing.T) {
)
logger := logging.DefaultLogger(logrus.DebugLevel, logging.FormatText)
DeleteReadyVolumeSnapshot(tc.vs, tc.vsc, client, logger)
DeleteReadyVolumeSnapshot(tc.vs, client, logger)
vsList := new(snapshotv1api.VolumeSnapshotList)
err := client.List(