@@ -37,8 +37,9 @@ const (
37
37
38
38
// The return value bool is only used as a sentinel value when function returns without actually performing modification
39
39
func (ctrl * modifyController ) modify (pvc * v1.PersistentVolumeClaim , pv * v1.PersistentVolume ) (* v1.PersistentVolumeClaim , * v1.PersistentVolume , error , bool ) {
40
- pvcSpecVacName := pvc .Spec .VolumeAttributesClassName
41
- curVacName := pvc .Status .CurrentVolumeAttributesClassName
40
+ pvcSpecVACName := pvc .Spec .VolumeAttributesClassName
41
+ currentVacName := pvc .Status .CurrentVolumeAttributesClassName
42
+
42
43
pvcKey , err := cache .MetaNamespaceKeyFunc (pvc )
43
44
if err != nil {
44
45
return pvc , pv , err , false
@@ -50,39 +51,50 @@ func (ctrl *modifyController) modify(pvc *v1.PersistentVolumeClaim, pv *v1.Persi
50
51
return pvc , pv , delayModificationErr , false
51
52
}
52
53
53
- if pvcSpecVacName != nil && curVacName == nil {
54
- // First time adding VAC to a PVC
54
+ if currentModificationInfeasible (pvc ) && isVacRolledBack (pvc ) {
55
+ return ctrl .validateVACAndRollback (pvc , pv )
56
+ }
57
+
58
+ if pvcSpecVACName == nil {
59
+ return pvc , pv , nil , false
60
+ }
61
+
62
+ switch {
63
+ case currentVacName == nil :
55
64
return ctrl .validateVACAndModifyVolumeWithTarget (pvc , pv )
56
- } else if pvcSpecVacName != nil && curVacName != nil && * pvcSpecVacName != * curVacName {
65
+ case * currentVacName != * pvcSpecVACName :
57
66
// Check if PVC in uncertain state
58
67
_ , inUncertainState := ctrl .uncertainPVCs [pvcKey ]
59
68
if ! inUncertainState {
60
69
klog .V (3 ).InfoS ("previous operation on the PVC failed with a final error, retrying" )
61
70
return ctrl .validateVACAndModifyVolumeWithTarget (pvc , pv )
62
71
} else {
63
- vac , err := ctrl .vacLister .Get (* pvcSpecVacName )
72
+ vac , err := ctrl .vacLister .Get (* pvcSpecVACName )
64
73
if err != nil {
65
74
if apierrors .IsNotFound (err ) {
66
- ctrl .eventRecorder .Eventf (pvc , v1 .EventTypeWarning , util .VolumeModifyFailed , "VAC " + * pvcSpecVacName + " does not exist." )
75
+ ctrl .eventRecorder .Eventf (pvc , v1 .EventTypeWarning , util .VolumeModifyFailed , "VAC " + * pvcSpecVACName + " does not exist." )
67
76
}
68
77
return pvc , pv , err , false
69
78
}
70
- return ctrl .controllerModifyVolumeWithTarget (pvc , pv , vac , pvcSpecVacName )
79
+ return ctrl .controllerModifyVolumeWithTarget (pvc , pv , vac , pvcSpecVACName )
71
80
}
72
81
}
82
+ return pvc , pv , nil , false
83
+ }
73
84
74
- // Rollback infeasible errors for recovery
75
- if pvc .Status .ModifyVolumeStatus != nil && pvc .Status .ModifyVolumeStatus .Status == v1 .PersistentVolumeClaimModifyVolumeInfeasible {
76
- targetVacName := pvc .Status .ModifyVolumeStatus .TargetVolumeAttributesClassName
77
- // Case 1: rollback to nil
78
- // Case 2: rollback to previous VAC
79
- if (pvcSpecVacName == nil && curVacName == nil && targetVacName != "" ) || (pvcSpecVacName != nil && curVacName != nil && * pvcSpecVacName == * curVacName && targetVacName != * curVacName ) {
80
- return ctrl .validateVACAndRollback (pvc , pv )
81
- }
82
- }
85
+ func isVacRolledBack (pvc * v1.PersistentVolumeClaim ) bool {
86
+ pvcSpecVacName := pvc .Spec .VolumeAttributesClassName
87
+ curVacName := pvc .Status .CurrentVolumeAttributesClassName
88
+ targetVacName := pvc .Status .ModifyVolumeStatus .TargetVolumeAttributesClassName
89
+ // Case 1: rollback to nil
90
+ // Case 2: rollback to previous VAC
91
+ return (pvcSpecVacName == nil && curVacName == nil && targetVacName != "" ) ||
92
+ (pvcSpecVacName != nil && curVacName != nil &&
93
+ * pvcSpecVacName == * curVacName && targetVacName != * curVacName )
94
+ }
83
95
84
- // No modification required
85
- return pvc , pv , nil , false
96
+ func currentModificationInfeasible ( pvc * v1. PersistentVolumeClaim ) bool {
97
+ return pvc . Status . ModifyVolumeStatus != nil && pvc . Status . ModifyVolumeStatus . Status == v1 . PersistentVolumeClaimModifyVolumeInfeasible
86
98
}
87
99
88
100
// func validateVACAndModifyVolumeWithTarget validate the VAC. The function sets pvc.Status.ModifyVolumeStatus
@@ -121,8 +133,12 @@ func (ctrl *modifyController) validateVACAndRollback(
121
133
// The controller does not triggers ModifyVolume because it is only
122
134
// for rollbacking infeasible errors
123
135
// Record an event to indicate that external resizer is rolling back this volume.
136
+ rollbackVACName := "nil"
137
+ if pvc .Spec .VolumeAttributesClassName != nil {
138
+ rollbackVACName = * pvc .Spec .VolumeAttributesClassName
139
+ }
124
140
ctrl .eventRecorder .Event (pvc , v1 .EventTypeNormal , util .VolumeModify ,
125
- fmt .Sprintf ("external resizer is rolling back volume %s with infeasible error" , pvc .Name ))
141
+ fmt .Sprintf ("external resizer is rolling back volume %s with infeasible error to VAC %s " , pvc .Name , rollbackVACName ))
126
142
// Mark pvc.Status.ModifyVolumeStatus as completed
127
143
pvc , pv , err := ctrl .markCotrollerModifyVolumeRollbackCompeleted (pvc , pv )
128
144
if err != nil {
0 commit comments