@@ -39,8 +39,9 @@ const (
3939
4040// The return value bool is only used as a sentinel value when function returns without actually performing modification
4141func (ctrl * modifyController ) modify (pvc * v1.PersistentVolumeClaim , pv * v1.PersistentVolume ) (* v1.PersistentVolumeClaim , * v1.PersistentVolume , error , bool ) {
42- pvcSpecVacName := pvc .Spec .VolumeAttributesClassName
43- curVacName := pvc .Status .CurrentVolumeAttributesClassName
42+ pvcSpecVACName := pvc .Spec .VolumeAttributesClassName
43+ currentVacName := pvc .Status .CurrentVolumeAttributesClassName
44+
4445 pvcKey , err := cache .MetaNamespaceKeyFunc (pvc )
4546 if err != nil {
4647 return pvc , pv , err , false
@@ -52,38 +53,34 @@ func (ctrl *modifyController) modify(pvc *v1.PersistentVolumeClaim, pv *v1.Persi
5253 return pvc , pv , delayModificationErr , false
5354 }
5455
55- if pvcSpecVacName != nil && curVacName == nil {
56- // First time adding VAC to a PVC
56+ if util .CurrentModificationInfeasible (pvc ) && util .IsVacRolledBack (pvc ) {
57+ return ctrl .validateVACAndRollback (pvc , pv )
58+ }
59+
60+ if pvcSpecVACName == nil {
61+ return pvc , pv , nil , false
62+ }
63+
64+ switch {
65+ case currentVacName == nil :
5766 return ctrl .validateVACAndModifyVolumeWithTarget (pvc , pv )
58- } else if pvcSpecVacName != nil && curVacName != nil && * pvcSpecVacName != * curVacName {
67+ case * currentVacName != * pvcSpecVACName :
5968 // Check if PVC in uncertain state
6069 _ , inUncertainState := ctrl .uncertainPVCs [pvcKey ]
6170 if ! inUncertainState {
6271 klog .V (3 ).InfoS ("previous operation on the PVC failed with a final error, retrying" )
6372 return ctrl .validateVACAndModifyVolumeWithTarget (pvc , pv )
6473 } else {
65- vac , err := ctrl .vacLister .Get (* pvcSpecVacName )
74+ vac , err := ctrl .vacLister .Get (* pvcSpecVACName )
6675 if err != nil {
6776 if apierrors .IsNotFound (err ) {
68- ctrl .eventRecorder .Eventf (pvc , v1 .EventTypeWarning , util .VolumeModifyFailed , "VAC " + * pvcSpecVacName + " does not exist." )
77+ ctrl .eventRecorder .Eventf (pvc , v1 .EventTypeWarning , util .VolumeModifyFailed , "VAC " + * pvcSpecVACName + " does not exist." )
6978 }
7079 return pvc , pv , err , false
7180 }
72- return ctrl .controllerModifyVolumeWithTarget (pvc , pv , vac , pvcSpecVacName )
81+ return ctrl .controllerModifyVolumeWithTarget (pvc , pv , vac , pvcSpecVACName )
7382 }
7483 }
75-
76- // Rollback infeasible errors for recovery
77- if pvc .Status .ModifyVolumeStatus != nil && pvc .Status .ModifyVolumeStatus .Status == v1 .PersistentVolumeClaimModifyVolumeInfeasible {
78- targetVacName := pvc .Status .ModifyVolumeStatus .TargetVolumeAttributesClassName
79- // Case 1: rollback to nil
80- // Case 2: rollback to previous VAC
81- if (pvcSpecVacName == nil && curVacName == nil && targetVacName != "" ) || (pvcSpecVacName != nil && curVacName != nil && * pvcSpecVacName == * curVacName && targetVacName != * curVacName ) {
82- return ctrl .validateVACAndRollback (pvc , pv )
83- }
84- }
85-
86- // No modification required
8784 return pvc , pv , nil , false
8885}
8986
@@ -123,8 +120,12 @@ func (ctrl *modifyController) validateVACAndRollback(
123120 // The controller does not triggers ModifyVolume because it is only
124121 // for rollbacking infeasible errors
125122 // Record an event to indicate that external resizer is rolling back this volume.
123+ rollbackVACName := "nil"
124+ if pvc .Spec .VolumeAttributesClassName != nil {
125+ rollbackVACName = * pvc .Spec .VolumeAttributesClassName
126+ }
126127 ctrl .eventRecorder .Event (pvc , v1 .EventTypeNormal , util .VolumeModify ,
127- fmt .Sprintf ("external resizer is rolling back volume %s with infeasible error" , pvc .Name ))
128+ fmt .Sprintf ("external resizer is rolling back volume %s with infeasible error to VAC %s " , pvc .Name , rollbackVACName ))
128129 // Mark pvc.Status.ModifyVolumeStatus as completed
129130 pvc , pv , err := ctrl .markCotrollerModifyVolumeRollbackCompeleted (pvc , pv )
130131 if err != nil {
0 commit comments