@@ -42,11 +42,11 @@ const (
42
42
43
43
var _ = utils .SIGDescribe ("Volume expand" , func () {
44
44
var (
45
- c clientset.Interface
46
- ns string
47
- err error
48
- pvc * v1.PersistentVolumeClaim
49
- resizableSc * storage.StorageClass
45
+ c clientset.Interface
46
+ ns string
47
+ err error
48
+ pvc * v1.PersistentVolumeClaim
49
+ storageClassVar * storage.StorageClass
50
50
)
51
51
52
52
f := framework .NewDefaultFramework ("volume-expand" )
@@ -55,61 +55,58 @@ var _ = utils.SIGDescribe("Volume expand", func() {
55
55
c = f .ClientSet
56
56
ns = f .Namespace .Name
57
57
framework .ExpectNoError (framework .WaitForAllNodesSchedulable (c , framework .TestContext .NodeSchedulableTimeout ))
58
+ })
59
+
60
+ setupFunc := func (allowExpansion bool , blockVolume bool ) (* v1.PersistentVolumeClaim , * storage.StorageClass , error ) {
58
61
test := testsuites.StorageClassTest {
59
- Name : "default" ,
60
- ClaimSize : "2Gi" ,
61
- AllowVolumeExpansion : true ,
62
+ Name : "default" ,
63
+ ClaimSize : "2Gi" ,
62
64
}
63
- resizableSc , err = createStorageClass (test , ns , "resizing" , c )
64
- framework .ExpectNoError (err , "Error creating resizable storage class" )
65
- Expect (resizableSc .AllowVolumeExpansion ).NotTo (BeNil ())
66
- Expect (* resizableSc .AllowVolumeExpansion ).To (BeTrue ())
67
-
68
- pvc = newClaim (test , ns , "default" )
69
- pvc .Spec .StorageClassName = & resizableSc .Name
70
- pvc , err = c .CoreV1 ().PersistentVolumeClaims (pvc .Namespace ).Create (pvc )
71
- framework .ExpectNoError (err , "Error creating pvc" )
72
- })
65
+ if allowExpansion {
66
+ test .AllowVolumeExpansion = true
67
+ }
68
+ if blockVolume {
69
+ test .VolumeMode = v1 .PersistentVolumeBlock
70
+ }
71
+
72
+ sc , err := createStorageClass (test , ns , "resizing" , c )
73
+ framework .ExpectNoError (err , "Error creating storage class for resizing" )
74
+
75
+ tPVC := newClaim (test , ns , "default" )
76
+ tPVC .Spec .StorageClassName = & sc .Name
77
+ tPVC , err = c .CoreV1 ().PersistentVolumeClaims (tPVC .Namespace ).Create (tPVC )
78
+ if err != nil {
79
+ return nil , sc , err
80
+ }
81
+ return tPVC , sc , nil
82
+ }
73
83
74
84
AfterEach (func () {
75
85
framework .ExpectNoError (framework .DeletePersistentVolumeClaim (c , pvc .Name , pvc .Namespace ))
76
- framework .ExpectNoError (c .StorageV1 ().StorageClasses ().Delete (resizableSc .Name , nil ))
86
+ framework .ExpectNoError (c .StorageV1 ().StorageClasses ().Delete (storageClassVar .Name , nil ))
77
87
})
78
88
79
89
It ("should not allow expansion of pvcs without AllowVolumeExpansion property" , func () {
80
- test := testsuites.StorageClassTest {
81
- Name : "no-expansion" ,
82
- ClaimSize : "2Gi" ,
83
- }
84
- regularSC , err := createStorageClass (test , ns , "noexpand" , c )
85
- framework .ExpectNoError (err , "Error creating non-expandable storage class" )
90
+ pvc , storageClassVar , err = setupFunc (false /* allowExpansion */ , false /*BlockVolume*/ )
91
+ framework .ExpectNoError (err , "Error creating non-expandable PVC" )
86
92
87
- defer func () {
88
- framework .ExpectNoError (c .StorageV1 ().StorageClasses ().Delete (regularSC .Name , nil ))
89
- }()
90
- Expect (regularSC .AllowVolumeExpansion ).To (BeNil ())
93
+ Expect (storageClassVar .AllowVolumeExpansion ).To (BeNil ())
91
94
92
- noExpandPVC := newClaim (test , ns , "noexpand" )
93
- noExpandPVC .Spec .StorageClassName = & regularSC .Name
94
- noExpandPVC , err = c .CoreV1 ().PersistentVolumeClaims (noExpandPVC .Namespace ).Create (noExpandPVC )
95
- framework .ExpectNoError (err , "Error creating pvc" )
96
-
97
- defer func () {
98
- framework .ExpectNoError (framework .DeletePersistentVolumeClaim (c , noExpandPVC .Name , noExpandPVC .Namespace ))
99
- }()
100
-
101
- pvcClaims := []* v1.PersistentVolumeClaim {noExpandPVC }
95
+ pvcClaims := []* v1.PersistentVolumeClaim {pvc }
102
96
pvs , err := framework .WaitForPVClaimBoundPhase (c , pvcClaims , framework .ClaimProvisionTimeout )
103
97
framework .ExpectNoError (err , "Failed waiting for PVC to be bound %v" , err )
104
98
Expect (len (pvs )).To (Equal (1 ))
105
99
106
100
By ("Expanding non-expandable pvc" )
107
101
newSize := resource .MustParse ("6Gi" )
108
- noExpandPVC , err = expandPVCSize (noExpandPVC , newSize , c )
102
+ pvc , err = expandPVCSize (pvc , newSize , c )
109
103
Expect (err ).To (HaveOccurred (), "While updating non-expandable PVC" )
110
104
})
111
105
112
106
It ("Verify if editing PVC allows resize" , func () {
107
+ pvc , storageClassVar , err = setupFunc (true /* allowExpansion */ , false /*BlockVolume*/ )
108
+ framework .ExpectNoError (err , "Error creating non-expandable PVC" )
109
+
113
110
By ("Waiting for pvc to be in bound phase" )
114
111
pvcClaims := []* v1.PersistentVolumeClaim {pvc }
115
112
pvs , err := framework .WaitForPVClaimBoundPhase (c , pvcClaims , framework .ClaimProvisionTimeout )
@@ -166,6 +163,38 @@ var _ = utils.SIGDescribe("Volume expand", func() {
166
163
pvcConditions := pvc .Status .Conditions
167
164
Expect (len (pvcConditions )).To (Equal (0 ), "pvc should not have conditions" )
168
165
})
166
+
167
+ It ("should allow expansion of block volumes" , func () {
168
+ pvc , storageClassVar , err = setupFunc (true /*allowExpansion*/ , true /*blockVolume*/ )
169
+
170
+ By ("Waiting for pvc to be in bound phase" )
171
+ pvcClaims := []* v1.PersistentVolumeClaim {pvc }
172
+ pvs , err := framework .WaitForPVClaimBoundPhase (c , pvcClaims , framework .ClaimProvisionTimeout )
173
+ framework .ExpectNoError (err , "Failed waiting for PVC to be bound %v" , err )
174
+ Expect (len (pvs )).To (Equal (1 ))
175
+
176
+ By ("Expanding current pvc" )
177
+ newSize := resource .MustParse ("6Gi" )
178
+ pvc , err = expandPVCSize (pvc , newSize , c )
179
+ framework .ExpectNoError (err , "While updating pvc for more size" )
180
+ Expect (pvc ).NotTo (BeNil ())
181
+
182
+ pvcSize := pvc .Spec .Resources .Requests [v1 .ResourceStorage ]
183
+ if pvcSize .Cmp (newSize ) != 0 {
184
+ framework .Failf ("error updating pvc size %q" , pvc .Name )
185
+ }
186
+
187
+ By ("Waiting for cloudprovider resize to finish" )
188
+ err = waitForControllerVolumeResize (pvc , c , totalResizeWaitPeriod )
189
+ framework .ExpectNoError (err , "While waiting for pvc resize to finish" )
190
+
191
+ By ("Waiting for file system resize to finish" )
192
+ pvc , err = waitForFSResize (pvc , c )
193
+ framework .ExpectNoError (err , "while waiting for fs resize to finish" )
194
+
195
+ pvcConditions := pvc .Status .Conditions
196
+ Expect (len (pvcConditions )).To (Equal (0 ), "pvc should not have conditions" )
197
+ })
169
198
})
170
199
171
200
func createStorageClass (t testsuites.StorageClassTest , ns string , suffix string , c clientset.Interface ) (* storage.StorageClass , error ) {
0 commit comments