@@ -39,8 +39,9 @@ const (
39
39
40
40
// The return value bool is only used as a sentinel value when function returns without actually performing modification
41
41
func (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
+
44
45
pvcKey , err := cache .MetaNamespaceKeyFunc (pvc )
45
46
if err != nil {
46
47
return pvc , pv , err , false
@@ -52,38 +53,34 @@ func (ctrl *modifyController) modify(pvc *v1.PersistentVolumeClaim, pv *v1.Persi
52
53
return pvc , pv , delayModificationErr , false
53
54
}
54
55
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 :
57
66
return ctrl .validateVACAndModifyVolumeWithTarget (pvc , pv )
58
- } else if pvcSpecVacName != nil && curVacName != nil && * pvcSpecVacName != * curVacName {
67
+ case * currentVacName != * pvcSpecVACName :
59
68
// Check if PVC in uncertain state
60
69
_ , inUncertainState := ctrl .uncertainPVCs [pvcKey ]
61
70
if ! inUncertainState {
62
71
klog .V (3 ).InfoS ("previous operation on the PVC failed with a final error, retrying" )
63
72
return ctrl .validateVACAndModifyVolumeWithTarget (pvc , pv )
64
73
} else {
65
- vac , err := ctrl .vacLister .Get (* pvcSpecVacName )
74
+ vac , err := ctrl .vacLister .Get (* pvcSpecVACName )
66
75
if err != nil {
67
76
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." )
69
78
}
70
79
return pvc , pv , err , false
71
80
}
72
- return ctrl .controllerModifyVolumeWithTarget (pvc , pv , vac , pvcSpecVacName )
81
+ return ctrl .controllerModifyVolumeWithTarget (pvc , pv , vac , pvcSpecVACName )
73
82
}
74
83
}
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
87
84
return pvc , pv , nil , false
88
85
}
89
86
@@ -123,8 +120,12 @@ func (ctrl *modifyController) validateVACAndRollback(
123
120
// The controller does not triggers ModifyVolume because it is only
124
121
// for rollbacking infeasible errors
125
122
// 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
+ }
126
127
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 ))
128
129
// Mark pvc.Status.ModifyVolumeStatus as completed
129
130
pvc , pv , err := ctrl .markCotrollerModifyVolumeRollbackCompeleted (pvc , pv )
130
131
if err != nil {
0 commit comments