Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure infeasible PVC modifications are retried at slower pace #453

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/csi-resizer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func main() {
var mc modifycontroller.ModifyController
// Add modify controller only if the feature gate is enabled
if utilfeature.DefaultFeatureGate.Enabled(features.VolumeAttributesClass) {
mc = modifycontroller.NewModifyController(modifierName, csiModifier, kubeClient, *resyncPeriod, *extraModifyMetadata, informerFactory,
mc = modifycontroller.NewModifyController(modifierName, csiModifier, kubeClient, *resyncPeriod, *retryIntervalMax, *extraModifyMetadata, informerFactory,
workqueue.NewTypedItemExponentialFailureRateLimiter[string](*retryIntervalStart, *retryIntervalMax))
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/csi/mock_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type MockClient struct {
expandCalled atomic.Int32
modifyCalled atomic.Int32
expansionError error
modifyFailed bool
modifyError error
checkMigratedLabel bool
usedSecrets atomic.Pointer[map[string]string]
usedCapability atomic.Pointer[csi.VolumeCapability]
Expand Down Expand Up @@ -74,8 +74,8 @@ func (c *MockClient) SetExpansionError(err error) {
c.expansionError = err
}

func (c *MockClient) SetModifyFailed() {
c.modifyFailed = true
func (c *MockClient) SetModifyError(err error) {
c.modifyError = err
}

func (c *MockClient) SetCheckMigratedLabel() {
Expand Down Expand Up @@ -135,8 +135,8 @@ func (c *MockClient) Modify(
secrets map[string]string,
mutableParameters map[string]string) error {
c.modifyCalled.Add(1)
if c.modifyFailed {
return fmt.Errorf("modify failed")
if c.modifyError != nil {
return c.modifyError
}
return nil
}
14 changes: 11 additions & 3 deletions pkg/modifycontroller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type modifyController struct {
extraModifyMetadata bool
// the key of the map is {PVC_NAMESPACE}/{PVC_NAME}
uncertainPVCs map[string]v1.PersistentVolumeClaim
// slowSet tracks PVCs for which modification failed with infeasible error and should be retried at slower rate.
slowSet *util.SlowSet
}

// NewModifyController returns a ModifyController.
Expand All @@ -69,6 +71,7 @@ func NewModifyController(
modifier modifier.Modifier,
kubeClient kubernetes.Interface,
resyncPeriod time.Duration,
maxRetryInterval time.Duration,
extraModifyMetadata bool,
informerFactory informers.SharedInformerFactory,
pvcRateLimiter workqueue.TypedRateLimiter[string]) ModifyController {
Expand Down Expand Up @@ -99,8 +102,9 @@ func NewModifyController(
claimQueue: claimQueue,
eventRecorder: eventRecorder,
extraModifyMetadata: extraModifyMetadata,
slowSet: util.NewSlowSet(maxRetryInterval),
}
// Add a resync period as the PVC's request modify can be modified again when we handling
// Add a resync period as the PVC's request modify can be modified again when we are handling
// a previous modify request of the same PVC.
pvcInformer.Informer().AddEventHandlerWithResyncPeriod(cache.ResourceEventHandlerFuncs{
AddFunc: ctrl.addPVC,
Expand Down Expand Up @@ -211,6 +215,10 @@ func (ctrl *modifyController) Run(
}

stopCh := ctx.Done()

// Starts go-routine that deletes expired slowSet entries.
go ctrl.slowSet.Run(stopCh)
AndrewSirenko marked this conversation as resolved.
Show resolved Hide resolved

for i := 0; i < workers; i++ {
go wait.Until(ctrl.sync, 0, stopCh)
}
Expand All @@ -235,7 +243,7 @@ func (ctrl *modifyController) sync() {
}
}

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

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

// Only trigger modify volume if the following conditions are met
// 1. Non empty vac name
// 1. Non-empty vac name
// 2. PVC is in Bound state
// 3. PV CSI driver name matches local driver
vacName := pvc.Spec.VolumeAttributesClassName
Expand Down
Loading