Skip to content

Commit

Permalink
pwx-37435 | fix: update the snapshotschedule post adding default recl…
Browse files Browse the repository at this point in the history
…aim policy (#1784)

* fix: update the snapshotschedule post adding default reclaim policy
  • Loading branch information
strivedi-px committed May 27, 2024
1 parent 5d5f16e commit a56733b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions pkg/snapshot/controllers/snapshotschedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 16 additions & 4 deletions test/integration_test/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a56733b

Please sign in to comment.