Skip to content

Commit 1faf727

Browse files
authored
Merge pull request #478 from saikat-royc/2.1
Cherrypick #335 - "Call dynamic VS content creation unconditionally"
2 parents 9c6df11 + 4bea398 commit 1faf727

File tree

3 files changed

+72
-25
lines changed

3 files changed

+72
-25
lines changed

pkg/common-controller/framework_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,14 @@ func testUpdateSnapshotClass(ctrl *csiSnapshotCommonController, reactor *snapsho
11341134
return err
11351135
}
11361136

1137+
func testNewSnapshotContentCreation(ctrl *csiSnapshotCommonController, reactor *snapshotReactor, test controllerTest) error {
1138+
if err := ctrl.syncUnreadySnapshot(test.initialSnapshots[0]); err != nil {
1139+
return fmt.Errorf("syncUnreadySnapshot failed: %v", err)
1140+
}
1141+
1142+
return nil
1143+
}
1144+
11371145
var (
11381146
classEmpty string
11391147
classGold = "gold"

pkg/common-controller/snapshot_controller.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -459,34 +459,34 @@ func (ctrl *csiSnapshotCommonController) syncUnreadySnapshot(snapshot *crdv1.Vol
459459
}
460460
klog.V(5).Infof("bindandUpdateVolumeSnapshot %v", newSnapshot)
461461
return nil
462-
} else if snapshot.Status == nil || snapshot.Status.Error == nil || isControllerUpdateFailError(snapshot.Status.Error) {
463-
if snapshot.Spec.Source.PersistentVolumeClaimName == nil {
464-
ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SnapshotPVCSourceMissing", fmt.Sprintf("PVC source for snapshot %s is missing", uniqueSnapshotName))
465-
return fmt.Errorf("expected PVC source for snapshot %s but got nil", uniqueSnapshotName)
466-
} else {
467-
var err error
468-
var content *crdv1.VolumeSnapshotContent
469-
if content, err = ctrl.createSnapshotContent(snapshot); err != nil {
470-
ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SnapshotContentCreationFailed", fmt.Sprintf("Failed to create snapshot content with error %v", err))
471-
return err
472-
}
462+
}
473463

474-
// Update snapshot status with BoundVolumeSnapshotContentName
475-
for i := 0; i < ctrl.createSnapshotContentRetryCount; i++ {
476-
klog.V(5).Infof("syncUnreadySnapshot [%s]: trying to update snapshot status", utils.SnapshotKey(snapshot))
477-
_, err = ctrl.updateSnapshotStatus(snapshot, content)
478-
if err == nil {
479-
break
480-
}
481-
klog.V(4).Infof("failed to update snapshot %s status: %v", utils.SnapshotKey(snapshot), err)
482-
time.Sleep(ctrl.createSnapshotContentInterval)
483-
}
464+
if snapshot.Spec.Source.PersistentVolumeClaimName == nil {
465+
ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SnapshotPVCSourceMissing", fmt.Sprintf("PVC source for snapshot %s is missing", uniqueSnapshotName))
466+
return fmt.Errorf("expected PVC source for snapshot %s but got nil", uniqueSnapshotName)
467+
} else {
468+
var err error
469+
var content *crdv1.VolumeSnapshotContent
470+
if content, err = ctrl.createSnapshotContent(snapshot); err != nil {
471+
ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SnapshotContentCreationFailed", fmt.Sprintf("Failed to create snapshot content with error %v", err))
472+
return err
473+
}
484474

485-
if err != nil {
486-
// update snapshot status failed
487-
ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SnapshotStatusUpdateFailed", fmt.Sprintf("Snapshot status update failed, %v", err))
488-
return err
475+
// Update snapshot status with BoundVolumeSnapshotContentName
476+
for i := 0; i < ctrl.createSnapshotContentRetryCount; i++ {
477+
klog.V(5).Infof("syncUnreadySnapshot [%s]: trying to update snapshot status", utils.SnapshotKey(snapshot))
478+
_, err = ctrl.updateSnapshotStatus(snapshot, content)
479+
if err == nil {
480+
break
489481
}
482+
klog.V(4).Infof("failed to update snapshot %s status: %v", utils.SnapshotKey(snapshot), err)
483+
time.Sleep(ctrl.createSnapshotContentInterval)
484+
}
485+
486+
if err != nil {
487+
// update snapshot status failed
488+
ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SnapshotStatusUpdateFailed", fmt.Sprintf("Snapshot status update failed, %v", err))
489+
return err
490490
}
491491
}
492492
return nil

pkg/common-controller/snapshot_update_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,45 @@ func TestSync(t *testing.T) {
459459
expectSuccess: false,
460460
test: testSyncContentError,
461461
},
462+
{
463+
name: "8-1 - Snapshot status nil, no initial snapshot content, new content should be created",
464+
initialContents: nocontents,
465+
expectedContents: withContentAnnotations(newContentArrayNoStatus("snapcontent-snapuid8-1", "snapuid8-1", "snap8-1", "sid8-1", validSecretClass, "", "pv-handle8-1", deletionPolicy, nil, nil, false, false), map[string]string{utils.AnnDeletionSecretRefName: "secret", utils.AnnDeletionSecretRefNamespace: "default"}),
466+
initialSnapshots: newSnapshotArray("snap8-1", "snapuid8-1", "claim8-1", "", validSecretClass, "", nil, nil, nil, nil, true, false, nil),
467+
expectedSnapshots: newSnapshotArray("snap8-1", "snapuid8-1", "claim8-1", "", validSecretClass, "snapcontent-snapuid8-1", &False, nil, nil, nil, false, false, nil),
468+
initialClaims: newClaimArray("claim8-1", "pvc-uid8-1", "1Gi", "volume8-1", v1.ClaimBound, &classEmpty),
469+
initialVolumes: newVolumeArray("volume8-1", "pv-uid8-1", "pv-handle8-1", "1Gi", "pvc-uid8-1", "claim8-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
470+
initialSecrets: []*v1.Secret{secret()},
471+
errors: noerrors,
472+
expectSuccess: true,
473+
test: testNewSnapshotContentCreation,
474+
},
475+
{
476+
name: "8-2 - Snapshot status with nil error, no initial snapshot content, new content should be created",
477+
initialContents: nocontents,
478+
expectedContents: withContentAnnotations(newContentArrayNoStatus("snapcontent-snapuid8-2", "snapuid8-2", "snap8-2", "sid8-2", validSecretClass, "", "pv-handle8-2", deletionPolicy, nil, nil, false, false), map[string]string{utils.AnnDeletionSecretRefName: "secret", utils.AnnDeletionSecretRefNamespace: "default"}),
479+
initialSnapshots: newSnapshotArray("snap8-2", "snapuid8-2", "claim8-2", "", validSecretClass, "", nil, nil, nil, nil, false, false, nil),
480+
expectedSnapshots: newSnapshotArray("snap8-2", "snapuid8-2", "claim8-2", "", validSecretClass, "snapcontent-snapuid8-2", &False, nil, nil, nil, false, false, nil),
481+
initialClaims: newClaimArray("claim8-2", "pvc-uid8-2", "1Gi", "volume8-2", v1.ClaimBound, &classEmpty),
482+
initialVolumes: newVolumeArray("volume8-2", "pv-uid8-2", "pv-handle8-2", "1Gi", "pvc-uid8-2", "claim8-2", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
483+
initialSecrets: []*v1.Secret{secret()},
484+
errors: noerrors,
485+
expectSuccess: true,
486+
test: testNewSnapshotContentCreation,
487+
},
488+
{
489+
name: "8-3 - Snapshot status with error, no initial content, new content created with no status, snapshot updates bound content and readytoUse=False state, error will not be cleared",
490+
initialContents: nocontents,
491+
expectedContents: withContentAnnotations(newContentArrayNoStatus("snapcontent-snapuid8-3", "snapuid8-3", "snap8-3", "sid8-3", validSecretClass, "", "pv-handle8-3", deletionPolicy, nil, nil, false, false), map[string]string{utils.AnnDeletionSecretRefName: "secret", utils.AnnDeletionSecretRefNamespace: "default"}),
492+
initialSnapshots: newSnapshotArray("snap8-3", "snapuid8-3", "claim8-3", "", validSecretClass, "", nil, nil, nil, newVolumeError("Mock content error"), false, false, nil),
493+
expectedSnapshots: newSnapshotArray("snap8-3", "snapuid8-3", "claim8-3", "", validSecretClass, "snapcontent-snapuid8-3", &False, nil, nil, newVolumeError("Mock content error"), false, false, nil),
494+
initialClaims: newClaimArray("claim8-3", "pvc-uid8-3", "1Gi", "volume8-3", v1.ClaimBound, &classEmpty),
495+
initialVolumes: newVolumeArray("volume8-3", "pv-uid8-3", "pv-handle8-3", "1Gi", "pvc-uid8-3", "claim8-3", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
496+
initialSecrets: []*v1.Secret{secret()},
497+
errors: noerrors,
498+
expectSuccess: true,
499+
test: testNewSnapshotContentCreation,
500+
},
462501
}
463502

464503
runSyncTests(t, tests, snapshotClasses)

0 commit comments

Comments
 (0)