From 775a44d74700b9721b6329c76263ab2d4e1491b2 Mon Sep 17 00:00:00 2001 From: Chris Mark Date: Thu, 28 May 2020 14:25:32 +0300 Subject: [PATCH] [CI|K8s] Fix k8s tests on Jenkins (#18766) --- Jenkinsfile | 2 +- dev-tools/mage/kubernetes/kind.go | 37 +++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 068b1ba4cc9..80972cf897e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -990,8 +990,8 @@ def k8sTest(versions){ withBeatsEnv(false) { sh(label: "Install kind", script: ".ci/scripts/install-kind.sh") sh(label: "Install kubectl", script: ".ci/scripts/install-kubectl.sh") - sh(label: "Integration tests", script: "MODULE=kubernetes make -C metricbeat integration-tests") sh(label: "Setup kind", script: ".ci/scripts/kind-setup.sh") + sh(label: "Integration tests", script: "MODULE=kubernetes make -C metricbeat integration-tests") sh(label: "Deploy to kubernetes",script: "make -C deploy/kubernetes test") sh(label: 'Delete cluster', script: 'kind delete cluster') } diff --git a/dev-tools/mage/kubernetes/kind.go b/dev-tools/mage/kubernetes/kind.go index c4a94649ca7..d74191e88cd 100644 --- a/dev-tools/mage/kubernetes/kind.go +++ b/dev-tools/mage/kubernetes/kind.go @@ -48,16 +48,15 @@ func (m *KindIntegrationTestStep) Use(dir string) (bool, error) { // // If `KUBECONFIG` is already deinfed in the env then it will do nothing. func (m *KindIntegrationTestStep) Setup(env map[string]string) error { - _, exists := env["KUBECONFIG"] - if exists { - // do nothing - return nil - } - _, exists = env["KUBE_CONFIG"] - if exists { - // do nothing - return nil + + envVars := []string{"KUBECONFIG", "KUBE_CONFIG"} + for _, envVar := range envVars { + exists := envKubeConfigExists(env, envVar) + if exists { + return nil + } } + _, err := exec.LookPath("kind") if err != nil { if mg.Verbose() { @@ -80,6 +79,9 @@ func (m *KindIntegrationTestStep) Setup(env map[string]string) error { return err } kubeConfig := filepath.Join(kubeCfgDir, "kubecfg") + if mg.Verbose() { + fmt.Println("Kubeconfig: ", kubeConfig) + } if err := os.MkdirAll(kubeCfgDir, os.ModePerm); err != nil { return err } @@ -141,3 +143,20 @@ func (m *KindIntegrationTestStep) Teardown(env map[string]string) error { } return nil } + +func envKubeConfigExists(env map[string]string, envVar string) bool { + _, exists := env[envVar] + if exists { + if mg.Verbose() { + fmt.Printf("%s: %s\n", envVar, env[envVar]) + } + if _, err := os.Stat(env[envVar]); err == nil { + return true + } else if os.IsNotExist(err) { + if mg.Verbose() { + fmt.Printf("%s file not found: %s: %v\n", envVar, env[envVar], err) + } + } + } + return false +}