From 402fe4ec9bb315a10aa49c92a5a4dc2e89873dfe Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Tue, 24 Jan 2023 18:43:42 -0500 Subject: [PATCH] use expansion without recovery if allocatedResource is not unset --- .../operationexecutor/operation_generator.go | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/pkg/volume/util/operationexecutor/operation_generator.go b/pkg/volume/util/operationexecutor/operation_generator.go index 13348a54bc0..120191488a4 100644 --- a/pkg/volume/util/operationexecutor/operation_generator.go +++ b/pkg/volume/util/operationexecutor/operation_generator.go @@ -2103,7 +2103,7 @@ func (og *operationGenerator) expandVolumeDuringMount(volumeToMount VolumeToMoun volumePlugin: expandablePlugin, actualStateOfWorld: actualStateOfWorld, } - if utilfeature.DefaultFeatureGate.Enabled(features.RecoverVolumeExpansionFailure) { + if og.checkForRecoveryFromExpansion(pvc, volumeToMount) { nodeExpander := newNodeExpander(resizeOp, og.kubeClient, og.recorder) resizeFinished, err, _ := nodeExpander.expandOnPlugin() return resizeFinished, err @@ -2165,7 +2165,8 @@ func (og *operationGenerator) nodeExpandVolume( volumePlugin: expandableVolumePlugin, actualStateOfWorld: actualStateOfWorld, } - if utilfeature.DefaultFeatureGate.Enabled(features.RecoverVolumeExpansionFailure) { + + if og.checkForRecoveryFromExpansion(pvc, volumeToMount) { nodeExpander := newNodeExpander(resizeOp, og.kubeClient, og.recorder) resizeFinished, err, _ := nodeExpander.expandOnPlugin() return resizeFinished, err @@ -2177,6 +2178,26 @@ func (og *operationGenerator) nodeExpandVolume( return true, nil } +func (og *operationGenerator) checkForRecoveryFromExpansion(pvc *v1.PersistentVolumeClaim, volumeToMount VolumeToMount) bool { + resizeStatus := pvc.Status.ResizeStatus + allocatedResource := pvc.Status.AllocatedResources + featureGateStatus := utilfeature.DefaultFeatureGate.Enabled(features.RecoverVolumeExpansionFailure) + + if !featureGateStatus { + return false + } + + // Even though RecoverVolumeExpansionFailure feature gate is enabled, it appears that we are running with older version + // of resize controller, which will not populate allocatedResource and resizeStatus. This can happen because of version skew + // and hence we are going to keep expanding using older logic. + if resizeStatus == nil && allocatedResource == nil { + _, detailedMsg := volumeToMount.GenerateMsg("MountVolume.NodeExpandVolume running with", "older external resize controller") + klog.Warningf(detailedMsg) + return false + } + return true +} + // legacyCallNodeExpandOnPlugin is old version of calling node expansion on plugin, which does not support // recovery from volume expansion failure // TODO: Removing this code when RecoverVolumeExpansionFailure feature goes GA.