Skip to content

Commit 6dc9026

Browse files
authored
test/e2e: Fix unset when gathering CI testing artifacts (#2450)
Update the testing e2e packages and ensure that the $KUBECONFIG environment variable is correctly set before running the bash script responsible for collecting CI artifacts. This should fix the following error message that was popping up in individual CI runs: ``` collecting logs in the ./artifacts/ artifacts directory ../test/e2e/collect-ci-artifacts.sh: line 7: KUBECONFIG: parameter null or not set failed to collect namespace artifacts: exit status 1 ``` Update the kind provisioner to avoid prematurely removing the temporary directory that contains the constructed (and ephemeral) kubeconfig file and track that metadata in the TestContext structure. In the case that field is unset for that object, fall back to the os.Getenv("KUBECONFIG") value. Signed-off-by: timflannagan <[email protected]>
1 parent a68dc42 commit 6dc9026

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

test/e2e/ctx/ctx.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ type TestContext struct {
3535
dynamicClient dynamic.Interface
3636
packageClient pversioned.Interface
3737
ssaClient *controllerclient.ServerSideApplier
38+
39+
kubeconfigPath string
3840
artifactsDir string
3941

4042
scheme *runtime.Scheme
@@ -101,10 +103,16 @@ func (ctx TestContext) DumpNamespaceArtifacts(namespace string) error {
101103
if err := os.MkdirAll(logDir, os.ModePerm); err != nil {
102104
return err
103105
}
106+
kubeconfigPath := ctx.kubeconfigPath
107+
if kubeconfigPath == "" {
108+
ctx.Logf("unable to determine kubeconfig path so defaulting to the $KUBECONFIG value")
109+
kubeconfigPath = os.Getenv("KUBECONFIG")
110+
}
111+
104112
envvars := []string{
105113
"TEST_NAMESPACE=" + namespace,
106114
"TEST_ARTIFACTS_DIR=" + logDir,
107-
"KUBECONFIG=" + os.Getenv("KUBECONFIG"),
115+
"KUBECONFIG=" + kubeconfigPath,
108116
}
109117

110118
// compiled test binary running e2e tests is run from the root ./bin directory

test/e2e/ctx/provisioner_kind.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ func Provision(ctx *TestContext) (func(), error) {
8181
if err != nil {
8282
return nil, fmt.Errorf("failed to create temporary directory: %s", err.Error())
8383
}
84-
defer os.RemoveAll(dir)
8584
kubeconfigPath := filepath.Join(dir, "kubeconfig")
8685

8786
provider := cluster.NewProvider(
@@ -139,10 +138,15 @@ func Provision(ctx *TestContext) (func(), error) {
139138
if artifactsDir := os.Getenv("ARTIFACTS_DIR"); artifactsDir != "" {
140139
ctx.artifactsDir = artifactsDir
141140
}
141+
ctx.kubeconfigPath = kubeconfigPath
142142

143143
var once sync.Once
144144
deprovision := func() {
145145
once.Do(func() {
146+
// remove the temporary kubeconfig directory
147+
if err := os.RemoveAll(dir); err != nil {
148+
ctx.Logf("failed to remove the %s kubeconfig directory: %v", dir, err)
149+
}
146150
if ctx.artifactsDir != "" {
147151
ctx.Logf("collecting container logs for the %s cluster", name)
148152
if err := provider.CollectLogs(name, filepath.Join(ctx.artifactsDir, logDir)); err != nil {

0 commit comments

Comments
 (0)