Skip to content

Commit

Permalink
[CI|K8s] Fix k8s tests on Jenkins (elastic#18766)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrsMark committed May 28, 2020
1 parent 1012d52 commit 775a44d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
37 changes: 28 additions & 9 deletions dev-tools/mage/kubernetes/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}

0 comments on commit 775a44d

Please sign in to comment.