From 5d6641f22dbb8433d54dee7cb77acbc57b2f37af Mon Sep 17 00:00:00 2001 From: "Siddhant N. Trivedi" <156179360+strivedi-px@users.noreply.github.com> Date: Mon, 27 May 2024 11:01:02 +0530 Subject: [PATCH] pwx-37435 | fix: update the snapshotschedule post adding default reclaim policy (#1784) * fix: update the snapshotschedule post adding default reclaim policy --- pkg/snapshot/controllers/snapshotschedule.go | 3 +++ test/integration_test/snapshot_test.go | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/pkg/snapshot/controllers/snapshotschedule.go b/pkg/snapshot/controllers/snapshotschedule.go index e098966f01..38e3bbcd31 100644 --- a/pkg/snapshot/controllers/snapshotschedule.go +++ b/pkg/snapshot/controllers/snapshotschedule.go @@ -307,6 +307,9 @@ func (s *SnapshotScheduleController) startVolumeSnapshot(inputSnapshotSchedule * if err != nil { return fmt.Errorf("failed to get volumesnapshot schedule %s", inputSnapshotSchedule.Name) } + // Set the default reclaim policy. + s.setDefaults(snapshotSchedule) + snapshotName := s.formatVolumeSnapshotName(snapshotSchedule, policyType) if snapshotSchedule.Status.Items == nil { snapshotSchedule.Status.Items = make(map[stork_api.SchedulePolicyType][]*stork_api.ScheduledVolumeSnapshotStatus) diff --git a/test/integration_test/snapshot_test.go b/test/integration_test/snapshot_test.go index 71660dd330..0bfd20f67a 100644 --- a/test/integration_test/snapshot_test.go +++ b/test/integration_test/snapshot_test.go @@ -16,6 +16,7 @@ import ( "github.com/portworx/sched-ops/k8s/core" k8sextops "github.com/portworx/sched-ops/k8s/externalstorage" storkops "github.com/portworx/sched-ops/k8s/stork" + "github.com/portworx/sched-ops/task" "github.com/portworx/torpedo/drivers/scheduler" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -498,10 +499,21 @@ func deletePolicyAndSnapshotSchedule(t *testing.T, namespace string, policyName log.FailOnError(t, err, fmt.Sprintf("Error deleting snapshot schedule %v from namespace %v", snapshotScheduleName, namespace)) - time.Sleep(10 * time.Second) - snapshotList, err := k8sextops.Instance().ListSnapshots(namespace) - log.FailOnError(t, err, fmt.Sprintf("Error getting list of snapshots for namespace: %v", namespace)) - Dash.VerifyFatal(t, len(snapshotList.Items), 0, fmt.Sprintf("All snapshots should have been deleted in namespace %v", namespace)) + fn := func() (interface{}, bool, error) { + snapshotList, err := k8sextops.Instance().ListSnapshots(namespace) + if err != nil { + return "", true, err + } + + // Keep retrying if the snapshots are still present. + if len(snapshotList.Items) > 0 { + return "", true, fmt.Errorf("waiting for snapshots deletion in namespace %s,expected=0,got=%d", namespace, len(snapshotList.Items)) + } + return len(snapshotList.Items), false, nil + } + snapshotItems, err := task.DoRetryWithTimeout(fn, defaultWaitTimeout, defaultWaitInterval) + log.FailOnError(t, err, fmt.Sprintf("Error waiting for snapshots deletion in namespace: %v", namespace)) + Dash.VerifyFatal(t, snapshotItems, 0, fmt.Sprintf("All snapshots should have been deleted in namespace %v", namespace)) } func intervalSnapshotScheduleTest(t *testing.T) {