Skip to content

Commit c6de4ce

Browse files
committed
Add tests for node-expansion-not-required annotation
1 parent ec9e3b4 commit c6de4ce

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

pkg/controller/expand_and_recover_test.go

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import (
99
"github.com/kubernetes-csi/external-resizer/pkg/features"
1010
"github.com/kubernetes-csi/external-resizer/pkg/resizer"
1111
"github.com/kubernetes-csi/external-resizer/pkg/testutil"
12+
"github.com/kubernetes-csi/external-resizer/pkg/util"
1213
"google.golang.org/grpc/codes"
1314
"google.golang.org/grpc/status"
1415
v1 "k8s.io/api/core/v1"
1516
"k8s.io/apimachinery/pkg/api/resource"
17+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1618
"k8s.io/apimachinery/pkg/runtime"
1719
"k8s.io/apimachinery/pkg/util/sets"
1820
utilfeature "k8s.io/apiserver/pkg/util/feature"
@@ -29,21 +31,24 @@ func TestExpandAndRecover(t *testing.T) {
2931
pv *v1.PersistentVolume
3032
disableNodeExpansion bool
3133
disableControllerExpansion bool
34+
3235
// expectations of test
33-
expectedResizeStatus v1.ClaimResourceStatus
34-
expectedAllocatedSize resource.Quantity
35-
pvcWithFinalErrors sets.Set[string]
36-
expansionError error
37-
expectResizeCall bool
38-
expectedConditions []v1.PersistentVolumeClaimConditionType
36+
expectedResizeStatus v1.ClaimResourceStatus
37+
expectedAllocatedSize resource.Quantity
38+
expectNodeExpansionNotRequiredAnnotation bool
39+
pvcWithFinalErrors sets.Set[string]
40+
expansionError error
41+
expectResizeCall bool
42+
expectedConditions []v1.PersistentVolumeClaimConditionType
3943
}{
4044
{
41-
name: "pvc.spec.size > pv.spec.size, resize_status=node_expansion_inprogress",
42-
pvc: testutil.GetTestPVC("test-vol0", "2G", "1G", "", ""),
43-
pv: createPV(1, "claim01", defaultNS, "test-uid", &fsVolumeMode),
44-
expectedResizeStatus: v1.PersistentVolumeClaimNodeResizePending,
45-
expectedAllocatedSize: resource.MustParse("2G"),
46-
expectResizeCall: true,
45+
name: "pvc.spec.size > pv.spec.size, resize_status=node_expansion_inprogress",
46+
pvc: testutil.GetTestPVC("test-vol0", "2G", "1G", "", ""),
47+
pv: createPV(1, "claim01", defaultNS, "test-uid", &fsVolumeMode),
48+
expectedResizeStatus: v1.PersistentVolumeClaimNodeResizePending,
49+
expectNodeExpansionNotRequiredAnnotation: false,
50+
expectedAllocatedSize: resource.MustParse("2G"),
51+
expectResizeCall: true,
4752
},
4853
{
4954
name: "pvc.spec.size = pv.spec.size, resize_status=no_expansion_inprogress",
@@ -116,13 +121,14 @@ func TestExpandAndRecover(t *testing.T) {
116121
expectResizeCall: false,
117122
},
118123
{
119-
name: "pvc.spec.size > pv.spec.size, disable_node_expansion=true, resize_status=no_expansion_inprogress",
120-
pvc: testutil.GetTestPVC("test-vol0", "2G", "1G", "", ""),
121-
pv: createPV(1, "claim01", defaultNS, "test-uid", &fsVolumeMode),
122-
disableNodeExpansion: true,
123-
expectedResizeStatus: "",
124-
expectedAllocatedSize: resource.MustParse("2G"),
125-
expectResizeCall: true,
124+
name: "pvc.spec.size > pv.spec.size, disable_node_expansion=true, resize_status=no_expansion_inprogress",
125+
pvc: testutil.GetTestPVC("test-vol0", "2G", "1G", "", ""),
126+
pv: createPV(1, "claim01", defaultNS, "test-uid", &fsVolumeMode),
127+
disableNodeExpansion: true,
128+
expectedResizeStatus: "",
129+
expectNodeExpansionNotRequiredAnnotation: true,
130+
expectedAllocatedSize: resource.MustParse("2G"),
131+
expectResizeCall: true,
126132
},
127133
{
128134
name: "pv.spec.size >= pvc.spec.size, resize_status=node_expansion_failed",
@@ -193,6 +199,10 @@ func TestExpandAndRecover(t *testing.T) {
193199
t.Fatalf("expected resize status to be %s, got %s", test.expectedResizeStatus, actualResizeStatus)
194200
}
195201

202+
if test.expectNodeExpansionNotRequiredAnnotation != metav1.HasAnnotation(pvc.ObjectMeta, util.NodeExpansionNotRequired) {
203+
t.Fatalf("expected node expansion not required annotation to be %t, got %t", test.expectNodeExpansionNotRequiredAnnotation, metav1.HasAnnotation(pvc.ObjectMeta, util.NodeExpansionNotRequired))
204+
}
205+
196206
actualAllocatedSize := pvc.Status.AllocatedResources.Storage()
197207

198208
if test.expectedAllocatedSize.Cmp(*actualAllocatedSize) != 0 {

pkg/controller/resize_status.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ func (ctrl *resizeController) markOverallExpansionAsFinished(
178178
newPVC.Status.AllocatedResourceStatuses = resourceStatusMap
179179
}
180180

181+
// this will ensure that kubelet does not try to resize volume again
181182
newPVC = ctrl.addNodeExpansionNotRequiredAnnotation(newPVC)
182183

183184
updatedPVC, err := util.PatchClaim(ctrl.kubeClient, pvc, newPVC, true /* addResourceVersionCheck */)

0 commit comments

Comments
 (0)