Code change:
func TestCheckVolumeFSResize(t *testing.T) { mode := v1.PersistentVolumeFilesystem <del> pv := &v1.PersistentVolume{ ObjectMeta: metav1.ObjectMeta{ Name: "dswp-test-volume-name", </del> <ins> setCapacity := func(pv *v1.PersistentVolume, pvc *v1.PersistentVolumeClaim, capacity int) { pv.Spec.Capacity = volumeCapacity(capacity) pvc.Spec.Resources.Requests = volumeCapacity(capacity) } testcases := []struct { resize       func(*testing.T, *v1.PersistentVolume, *v1.PersistentVolumeClaim, *desiredStateOfWorldPopulator) verify       func(*testing.T, []v1.UniqueVolumeName, v1.UniqueVolumeName) enableResize bool readOnlyVol  bool }{ { // No resize request for volume, volumes in ASW shouldn't be marked as fsResizeRequired resize: func(*testing.T, *v1.PersistentVolume, *v1.PersistentVolumeClaim, *desiredStateOfWorldPopulator) { }, verify: func(t *testing.T, vols []v1.UniqueVolumeName, _ v1.UniqueVolumeName) { if len(vols) > 0 { t.Errorf("No resize request for any volumes, but found resize required volumes in ASW: %v", vols) } }, enableResize: true, </ins> }, <del> Spec: v1.PersistentVolumeSpec{ PersistentVolumeSource: v1.PersistentVolumeSource{RBD: &v1.RBDPersistentVolumeSource{}}, Capacity:               volumeCapacity(1), ClaimRef:               &v1.ObjectReference{Namespace: "ns", Name: "file-bound"}, VolumeMode:             &mode, </del> <ins> { // Disable the feature gate, so volume shouldn't be marked as fsResizeRequired resize: func(_ *testing.T, pv *v1.PersistentVolume, pvc *v1.PersistentVolumeClaim, _ *desiredStateOfWorldPopulator) { setCapacity(pv, pvc, 2) }, verify: func(t *testing.T, vols []v1.UniqueVolumeName, _ v1.UniqueVolumeName) { if len(vols) > 0 { t.Errorf("Feature gate disabled, but found resize required volumes in ASW: %v", vols) } }, enableResize: false, </ins> }, <del> } pvc := &v1.PersistentVolumeClaim{ Spec: v1.PersistentVolumeClaimSpec{ VolumeName: "dswp-test-volume-name", Resources: v1.ResourceRequirements{ Requests: volumeCapacity(1), </del> <ins> { // Make volume used as ReadOnly, so volume shouldn't be marked as fsResizeRequired resize: func(_ *testing.T, pv *v1.PersistentVolume, pvc *v1.PersistentVolumeClaim, _ *desiredStateOfWorldPopulator) { setCapacity(pv, pvc, 2) </ins> }, <ins> verify: func(t *testing.T, vols []v1.UniqueVolumeName, _ v1.UniqueVolumeName) { if len(vols) > 0 { t.Errorf("volume mounted as ReadOnly, but found resize required volumes in ASW: %v", vols) } }, readOnlyVol:  true, enableResize: true, </ins> }, <del> Status: v1.PersistentVolumeClaimStatus{ Phase:    v1.ClaimBound, Capacity: volumeCapacity(1), </del> <ins> { // Clear ASW, so volume shouldn't be marked as fsResizeRequired because they are not mounted resize: func(_ *testing.T, pv *v1.PersistentVolume, pvc *v1.PersistentVolumeClaim, dswp *desiredStateOfWorldPopulator) { setCapacity(pv, pvc, 2) clearASW(dswp.actualStateOfWorld, dswp.desiredStateOfWorld, t) }, verify: func(t *testing.T, vols []v1.UniqueVolumeName, _ v1.UniqueVolumeName) { if len(vols) > 0 { t.Errorf("volume hasn't been mounted, but found resize required volumes in ASW: %v", vols) } }, enableResize: true, </ins> }, <del> } dswp, fakePodManager, fakeDSW := createDswpWithVolume(t, pv, pvc) fakeASW := dswp.actualStateOfWorld // create pod containers := []v1.Container{ </del> { <del> VolumeMounts: []v1.VolumeMount{ { Name:      "dswp-test-volume-name", MountPath: "/mnt", }, </del> <ins> // volume in ASW should be marked as fsResizeRequired resize: func(_ *testing.T, pv *v1.PersistentVolume, pvc *v1.PersistentVolumeClaim, _ *desiredStateOfWorldPopulator) { setCapacity(pv, pvc, 2) }, verify: func(t *testing.T, vols []v1.UniqueVolumeName, volName v1.UniqueVolumeName) { if len(vols) == 0 { t.Fatalf("Request resize for volume, but volume in ASW hasn't been marked as fsResizeRequired") } if len(vols) != 1 { t.Errorf("Some unexpected volumes are marked as fsResizeRequired: %v", vols) } if vols[0] != volName { t.Fatalf("Mark wrong volume as fsResizeRequired: %s", vols[0]) } </ins> }, <ins> enableResize: true, </ins> }, } <del> pod := createPodWithVolume("dswp-test-pod", "dswp-test-volume-name", "file-bound", containers) uniquePodName := types.UniquePodName(pod.UID) uniqueVolumeName := v1.UniqueVolumeName("fake-plugin/" + pod.Spec.Volumes[0].Name) fakePodManager.AddPod(pod) // Fill the dsw to contains volumes and pods. dswp.findAndAddNewPods() reconcileASW(fakeASW, fakeDSW, t) </del> <ins> for _, tc := range testcases { pv := &v1.PersistentVolume{ ObjectMeta: metav1.ObjectMeta{ Name: "dswp-test-volume-name", }, Spec: v1.PersistentVolumeSpec{ PersistentVolumeSource: v1.PersistentVolumeSource{RBD: &v1.RBDPersistentVolumeSource{}}, Capacity:               volumeCapacity(1), ClaimRef:               &v1.ObjectReference{Namespace: "ns", Name: "file-bound"}, VolumeMode:             &mode, }, } pvc := &v1.PersistentVolumeClaim{ Spec: v1.PersistentVolumeClaimSpec{ VolumeName: pv.Name, Resources: v1.ResourceRequirements{ Requests: pv.Spec.Capacity, }, }, Status: v1.PersistentVolumeClaimStatus{ Phase:    v1.ClaimBound, Capacity: pv.Spec.Capacity, }, } </ins> <del> // No resize request for volume, volumes in ASW shouldn't be marked as fsResizeRequired. defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ExpandInUsePersistentVolumes, true)() resizeRequiredVolumes := reprocess(dswp, uniquePodName, fakeDSW, fakeASW) if len(resizeRequiredVolumes) > 0 { t.Fatalf("No resize request for any volumes, but found resize required volumes in ASW: %v", resizeRequiredVolumes) } </del> <ins> dswp, fakePodManager, fakeDSW := createDswpWithVolume(t, pv, pvc) fakeASW := dswp.actualStateOfWorld // create pod containers := []v1.Container{ { VolumeMounts: []v1.VolumeMount{ { Name:      pv.Name, MountPath: "/mnt", ReadOnly:  tc.readOnlyVol, }, }, }, } pod := createPodWithVolume("dswp-test-pod", "dswp-test-volume-name", "file-bound", containers) uniquePodName := types.UniquePodName(pod.UID) uniqueVolumeName := v1.UniqueVolumeName("fake-plugin/" + pod.Spec.Volumes[0].Name) </ins> <del> // Add a resize request to volume. pv.Spec.Capacity = volumeCapacity(2) pvc.Spec.Resources.Requests = volumeCapacity(2) </del> <ins> fakePodManager.AddPod(pod) // Fill the dsw to contains volumes and pods. dswp.findAndAddNewPods() reconcileASW(fakeASW, fakeDSW, t) </ins> <del> // Disable the feature gate, so volume shouldn't be marked as fsResizeRequired. defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ExpandInUsePersistentVolumes, false)() resizeRequiredVolumes = reprocess(dswp, uniquePodName, fakeDSW, fakeASW) if len(resizeRequiredVolumes) > 0 { t.Fatalf("Feature gate disabled, but found resize required volumes in ASW: %v", resizeRequiredVolumes) } </del> <ins> func() { defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ExpandInUsePersistentVolumes, tc.enableResize)() </ins> <del> // Make volume used as ReadOnly, so volume shouldn't be marked as fsResizeRequired. defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ExpandInUsePersistentVolumes, true)() pod.Spec.Containers[0].VolumeMounts[0].ReadOnly = true resizeRequiredVolumes = reprocess(dswp, uniquePodName, fakeDSW, fakeASW) if len(resizeRequiredVolumes) > 0 { t.Fatalf("volume mounted as ReadOnly, but found resize required volumes in ASW: %v", resizeRequiredVolumes) } </del> <ins> tc.resize(t, pv, pvc, dswp) </ins> <del> // Clear ASW, so volume shouldn't be marked as fsResizeRequired because they are not mounted. pod.Spec.Containers[0].VolumeMounts[0].ReadOnly = false clearASW(fakeASW, fakeDSW, t) resizeRequiredVolumes = reprocess(dswp, uniquePodName, fakeDSW, fakeASW) if len(resizeRequiredVolumes) > 0 { t.Fatalf("volume hasn't been mounted, but found resize required volumes in ASW: %v", resizeRequiredVolumes) } </del> <ins> resizeRequiredVolumes := reprocess(dswp, uniquePodName, fakeDSW, fakeASW) </ins> <del> // volume in ASW should be marked as fsResizeRequired. reconcileASW(fakeASW, fakeDSW, t) resizeRequiredVolumes = reprocess(dswp, uniquePodName, fakeDSW, fakeASW) if len(resizeRequiredVolumes) == 0 { t.Fatalf("Request resize for volume, but volume in ASW hasn't been marked as fsResizeRequired") } if len(resizeRequiredVolumes) != 1 { t.Fatalf("Some unexpected volumes are marked as fsResizeRequired: %v", resizeRequiredVolumes) } if resizeRequiredVolumes[0] != uniqueVolumeName { t.Fatalf("Mark wrong volume as fsResizeRequired: %s", resizeRequiredVolumes[0]) </del> <ins> tc.verify(t, resizeRequiredVolumes, uniqueVolumeName) }() </ins> } }

Related discussion:
text: <!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks!--What happened: These test cases are very hard to follow because they keep toggling the feature gates on and off, and subsequent test cases depend on the behavior of the previous. <!-- DO NOT EDIT BELOW THIS LINE --/kind bug
/assign
Issues go stale after 90d of inactivity. Mark the issue as fresh with . Stale issues rot after an additional 30d of inactivity and eventually close. If this issue is safe to close now please do so with . Send feedback to sig-testing, kubernetes/test-infra and/or . /lifecycle stale
/remove-lifecycle-stale
Stale issues rot after 30d of inactivity. Mark the issue as fresh with . Rotten issues close after an additional 30d of inactivity. If this issue is safe to close now please do so with . Send feedback to sig-testing, kubernetes/test-infra and/or . /lifecycle rotten
Rotten issues close after 30d of inactivity. Reopen the issue with . Mark the issue as fresh with . Send feedback to sig-testing, kubernetes/test-infra and/or . /close
Closing this issue. <detailsIn response to : Rotten issues close after 30d of inactivity. Reopen the issue with . Mark the issue as fresh with . /close Instructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
/reopen
Reopened this issue. <detailsIn response to : /reopen Instructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
/remove-lifecycle rotten
/help
This request has been marked as needing help from a contributor. Please ensure the request meets the requirements listed . If this request no longer meets these requirements, the label can be removed by commenting with the command. <detailsIn response to : /help Instructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
Hey, I'd like to take this if nobody is working on it
Hi thanks for volunteering! Let us know if you have any questions