@@ -31,20 +31,29 @@ import (
31
31
)
32
32
33
33
var (
34
- teardownCluster = flag . Bool ( "teardown- cluster" , true , "teardown the cluster after the e2e test" )
35
- teardownDriver = flag .Bool ("teardown-driver " , true , "teardown the driver after the e2e test" )
36
- bringupCluster = flag .Bool ("bringup-cluster " , true , "build kubernetes and bringup a cluster " )
37
- stagingImage = flag .String ( "staging-image " , "" , "name of image to stage to " )
38
- kubeVersion = flag .String ("kube-version " , "master " , "version of Kubernetes to download and use " )
39
- inProw = flag .Bool ( "run-in-prow " , false , "is the test running in PROW " )
40
- saFile = flag .String ("service-account-file " , "" , "path of service account file " )
41
- deployOverlayName = flag .String ("deploy-overlay-name " , "" , "which kustomize overlay to deploy the driver with " )
42
- localK8sDir = flag . String ( "local-k8s-dir" , "" , "local kubernetes/kubernetes directory to run e2e tests from" )
43
- doDriverBuild = flag . Bool ( "do-driver-build" , true , "building the driver from source" )
34
+ // Kubernetes cluster flags
35
+ teardownCluster = flag .Bool ("teardown-cluster " , true , "teardown the cluster after the e2e test" )
36
+ teardownDriver = flag .Bool ("teardown-driver " , true , "teardown the driver after the e2e test " )
37
+ bringupCluster = flag .Bool ( "bringup-cluster " , true , "build kubernetes and bringup a cluster " )
38
+ gceZone = flag .String ("gce-zone " , "" , "zone that the gce k8s cluster is created/found in " )
39
+ kubeVersion = flag .String ( "kube-version " , "master" , "version of Kubernetes to download and use " )
40
+ kubeFeatureGates = flag .String ("kube-feature-gates " , "" , "feature gates to set on new kubernetes cluster " )
41
+ localK8sDir = flag .String ("local-k8s-dir " , "" , "local kubernetes/kubernetes directory to run e2e tests from " )
42
+
43
+ // Test infrastructure flags
44
44
boskosResourceType = flag .String ("boskos-resource-type" , "gce-project" , "name of the boskos resource type to reserve" )
45
45
storageClassFile = flag .String ("storageclass-file" , "" , "name of storageclass yaml file to use for test relative to test/k8s-integration/config" )
46
- kubeFeatureGates = flag .String ("kube-feature-gates" , "" , "feature gates to set on new kubernetes cluster" )
47
- testFocus = flag .String ("test-focus" , "" , "test focus for Kubernetes e2e" )
46
+ inProw = flag .Bool ("run-in-prow" , false , "is the test running in PROW" )
47
+
48
+ // Driver flags
49
+ stagingImage = flag .String ("staging-image" , "" , "name of image to stage to" )
50
+ saFile = flag .String ("service-account-file" , "" , "path of service account file" )
51
+ deployOverlayName = flag .String ("deploy-overlay-name" , "" , "which kustomize overlay to deploy the driver with" )
52
+ doDriverBuild = flag .Bool ("do-driver-build" , true , "building the driver from source" )
53
+
54
+ // Test flags
55
+ migrationTest = flag .Bool ("migration-test" , false , "sets the flag on the e2e binary signalling migration" )
56
+ testFocus = flag .String ("test-focus" , "" , "test focus for Kubernetes e2e" )
48
57
)
49
58
50
59
const (
@@ -70,8 +79,12 @@ func main() {
70
79
glog .Fatalf ("deploy-overlay-name is a required flag" )
71
80
}
72
81
73
- if len (* storageClassFile ) == 0 {
74
- glog .Fatalf ("storageclass-file is a required flag" )
82
+ if len (* storageClassFile ) == 0 && ! * migrationTest {
83
+ glog .Fatalf ("One of storageclass-file and migration-test must be set" )
84
+ }
85
+
86
+ if len (* storageClassFile ) != 0 && * migrationTest {
87
+ glog .Fatalf ("storage-class-file and migration-test cannot both be set" )
75
88
}
76
89
77
90
if ! * bringupCluster && len (* kubeFeatureGates ) > 0 {
@@ -82,6 +95,10 @@ func main() {
82
95
glog .Fatalf ("test-focus is a required flag" )
83
96
}
84
97
98
+ if len (* gceZone ) == 0 {
99
+ glog .Fatalf ("gce-zone is a required flag" )
100
+ }
101
+
85
102
err := handle ()
86
103
if err != nil {
87
104
glog .Fatalf ("Failed to run integration test: %v" , err )
@@ -179,7 +196,7 @@ func handle() error {
179
196
glog .V (4 ).Infof ("Set Kubernetes feature gates: %v" , * kubeFeatureGates )
180
197
}
181
198
182
- err = clusterUp (k8sDir )
199
+ err = clusterUp (k8sDir , * gceZone )
183
200
if err != nil {
184
201
return fmt .Errorf ("failed to cluster up: %v" , err )
185
202
}
@@ -210,7 +227,15 @@ func handle() error {
210
227
if len (* localK8sDir ) != 0 {
211
228
k8sDir = * localK8sDir
212
229
}
213
- err = runTests (pkgDir , k8sDir , * storageClassFile , * testFocus )
230
+
231
+ if len (* storageClassFile ) != 0 {
232
+ err = runCSITests (pkgDir , k8sDir , * testFocus , * storageClassFile , * gceZone )
233
+ } else if * migrationTest {
234
+ err = runMigrationTests (pkgDir , k8sDir , * testFocus , * gceZone )
235
+ } else {
236
+ return fmt .Errorf ("Did not run either CSI or Migration test" )
237
+ }
238
+
214
239
if err != nil {
215
240
return fmt .Errorf ("failed to run tests: %v" , err )
216
241
}
@@ -231,13 +256,21 @@ func setEnvProject(project string) error {
231
256
return nil
232
257
}
233
258
234
- func runTests (pkgDir , k8sDir , storageClassFile , testFocus string ) error {
259
+ func runMigrationTests (pkgDir , k8sDir , testFocus , gceZone string ) error {
260
+ return runTestsWithConfig (pkgDir , k8sDir , gceZone , testFocus , "-storage.migratedPlugins=kubernetes.io/gce-pd" )
261
+ }
262
+
263
+ func runCSITests (pkgDir , k8sDir , testFocus , storageClassFile , gceZone string ) error {
235
264
testDriverConfigFile , err := generateDriverConfigFile (pkgDir , storageClassFile )
236
265
if err != nil {
237
266
return err
238
267
}
268
+ testConfigArg := fmt .Sprintf ("-storage.testdriver=%s" , testDriverConfigFile )
269
+ return runTestsWithConfig (pkgDir , k8sDir , gceZone , testFocus , testConfigArg )
270
+ }
239
271
240
- err = os .Chdir (k8sDir )
272
+ func runTestsWithConfig (pkgDir , k8sDir , gceZone , testFocus , testConfigArg string ) error {
273
+ err := os .Chdir (k8sDir )
241
274
if err != nil {
242
275
return err
243
276
}
@@ -248,7 +281,6 @@ func runTests(pkgDir, k8sDir, storageClassFile, testFocus string) error {
248
281
artifactsDir , _ := os .LookupEnv ("ARTIFACTS" )
249
282
reportArg := fmt .Sprintf ("-report-dir=%s" , artifactsDir )
250
283
251
- driverConfigArg := fmt .Sprintf ("-storage.testdriver=%s" , testDriverConfigFile )
252
284
testFocusArg := fmt .Sprintf ("-focus=%s" , testFocus )
253
285
254
286
cmd := exec .Command (filepath .Join (k8sBuildBinDir , "ginkgo" ),
@@ -258,7 +290,9 @@ func runTests(pkgDir, k8sDir, storageClassFile, testFocus string) error {
258
290
filepath .Join (k8sBuildBinDir , "e2e.test" ),
259
291
"--" ,
260
292
reportArg ,
261
- driverConfigArg )
293
+ "-provider=gce" ,
294
+ fmt .Sprintf ("-gce-zone=%s" , gceZone ),
295
+ testConfigArg )
262
296
263
297
err = runCommand ("Running Tests" , cmd )
264
298
if err != nil {
@@ -306,9 +340,13 @@ func buildKubernetes(k8sDir string) error {
306
340
return nil
307
341
}
308
342
309
- func clusterUp (k8sDir string ) error {
343
+ func clusterUp (k8sDir , gceZone string ) error {
344
+ err := os .Setenv ("KUBE_GCE_ZONE" , gceZone )
345
+ if err != nil {
346
+ return err
347
+ }
310
348
cmd := exec .Command (filepath .Join (k8sDir , "hack" , "e2e-internal" , "e2e-up.sh" ))
311
- err : = runCommand ("Starting E2E Cluster" , cmd )
349
+ err = runCommand ("Starting E2E Cluster" , cmd )
312
350
if err != nil {
313
351
return fmt .Errorf ("failed to bring up kubernetes e2e cluster: %v" , err )
314
352
}
0 commit comments