Skip to content

Commit ec9e3b4

Browse files
committed
Disable node expansion on a node if not required
1 parent ec950c1 commit ec9e3b4

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

pkg/controller/expand_and_recover.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/kubernetes-csi/external-resizer/pkg/util"
2323
v1 "k8s.io/api/core/v1"
2424
"k8s.io/apimachinery/pkg/api/resource"
25+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2526
"k8s.io/klog/v2"
2627
)
2728

@@ -196,6 +197,27 @@ func (ctrl *resizeController) expandAndRecover(pvc *v1.PersistentVolumeClaim, pv
196197
return pvc, pv, nil, true
197198
}
198199

200+
func (ctrl *resizeController) removeNodeExpansionNotRequiredAnnotation(pvc *v1.PersistentVolumeClaim) *v1.PersistentVolumeClaim {
201+
if !metav1.HasAnnotation(pvc.ObjectMeta, util.NodeExpansionNotRequired) {
202+
return pvc
203+
}
204+
205+
delete(pvc.Annotations, util.NodeExpansionNotRequired)
206+
return pvc
207+
}
208+
209+
func (ctrl *resizeController) addNodeExpansionNotRequiredAnnotation(pvc *v1.PersistentVolumeClaim) *v1.PersistentVolumeClaim {
210+
if metav1.HasAnnotation(pvc.ObjectMeta, util.NodeExpansionNotRequired) {
211+
return pvc
212+
}
213+
214+
if pvc.Annotations == nil {
215+
pvc.Annotations = make(map[string]string)
216+
}
217+
pvc.Annotations[util.NodeExpansionNotRequired] = "true"
218+
return pvc
219+
}
220+
199221
func (ctrl *resizeController) markForSlowRetry(pvcKey string, resizeStatus v1.ClaimResourceStatus) {
200222
if resizeStatus == v1.PersistentVolumeClaimControllerResizeInfeasible {
201223
ctrl.slowSet.Add(pvcKey)

pkg/controller/resize_status.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ func (ctrl *resizeController) markControllerResizeInProgress(
4747
newPVC.Status.Conditions = util.MergeResizeConditionsOfPVC(newPVC.Status.Conditions, conditions, true /*keepOldResizeConditions*/)
4848
}
4949

50+
newPVC = ctrl.removeNodeExpansionNotRequiredAnnotation(newPVC)
51+
5052
if updateStatus {
5153
newPVC = mergeStorageResourceStatus(newPVC, v1.PersistentVolumeClaimControllerResizeInProgress)
5254
}
@@ -78,6 +80,9 @@ func (ctrl *resizeController) markForPendingNodeExpansion(pvc *v1.PersistentVolu
7880
newPVC.Status.Conditions = util.MergeResizeConditionsOfPVC(newPVC.Status.Conditions,
7981
[]v1.PersistentVolumeClaimCondition{pvcCondition}, true /*keepOldResizeConditions*/)
8082

83+
// make sure if any annotation was previously added is removed here
84+
newPVC = ctrl.removeNodeExpansionNotRequiredAnnotation(newPVC)
85+
8186
newPVC = mergeStorageResourceStatus(newPVC, v1.PersistentVolumeClaimNodeResizePending)
8287
updatedPVC, err := util.PatchClaim(ctrl.kubeClient, pvc, newPVC, true /* addResourceVersionCheck */)
8388

@@ -173,6 +178,8 @@ func (ctrl *resizeController) markOverallExpansionAsFinished(
173178
newPVC.Status.AllocatedResourceStatuses = resourceStatusMap
174179
}
175180

181+
newPVC = ctrl.addNodeExpansionNotRequiredAnnotation(newPVC)
182+
176183
updatedPVC, err := util.PatchClaim(ctrl.kubeClient, pvc, newPVC, true /* addResourceVersionCheck */)
177184
if err != nil {
178185
return pvc, fmt.Errorf("mark PVC %q as resize finished failed: %v", klog.KObj(pvc), err)

pkg/util/util.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ var (
5353
// Its value will be set by the external-resizer when it deems that filesystem resize is required after resizing volume.
5454
// Its value will be used by pv_controller to determine pvc's status capacity when binding pvc and pv.
5555
AnnPreResizeCapacity = "volume.alpha.kubernetes.io/pre-resize-capacity"
56+
57+
NodeExpansionNotRequired = "volume.kubernetes.io/node-expansion-not-required"
5658
)
5759

5860
// MergeResizeConditionsOfPVC updates pvc with requested resize conditions

0 commit comments

Comments
 (0)