Skip to content

Commit 95bd1d1

Browse files
authored
Merge pull request #453 from AndrewSirenko/modifyInfeasibleSlowSet
Ensure infeasible PVC modifications are retried at slower pace
2 parents 4327878 + 350de93 commit 95bd1d1

File tree

8 files changed

+332
-218
lines changed

8 files changed

+332
-218
lines changed

cmd/csi-resizer/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func main() {
222222
var mc modifycontroller.ModifyController
223223
// Add modify controller only if the feature gate is enabled
224224
if utilfeature.DefaultFeatureGate.Enabled(features.VolumeAttributesClass) {
225-
mc = modifycontroller.NewModifyController(modifierName, csiModifier, kubeClient, *resyncPeriod, *extraModifyMetadata, informerFactory,
225+
mc = modifycontroller.NewModifyController(modifierName, csiModifier, kubeClient, *resyncPeriod, *retryIntervalMax, *extraModifyMetadata, informerFactory,
226226
workqueue.NewTypedItemExponentialFailureRateLimiter[string](*retryIntervalStart, *retryIntervalMax))
227227
}
228228

pkg/csi/mock_client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type MockClient struct {
3939
expandCalled atomic.Int32
4040
modifyCalled atomic.Int32
4141
expansionError error
42-
modifyFailed bool
42+
modifyError error
4343
checkMigratedLabel bool
4444
usedSecrets atomic.Pointer[map[string]string]
4545
usedCapability atomic.Pointer[csi.VolumeCapability]
@@ -74,8 +74,8 @@ func (c *MockClient) SetExpansionError(err error) {
7474
c.expansionError = err
7575
}
7676

77-
func (c *MockClient) SetModifyFailed() {
78-
c.modifyFailed = true
77+
func (c *MockClient) SetModifyError(err error) {
78+
c.modifyError = err
7979
}
8080

8181
func (c *MockClient) SetCheckMigratedLabel() {
@@ -135,8 +135,8 @@ func (c *MockClient) Modify(
135135
secrets map[string]string,
136136
mutableParameters map[string]string) error {
137137
c.modifyCalled.Add(1)
138-
if c.modifyFailed {
139-
return fmt.Errorf("modify failed")
138+
if c.modifyError != nil {
139+
return c.modifyError
140140
}
141141
return nil
142142
}

pkg/modifycontroller/controller.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ type modifyController struct {
6161
extraModifyMetadata bool
6262
// the key of the map is {PVC_NAMESPACE}/{PVC_NAME}
6363
uncertainPVCs map[string]v1.PersistentVolumeClaim
64+
// slowSet tracks PVCs for which modification failed with infeasible error and should be retried at slower rate.
65+
slowSet *util.SlowSet
6466
}
6567

6668
// NewModifyController returns a ModifyController.
@@ -69,6 +71,7 @@ func NewModifyController(
6971
modifier modifier.Modifier,
7072
kubeClient kubernetes.Interface,
7173
resyncPeriod time.Duration,
74+
maxRetryInterval time.Duration,
7275
extraModifyMetadata bool,
7376
informerFactory informers.SharedInformerFactory,
7477
pvcRateLimiter workqueue.TypedRateLimiter[string]) ModifyController {
@@ -99,8 +102,9 @@ func NewModifyController(
99102
claimQueue: claimQueue,
100103
eventRecorder: eventRecorder,
101104
extraModifyMetadata: extraModifyMetadata,
105+
slowSet: util.NewSlowSet(maxRetryInterval),
102106
}
103-
// Add a resync period as the PVC's request modify can be modified again when we handling
107+
// Add a resync period as the PVC's request modify can be modified again when we are handling
104108
// a previous modify request of the same PVC.
105109
pvcInformer.Informer().AddEventHandlerWithResyncPeriod(cache.ResourceEventHandlerFuncs{
106110
AddFunc: ctrl.addPVC,
@@ -211,6 +215,10 @@ func (ctrl *modifyController) Run(
211215
}
212216

213217
stopCh := ctx.Done()
218+
219+
// Starts go-routine that deletes expired slowSet entries.
220+
go ctrl.slowSet.Run(stopCh)
221+
214222
for i := 0; i < workers; i++ {
215223
go wait.Until(ctrl.sync, 0, stopCh)
216224
}
@@ -235,7 +243,7 @@ func (ctrl *modifyController) sync() {
235243
}
236244
}
237245

238-
// syncPVC checks if a pvc requests resizing, and execute the resize operation if requested.
246+
// syncPVC checks if a pvc requests modification, and execute the ModifyVolume operation if requested.
239247
func (ctrl *modifyController) syncPVC(key string) error {
240248
klog.V(4).InfoS("Started PVC processing for modify controller", "key", key)
241249

@@ -260,7 +268,7 @@ func (ctrl *modifyController) syncPVC(key string) error {
260268
}
261269

262270
// Only trigger modify volume if the following conditions are met
263-
// 1. Non empty vac name
271+
// 1. Non-empty vac name
264272
// 2. PVC is in Bound state
265273
// 3. PV CSI driver name matches local driver
266274
vacName := pvc.Spec.VolumeAttributesClassName

0 commit comments

Comments
 (0)