36
36
teardownCluster = flag .Bool ("teardown-cluster" , true , "teardown the cluster after the e2e test" )
37
37
teardownDriver = flag .Bool ("teardown-driver" , true , "teardown the driver after the e2e test" )
38
38
bringupCluster = flag .Bool ("bringup-cluster" , true , "build kubernetes and bringup a cluster" )
39
- platform = flag .String ("platform" , "linux" , "platform that the tests will be run, either linux or windows" )
39
+ platform = flag .String ("platform" , "linux" , "platform that the tests will be run on, either linux or windows" )
40
+ arch = flag .String ("arch" , "amd64" , "architecture that the tests will be run on (eg: amd64/arm64)" )
40
41
gceZone = flag .String ("gce-zone" , "" , "zone that the gce k8s cluster is created/found in" )
41
42
gceRegion = flag .String ("gce-region" , "" , "region that gke regional cluster should be created in" )
42
43
kubeVersion = flag .String ("kube-version" , "" , "version of Kubernetes to download and use for the cluster" )
65
66
saFile = flag .String ("service-account-file" , "" , "path of service account file" )
66
67
deployOverlayName = flag .String ("deploy-overlay-name" , "" , "which kustomize overlay to deploy the driver with" )
67
68
doDriverBuild = flag .Bool ("do-driver-build" , true , "building the driver from source" )
69
+ doK8sBuild = flag .Bool ("do-k8s-build" , true , "building the driver from source. If false, will fetch precompiled artifacts" )
68
70
useGKEManagedDriver = flag .Bool ("use-gke-managed-driver" , false , "use GKE managed PD CSI driver for the tests" )
69
71
70
72
// Test flags
@@ -191,12 +193,32 @@ func main() {
191
193
klog .Fatalf ("num-windows-nodes must be set if the platform is windows" )
192
194
}
193
195
196
+ if * kubeVersion == "master" && ! * doK8sBuild {
197
+ klog .Fatalf ("must set do-k8s-build=true when kubeVersion=%s" , kubeVersion )
198
+ }
199
+
194
200
err := handle ()
195
201
if err != nil {
196
202
klog .Fatalf ("Failed to run integration test: %w" , err )
197
203
}
198
204
}
199
205
206
+ func buildTestingBinaries (k8sDir string ) error {
207
+ if err := buildKubernetes (k8sDir , "WHAT=test/e2e/e2e.test" ); err != nil {
208
+ return fmt .Errorf ("failed to build Kubernetes e2e: %v" , err .Error ())
209
+ }
210
+
211
+ // kubetest relies on ginkgo and kubectl already built in the test k8s directory
212
+ if err := buildKubernetes (k8sDir , "ginkgo" ); err != nil {
213
+ return fmt .Errorf ("failed to build gingko: %v" , err .Error ())
214
+ }
215
+
216
+ if err := buildKubernetes (k8sDir , "kubectl" ); err != nil {
217
+ return fmt .Errorf ("failed to build kubectl: %v" , err .Error ())
218
+ }
219
+ return nil
220
+ }
221
+
200
222
func handle () error {
201
223
oldmask := syscall .Umask (0000 )
202
224
defer syscall .Umask (oldmask )
@@ -266,21 +288,32 @@ func handle() error {
266
288
}()
267
289
}
268
290
269
- // Create temporary directories for kubernetes builds
291
+ // Create temporary directories for kubernetes source/build artifacts
270
292
testParams .testParentDir = generateUniqueTmpDir ()
271
293
defer removeDir (testParams .testParentDir )
272
294
273
295
// If kube version is set, then download and build Kubernetes for cluster creation
274
296
// Otherwise, either GKE or a prebuild local K8s dir is being used
275
297
if len (* kubeVersion ) != 0 {
276
298
testParams .k8sSourceDir = filepath .Join (testParams .testParentDir , "kubernetes" )
277
- err := downloadKubernetesSource ( testParams . pkgDir , testParams . testParentDir , * kubeVersion )
278
- if err != nil {
299
+ klog . Infof ( "Downloading Kubernetes source from: %s" , * kubeVersion )
300
+ if err := downloadKubernetesSource ( testParams . k8sSourceDir , * kubeVersion ); err != nil {
279
301
return fmt .Errorf ("failed to download Kubernetes source: %v" , err .Error ())
280
302
}
281
- err = buildKubernetes (testParams .k8sSourceDir , "quick-release" )
282
- if err != nil {
283
- return fmt .Errorf ("failed to build Kubernetes: %v" , err .Error ())
303
+
304
+ if * doK8sBuild {
305
+ klog .Info ("Building Kubernetes source" )
306
+ if err := buildKubernetes (testParams .k8sSourceDir , "quick-release" ); err != nil {
307
+ return fmt .Errorf ("failed to build Kubernetes: %v" , err .Error ())
308
+ }
309
+ } else {
310
+ klog .Info ("Fetching precompiled Kubernetes artifacts for %s/%s" , * platform , * arch )
311
+ if err := downloadKubernetesRelease (testParams .k8sSourceDir , * kubeVersion , * platform , * arch ); err != nil {
312
+ return fmt .Errorf ("failed to download Kubernetes release: %v" , err .Error ())
313
+ }
314
+ if err := buildTestingBinaries (testParams .k8sSourceDir ); err != nil {
315
+ return err
316
+ }
284
317
}
285
318
} else {
286
319
testParams .k8sSourceDir = * localK8sDir
@@ -290,22 +323,13 @@ func handle() error {
290
323
// Otherwise, either kube version is set (which implies GCE) or a local K8s dir is being used.
291
324
if ! * useKubeTest2 && len (* testVersion ) != 0 && * testVersion != * kubeVersion {
292
325
testParams .k8sSourceDir = filepath .Join (testParams .testParentDir , "kubernetes" )
293
- err := downloadKubernetesSource ( testParams . pkgDir , testParams . testParentDir , * testVersion )
294
- if err != nil {
326
+ // Overlay the Kubernetes source
327
+ if err := downloadKubernetesSource ( testParams . k8sSourceDir , * testVersion ); err != nil {
295
328
return fmt .Errorf ("failed to download Kubernetes source: %v" , err .Error ())
296
329
}
297
- err = buildKubernetes (testParams .k8sSourceDir , "WHAT=test/e2e/e2e.test" )
298
- if err != nil {
299
- return fmt .Errorf ("failed to build Kubernetes e2e: %v" , err .Error ())
300
- }
301
- // kubetest relies on ginkgo and kubectl already built in the test k8s directory
302
- err = buildKubernetes (testParams .k8sSourceDir , "ginkgo" )
303
- if err != nil {
304
- return fmt .Errorf ("failed to build gingko: %v" , err .Error ())
305
- }
306
- err = buildKubernetes (testParams .k8sSourceDir , "kubectl" )
307
- if err != nil {
308
- return fmt .Errorf ("failed to build kubectl: %v" , err .Error ())
330
+ klog .Infof ("Building Kubernetes Testing binaries: %s" , * kubeVersion )
331
+ if err := buildTestingBinaries (testParams .k8sSourceDir ); err != nil {
332
+ return err
309
333
}
310
334
}
311
335
0 commit comments