Skip to content

Commit 45a89c4

Browse files
author
Hantao (Will) Wang
committed
add functionality to use gke with kubetest
1 parent 168218c commit 45a89c4

File tree

2 files changed

+62
-12
lines changed

2 files changed

+62
-12
lines changed

test/k8s-integration/cluster.go

+37
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,40 @@ func downloadKubernetesSource(pkgDir, k8sIoDir, kubeVersion string) error {
155155

156156
return nil
157157
}
158+
159+
func getGKEKubeTestArgs() ([]string, error) {
160+
var gkeEnv string
161+
switch gkeURL := os.Getenv("CLOUDSDK_API_ENDPOINT_OVERRIDES_CONTAINER"); gkeURL {
162+
case "https://staging-container.sandbox.googleapis.com/":
163+
gkeEnd = "staging"
164+
case "https://test-container.sandbox.googleapis.com/":
165+
gkeEnv = "test"
166+
case "":
167+
gkeEnv = "prod"
168+
default:
169+
gkeEnv = gkeURL
170+
}
171+
172+
cmd := exec.Command("gcloud", "config", "get-value", "project")
173+
project, err := cmd.Output()
174+
if err != nil {
175+
return nil, fmt.Errorf("failed to get current project: %v", err)
176+
}
177+
178+
args := []string{
179+
"--up=false",
180+
"--down=false",
181+
"--provider=gke",
182+
"--gcp-network=default",
183+
"--check-version-skew=false",
184+
"--deployment=gke",
185+
"--gcp-node-image=cos",
186+
"--gcp-network=default",
187+
fmt.Sprintf("--cluster=%s", gkeTestClusterName),
188+
fmt.Sprintf("--gke-environment=%s", gkeEnv),
189+
fmt.Sprintf("--gcp-zone=%s", *gceZone),
190+
fmt.Sprintf("--gcp-project=%s", project[:len(project)-1]),
191+
}
192+
193+
return args, nil
194+
}

test/k8s-integration/main.go

+25-12
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,16 @@ func handle() error {
216216
if err != nil {
217217
return fmt.Errorf("failed to build Kubernetes: %v", err)
218218
}
219+
err = buildKubernetes(testDir, "ginkgo")
220+
if err != nil {
221+
return fmt.Errorf("failed to build gingko: %v", err)
222+
}
219223
} else {
220224
testDir = k8sDir
221225
}
222226

227+
var cloudProviderArgs []string
228+
223229
// Create a cluster either through GKE or GCE
224230
if *bringupCluster {
225231
var err error = nil
@@ -228,6 +234,10 @@ func handle() error {
228234
err = clusterUpGCE(k8sDir, *gceZone, *numNodes)
229235
case "gke":
230236
err = clusterUpGKE(*gceZone, *numNodes)
237+
cloudProviderArgs, err = getGKEKubeTestArgs()
238+
if err != nil {
239+
return fmt.Errorf("failed to build GKE kubetest args: %v", err)
240+
}
231241
default:
232242
err = fmt.Errorf("deployment-strategy must be set to 'gce' or 'gke', but is: %s", *deploymentStrat)
233243
}
@@ -272,9 +282,9 @@ func handle() error {
272282

273283
// Run the tests using the testDir kubernetes
274284
if len(*storageClassFile) != 0 {
275-
err = runCSITests(pkgDir, testDir, *testFocus, *storageClassFile)
285+
err = runCSITests(pkgDir, testDir, *testFocus, *storageClassFile, cloudProviderArgs)
276286
} else if *migrationTest {
277-
err = runMigrationTests(pkgDir, testDir, *testFocus)
287+
err = runMigrationTests(pkgDir, testDir, *testFocus, cloudProviderArgs)
278288
} else {
279289
return fmt.Errorf("did not run either CSI or Migration test")
280290
}
@@ -299,20 +309,20 @@ func setEnvProject(project string) error {
299309
return nil
300310
}
301311

302-
func runMigrationTests(pkgDir, testDir, testFocus string) error {
303-
return runTestsWithConfig(testDir, testFocus, "--storage.migratedPlugins=kubernetes.io/gce-pd")
312+
func runMigrationTests(pkgDir, testDir, testFocus string, cloudProviderArgs []string) error {
313+
return runTestsWithConfig(testDir, testFocus, "--storage.migratedPlugins=kubernetes.io/gce-pd", cloudProviderArgs)
304314
}
305315

306-
func runCSITests(pkgDir, testDir, testFocus, storageClassFile string) error {
316+
func runCSITests(pkgDir, testDir, testFocus, storageClassFile string, cloudProviderArgs []string) error {
307317
testDriverConfigFile, err := generateDriverConfigFile(pkgDir, storageClassFile)
308318
if err != nil {
309319
return err
310320
}
311321
testConfigArg := fmt.Sprintf("--storage.testdriver=%s", testDriverConfigFile)
312-
return runTestsWithConfig(testDir, testFocus, testConfigArg)
322+
return runTestsWithConfig(testDir, testFocus, testConfigArg, cloudProviderArgs)
313323
}
314324

315-
func runTestsWithConfig(testDir, testFocus, testConfigArg string) error {
325+
func runTestsWithConfig(testDir, testFocus, testConfigArg string, cloudProviderArgs []string) error {
316326
err := os.Chdir(testDir)
317327
if err != nil {
318328
return err
@@ -324,18 +334,21 @@ func runTestsWithConfig(testDir, testFocus, testConfigArg string) error {
324334
artifactsDir, _ := os.LookupEnv("ARTIFACTS")
325335
reportArg := fmt.Sprintf("-report-dir=%s", artifactsDir)
326336

327-
kubetestArgs := fmt.Sprintf("--ginkgo.focus=%s --ginkgo.skip=%s %s %s",
337+
testArgs := fmt.Sprintf("--ginkgo.focus=%s --ginkgo.skip=%s %s %s",
328338
testFocus,
329339
"\\[Disruptive\\]|\\[Serial\\]|\\[Feature:.+\\]",
330340
testConfigArg,
331341
reportArg)
332342

333-
cmd := exec.Command("kubetest",
343+
kubeTestArgs := []string{
334344
"--test",
335345
"--ginkgo-parallel",
336-
fmt.Sprintf("--test_args=%s", kubetestArgs),
337-
)
338-
err = runCommand("Running Tests", cmd)
346+
fmt.Sprintf("--test_args=%s", testArgs),
347+
}
348+
349+
kubeTestArgs = append(kubeTestArgs, cloudProviderArgs...)
350+
351+
err = runCommand("Running Tests", exec.Command("kubetest", kubeTestArgs...))
339352
if err != nil {
340353
return fmt.Errorf("failed to run tests on e2e cluster: %v", err)
341354
}

0 commit comments

Comments
 (0)