Skip to content

Commit 0df2a99

Browse files
committed
don't change target in uncertain state
We should keep retry the previously specified target.
1 parent 5459e07 commit 0df2a99

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

pkg/modifycontroller/modify_status.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func (ctrl *modifyController) markControllerModifyVolumeStatus(
4747
case v1.PersistentVolumeClaimModifyVolumeInProgress:
4848
conditionMessage = "ModifyVolume operation in progress."
4949
case v1.PersistentVolumeClaimModifyVolumeInfeasible:
50+
newPVC.Status.ModifyVolumeStatus.TargetVolumeAttributesClassName = pvc.Status.ModifyVolumeStatus.TargetVolumeAttributesClassName
5051
conditionMessage = "ModifyVolume failed with error " + err.Error() + ". Waiting for retry."
5152
}
5253
pvcCondition.Message = conditionMessage

pkg/modifycontroller/modify_volume.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ func (ctrl *modifyController) modify(pvc *v1.PersistentVolumeClaim, pv *v1.Persi
5858
} else if pvcSpecVacName != nil && curVacName != nil && *pvcSpecVacName != *curVacName {
5959
// Check if PVC in uncertain state
6060
_, inUncertainState := ctrl.uncertainPVCs.Load(pvcKey)
61-
if !inUncertainState {
62-
klog.V(3).InfoS("previous operation on the PVC failed with a final error, retrying")
61+
status := pvc.Status.ModifyVolumeStatus
62+
if !inUncertainState || status == nil {
63+
klog.V(3).InfoS("previous operation on the PVC succeeded or failed with a final error, retrying")
6364
return ctrl.validateVACAndModifyVolumeWithTarget(pvc, pv)
6465
} else {
65-
vac, err := ctrl.vacLister.Get(*pvcSpecVacName)
66+
vac, err := ctrl.vacLister.Get(status.TargetVolumeAttributesClassName)
6667
if err != nil {
6768
if apierrors.IsNotFound(err) {
68-
ctrl.eventRecorder.Eventf(pvc, v1.EventTypeWarning, util.VolumeModifyFailed, "VAC "+*pvcSpecVacName+" does not exist.")
69+
ctrl.eventRecorder.Eventf(pvc, v1.EventTypeWarning, util.VolumeModifyFailed, "VAC "+status.TargetVolumeAttributesClassName+" does not exist.")
6970
}
7071
return pvc, pv, err, false
7172
}

pkg/modifycontroller/modify_volume_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"k8s.io/client-go/informers"
1616
"k8s.io/client-go/kubernetes"
1717
"k8s.io/client-go/kubernetes/fake"
18+
"k8s.io/utils/ptr"
1819
)
1920

2021
var (
@@ -185,12 +186,22 @@ func TestModifyUncertain(t *testing.T) {
185186
assertUncertain(false)
186187

187188
client.SetModifyError(nonFinalErr)
188-
_, _, err, _ = ctrlInstance.modify(pvc, pv)
189+
pvc, pv, err, _ = ctrlInstance.modify(pvc, pv)
189190
if !errors.Is(err, nonFinalErr) {
190191
t.Fatalf("expected error to be %v, got %v", nonFinalErr, err)
191192
}
192193
// should enter uncertain state again
193194
assertUncertain(true)
195+
196+
pvc.Spec.VolumeAttributesClassName = ptr.To("yet-another-vac")
197+
pvc, _, err, _ = ctrlInstance.modify(pvc, pv)
198+
if !errors.Is(err, nonFinalErr) {
199+
t.Fatalf("expected error to be %v, got %v", nonFinalErr, err)
200+
}
201+
// target should not change, yet-another-vac should be ignored
202+
if pvc.Status.ModifyVolumeStatus.TargetVolumeAttributesClassName != targetVac {
203+
t.Fatalf("expected target to be %v, got %v", targetVac, pvc.Status.ModifyVolumeStatus.TargetVolumeAttributesClassName)
204+
}
194205
}
195206

196207
func createTestPVC(pvcName string, vacName string, curVacName string, targetVacName string) *v1.PersistentVolumeClaim {

0 commit comments

Comments
 (0)