Skip to content

Commit

Permalink
test/e2e: Fix unset when gathering CI testing artifacts (#2450)
Browse files Browse the repository at this point in the history
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 <timflannagan@gmail.com>

Upstream-repository: operator-lifecycle-manager
Upstream-commit: 6dc902654d4f2089da9da56cc6b1d574be995d20
  • Loading branch information
timflannagan authored and perdasilva committed Mar 4, 2022
1 parent 953014a commit 322ec9f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 9 additions & 1 deletion staging/operator-lifecycle-manager/test/e2e/ctx/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type TestContext struct {
dynamicClient dynamic.Interface
packageClient pversioned.Interface
ssaClient *controllerclient.ServerSideApplier

kubeconfigPath string
artifactsDir string

scheme *runtime.Scheme
Expand Down Expand Up @@ -101,10 +103,16 @@ func (ctx TestContext) DumpNamespaceArtifacts(namespace string) error {
if err := os.MkdirAll(logDir, os.ModePerm); err != nil {
return err
}
kubeconfigPath := ctx.kubeconfigPath
if kubeconfigPath == "" {
ctx.Logf("unable to determine kubeconfig path so defaulting to the $KUBECONFIG value")
kubeconfigPath = os.Getenv("KUBECONFIG")
}

envvars := []string{
"TEST_NAMESPACE=" + namespace,
"TEST_ARTIFACTS_DIR=" + logDir,
"KUBECONFIG=" + os.Getenv("KUBECONFIG"),
"KUBECONFIG=" + kubeconfigPath,
}

// compiled test binary running e2e tests is run from the root ./bin directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func Provision(ctx *TestContext) (func(), error) {
if err != nil {
return nil, fmt.Errorf("failed to create temporary directory: %s", err.Error())
}
defer os.RemoveAll(dir)
kubeconfigPath := filepath.Join(dir, "kubeconfig")

provider := cluster.NewProvider(
Expand Down Expand Up @@ -139,10 +138,15 @@ func Provision(ctx *TestContext) (func(), error) {
if artifactsDir := os.Getenv("ARTIFACTS_DIR"); artifactsDir != "" {
ctx.artifactsDir = artifactsDir
}
ctx.kubeconfigPath = kubeconfigPath

var once sync.Once
deprovision := func() {
once.Do(func() {
// remove the temporary kubeconfig directory
if err := os.RemoveAll(dir); err != nil {
ctx.Logf("failed to remove the %s kubeconfig directory: %v", dir, err)
}
if ctx.artifactsDir != "" {
ctx.Logf("collecting container logs for the %s cluster", name)
if err := provider.CollectLogs(name, filepath.Join(ctx.artifactsDir, logDir)); err != nil {
Expand Down

0 comments on commit 322ec9f

Please sign in to comment.