Skip to content

add functionality to use gke with kubetest #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions test/k8s-integration/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,42 @@ func downloadKubernetesSource(pkgDir, k8sIoDir, kubeVersion string) error {

return nil
}

func getGKEKubeTestArgs() ([]string, error) {
var gkeEnv string
switch gkeURL := os.Getenv("CLOUDSDK_API_ENDPOINT_OVERRIDES_CONTAINER"); gkeURL {
case "https://staging-container.sandbox.googleapis.com/":
gkeEnv = "staging"
case "https://test-container.sandbox.googleapis.com/":
gkeEnv = "test"
case "":
gkeEnv = "prod"
default:
// if the URL does not match to an option, assume it is a custom GKE backend
// URL and pass that to kubetest
gkeEnv = gkeURL
}

cmd := exec.Command("gcloud", "config", "get-value", "project")
project, err := cmd.Output()
if err != nil {
return nil, fmt.Errorf("failed to get current project: %v", err)
}

args := []string{
"--up=false",
"--down=false",
"--provider=gke",
"--gcp-network=default",
"--check-version-skew=false",
"--deployment=gke",
"--gcp-node-image=cos",
"--gcp-network=default",
fmt.Sprintf("--cluster=%s", gkeTestClusterName),
fmt.Sprintf("--gke-environment=%s", gkeEnv),
fmt.Sprintf("--gcp-zone=%s", *gceZone),
fmt.Sprintf("--gcp-project=%s", project[:len(project)-1]),
}

return args, nil
}
38 changes: 26 additions & 12 deletions test/k8s-integration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,17 @@ func handle() error {
if err != nil {
return fmt.Errorf("failed to build Kubernetes: %v", err)
}
// kubetest relies on ginkgo already built in the test k8s directory
err = buildKubernetes(testDir, "ginkgo")
if err != nil {
return fmt.Errorf("failed to build gingko: %v", err)
}
} else {
testDir = k8sDir
}

var cloudProviderArgs []string

// Create a cluster either through GKE or GCE
if *bringupCluster {
var err error = nil
Expand All @@ -228,6 +235,10 @@ func handle() error {
err = clusterUpGCE(k8sDir, *gceZone, *numNodes)
case "gke":
err = clusterUpGKE(*gceZone, *numNodes)
cloudProviderArgs, err = getGKEKubeTestArgs()
if err != nil {
return fmt.Errorf("failed to build GKE kubetest args: %v", err)
}
default:
err = fmt.Errorf("deployment-strategy must be set to 'gce' or 'gke', but is: %s", *deploymentStrat)
}
Expand Down Expand Up @@ -272,9 +283,9 @@ func handle() error {

// Run the tests using the testDir kubernetes
if len(*storageClassFile) != 0 {
err = runCSITests(pkgDir, testDir, *testFocus, *storageClassFile)
err = runCSITests(pkgDir, testDir, *testFocus, *storageClassFile, cloudProviderArgs)
} else if *migrationTest {
err = runMigrationTests(pkgDir, testDir, *testFocus)
err = runMigrationTests(pkgDir, testDir, *testFocus, cloudProviderArgs)
} else {
return fmt.Errorf("did not run either CSI or Migration test")
}
Expand All @@ -299,20 +310,20 @@ func setEnvProject(project string) error {
return nil
}

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

func runCSITests(pkgDir, testDir, testFocus, storageClassFile string) error {
func runCSITests(pkgDir, testDir, testFocus, storageClassFile string, cloudProviderArgs []string) error {
testDriverConfigFile, err := generateDriverConfigFile(pkgDir, storageClassFile)
if err != nil {
return err
}
testConfigArg := fmt.Sprintf("--storage.testdriver=%s", testDriverConfigFile)
return runTestsWithConfig(testDir, testFocus, testConfigArg)
return runTestsWithConfig(testDir, testFocus, testConfigArg, cloudProviderArgs)
}

func runTestsWithConfig(testDir, testFocus, testConfigArg string) error {
func runTestsWithConfig(testDir, testFocus, testConfigArg string, cloudProviderArgs []string) error {
err := os.Chdir(testDir)
if err != nil {
return err
Expand All @@ -324,18 +335,21 @@ func runTestsWithConfig(testDir, testFocus, testConfigArg string) error {
artifactsDir, _ := os.LookupEnv("ARTIFACTS")
reportArg := fmt.Sprintf("-report-dir=%s", artifactsDir)

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

cmd := exec.Command("kubetest",
kubeTestArgs := []string{
"--test",
"--ginkgo-parallel",
fmt.Sprintf("--test_args=%s", kubetestArgs),
)
err = runCommand("Running Tests", cmd)
fmt.Sprintf("--test_args=%s", testArgs),
}

kubeTestArgs = append(kubeTestArgs, cloudProviderArgs...)

err = runCommand("Running Tests", exec.Command("kubetest", kubeTestArgs...))
if err != nil {
return fmt.Errorf("failed to run tests on e2e cluster: %v", err)
}
Expand Down