Skip to content

Commit 775a44d

Browse files
authored
[CI|K8s] Fix k8s tests on Jenkins (#18766)
1 parent 1012d52 commit 775a44d

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,8 @@ def k8sTest(versions){
990990
withBeatsEnv(false) {
991991
sh(label: "Install kind", script: ".ci/scripts/install-kind.sh")
992992
sh(label: "Install kubectl", script: ".ci/scripts/install-kubectl.sh")
993-
sh(label: "Integration tests", script: "MODULE=kubernetes make -C metricbeat integration-tests")
994993
sh(label: "Setup kind", script: ".ci/scripts/kind-setup.sh")
994+
sh(label: "Integration tests", script: "MODULE=kubernetes make -C metricbeat integration-tests")
995995
sh(label: "Deploy to kubernetes",script: "make -C deploy/kubernetes test")
996996
sh(label: 'Delete cluster', script: 'kind delete cluster')
997997
}

dev-tools/mage/kubernetes/kind.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,15 @@ func (m *KindIntegrationTestStep) Use(dir string) (bool, error) {
4848
//
4949
// If `KUBECONFIG` is already deinfed in the env then it will do nothing.
5050
func (m *KindIntegrationTestStep) Setup(env map[string]string) error {
51-
_, exists := env["KUBECONFIG"]
52-
if exists {
53-
// do nothing
54-
return nil
55-
}
56-
_, exists = env["KUBE_CONFIG"]
57-
if exists {
58-
// do nothing
59-
return nil
51+
52+
envVars := []string{"KUBECONFIG", "KUBE_CONFIG"}
53+
for _, envVar := range envVars {
54+
exists := envKubeConfigExists(env, envVar)
55+
if exists {
56+
return nil
57+
}
6058
}
59+
6160
_, err := exec.LookPath("kind")
6261
if err != nil {
6362
if mg.Verbose() {
@@ -80,6 +79,9 @@ func (m *KindIntegrationTestStep) Setup(env map[string]string) error {
8079
return err
8180
}
8281
kubeConfig := filepath.Join(kubeCfgDir, "kubecfg")
82+
if mg.Verbose() {
83+
fmt.Println("Kubeconfig: ", kubeConfig)
84+
}
8385
if err := os.MkdirAll(kubeCfgDir, os.ModePerm); err != nil {
8486
return err
8587
}
@@ -141,3 +143,20 @@ func (m *KindIntegrationTestStep) Teardown(env map[string]string) error {
141143
}
142144
return nil
143145
}
146+
147+
func envKubeConfigExists(env map[string]string, envVar string) bool {
148+
_, exists := env[envVar]
149+
if exists {
150+
if mg.Verbose() {
151+
fmt.Printf("%s: %s\n", envVar, env[envVar])
152+
}
153+
if _, err := os.Stat(env[envVar]); err == nil {
154+
return true
155+
} else if os.IsNotExist(err) {
156+
if mg.Verbose() {
157+
fmt.Printf("%s file not found: %s: %v\n", envVar, env[envVar], err)
158+
}
159+
}
160+
}
161+
return false
162+
}

0 commit comments

Comments
 (0)