From 63589f3314abe00e14dd7cba4a8d7fd4fe40247d Mon Sep 17 00:00:00 2001 From: Woohyung Han Date: Sun, 1 Dec 2019 12:18:05 +0900 Subject: [PATCH] Fix kubeconfig default working correctly Kuberentes e2e framework get kubeconfig information from KUBECONFIG environment variable. set the variable by default. --- e2e/e2e_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 26b2994ce..c9d5a66f1 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -4,6 +4,8 @@ import ( "flag" "fmt" "log" + "os" + "path/filepath" "testing" . "github.com/onsi/ginkgo" @@ -24,6 +26,9 @@ func init() { flag.BoolVar(&rookRequired, "deploy-rook", true, "deploy rook on kubernetes") flag.IntVar(&deployTimeout, "deploy-timeout", 10, "timeout to wait for created kubernetes resources") + + setDefaultKubeconfig() + // Register framework flags, then handle flags framework.HandleFlags() framework.AfterReadingAllFlags(&framework.TestContext) @@ -32,6 +37,14 @@ func init() { fmt.Println("timeout for deploytimeout ", deployTimeout) } +func setDefaultKubeconfig() { + _, exists := os.LookupEnv("KUBECONFIG") + if !exists { + defaultKubeconfig := filepath.Join(os.Getenv("HOME"), ".kube", "config") + os.Setenv("KUBECONFIG", defaultKubeconfig) + } +} + // removeCephCSIResource is a temporary fix for CI to remove the ceph-csi resources deployed by rook func removeCephCSIResource() { // cleanup rbd and cephfs deamonset deployed by rook