@@ -13,6 +13,7 @@ import (
13
13
"k8s.io/apimachinery/pkg/api/resource"
14
14
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
15
"k8s.io/apimachinery/pkg/runtime"
16
+ "k8s.io/apimachinery/pkg/types"
16
17
"k8s.io/client-go/informers"
17
18
"k8s.io/client-go/kubernetes"
18
19
"k8s.io/client-go/kubernetes/fake"
@@ -26,43 +27,62 @@ func TestController(t *testing.T) {
26
27
27
28
CreateObjects bool
28
29
NodeResize bool
30
+ CallCSIExpand bool
29
31
}{
30
32
{
31
- Name : "Invalid key" ,
32
- PVC : invalidPVC (),
33
+ Name : "Invalid key" ,
34
+ PVC : invalidPVC (),
35
+ CallCSIExpand : false ,
33
36
},
34
37
{
35
- Name : "PVC not found" ,
36
- PVC : createPVC (1 , 1 ),
38
+ Name : "PVC not found" ,
39
+ PVC : createPVC (1 , 1 ),
40
+ CallCSIExpand : false ,
37
41
},
38
42
{
39
43
Name : "PVC doesn't need resize" ,
40
44
PVC : createPVC (1 , 1 ),
41
45
CreateObjects : true ,
46
+ CallCSIExpand : false ,
42
47
},
43
48
{
44
49
Name : "PV not found" ,
45
50
PVC : createPVC (2 , 1 ),
46
51
CreateObjects : true ,
52
+ CallCSIExpand : false ,
47
53
},
48
54
{
49
- Name : "PV doesn't need resize " ,
55
+ Name : "pv claimref does not have pvc UID " ,
50
56
PVC : createPVC (2 , 1 ),
51
- PV : createPV (2 ),
52
- CreateObjects : true ,
57
+ PV : createPV (1 , "testPVC" /*pvcName*/ , "test" /*pvcNamespace*/ , "foobaz" /*pvcUID*/ ),
58
+ CallCSIExpand : false ,
59
+ },
60
+ {
61
+ Name : "pv claimref does not have PVC namespace" ,
62
+ PVC : createPVC (2 , 1 ),
63
+ PV : createPV (1 , "testPVC" /*pvcName*/ , "test1" /*pvcNamespace*/ , "foobar" /*pvcUID*/ ),
64
+ CallCSIExpand : false ,
65
+ },
66
+ {
67
+ Name : "pv claimref is nil" ,
68
+ PVC : createPVC (2 , 1 ),
69
+ PV : createPV (1 , "" /*pvcName*/ , "test1" /*pvcNamespace*/ , "foobar" /*pvcUID*/ ),
70
+ CallCSIExpand : false ,
53
71
},
54
72
{
55
73
Name : "Resize PVC, no FS resize" ,
56
74
PVC : createPVC (2 , 1 ),
57
- PV : createPV (1 ),
75
+ PV : createPV (1 , "testPVC" , "test" , "foobar" ),
58
76
CreateObjects : true ,
77
+ CallCSIExpand : true ,
59
78
},
60
79
{
61
80
Name : "Resize PVC with FS resize" ,
62
81
PVC : createPVC (2 , 1 ),
63
- PV : createPV (1 ),
82
+ PV : createPV (1 , "testPVC" , "test" , "foobar" ),
64
83
CreateObjects : true ,
65
84
NodeResize : true ,
85
+ CallCSIExpand : true ,
66
86
},
67
87
} {
68
88
client := csi .NewMockClient ("mock" , test .NodeResize , true , true )
@@ -104,6 +124,15 @@ func TestController(t *testing.T) {
104
124
if err != nil {
105
125
t .Fatalf ("Test %s: Unexpected error: %v" , test .Name , err )
106
126
}
127
+
128
+ expandCallCount := client .GetExpandCount ()
129
+ if test .CallCSIExpand && expandCallCount == 0 {
130
+ t .Fatalf ("for %s: expected csi expand call, no csi expand call was made" , test .Name )
131
+ }
132
+
133
+ if ! test .CallCSIExpand && expandCallCount > 0 {
134
+ t .Fatalf ("for %s: expected no csi expand call, received csi expansion request" , test .Name )
135
+ }
107
136
}
108
137
}
109
138
@@ -128,6 +157,7 @@ func createPVC(requestGB, capacityGB int) *v1.PersistentVolumeClaim {
128
157
ObjectMeta : metav1.ObjectMeta {
129
158
Name : "testPVC" ,
130
159
Namespace : "test" ,
160
+ UID : "foobar" ,
131
161
},
132
162
Spec : v1.PersistentVolumeClaimSpec {
133
163
Resources : v1.ResourceRequirements {
@@ -146,10 +176,10 @@ func createPVC(requestGB, capacityGB int) *v1.PersistentVolumeClaim {
146
176
}
147
177
}
148
178
149
- func createPV (capacityGB int ) * v1.PersistentVolume {
179
+ func createPV (capacityGB int , pvcName , pvcNamespace string , pvcUID types. UID ) * v1.PersistentVolume {
150
180
capacity := quantityGB (capacityGB )
151
181
152
- return & v1.PersistentVolume {
182
+ pv := & v1.PersistentVolume {
153
183
ObjectMeta : metav1.ObjectMeta {
154
184
Name : "testPV" ,
155
185
},
@@ -165,6 +195,14 @@ func createPV(capacityGB int) *v1.PersistentVolume {
165
195
},
166
196
},
167
197
}
198
+ if len (pvcName ) > 0 {
199
+ pv .Spec .ClaimRef = & v1.ObjectReference {
200
+ Namespace : pvcNamespace ,
201
+ Name : pvcName ,
202
+ UID : pvcUID ,
203
+ }
204
+ }
205
+ return pv
168
206
}
169
207
170
208
func fakeK8s (objs []runtime.Object ) (kubernetes.Interface , informers.SharedInformerFactory ) {
0 commit comments