Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

envtest.Environment.Stop() leaves orphan /tmp/envtest-serving-certs-* directories #1496

Closed
invidian opened this issue Apr 29, 2021 · 4 comments · Fixed by #1504
Closed

envtest.Environment.Stop() leaves orphan /tmp/envtest-serving-certs-* directories #1496

invidian opened this issue Apr 29, 2021 · 4 comments · Fixed by #1504
Assignees

Comments

@invidian
Copy link
Member

Executing the following snippet in tests:

    testEnv := &envtest.Environment{}

    cfg, err := testEnv.Start()
    if err != nil {
      t.Fatalf("starting test environment: %v", err)
    }

    t.Cleanup(func() {
      t.Logf("stopping test environment")

      if err := testEnv.Stop(); err != nil {
        t.Logf("stopping test environment: %v", err)
      }
    })

Leaves orphan files in /tmp:

$ ls /tmp/envtest-serving-certs-*
/tmp/envtest-serving-certs-210428206:
tls.crt  tls.key

/tmp/envtest-serving-certs-672117224:
tls.crt  tls.key

/tmp/envtest-serving-certs-778787569:
tls.crt  tls.key

/tmp/envtest-serving-certs-912074827:
tls.crt  tls.key

They should be cleaned up.

@aayushrangwala
Copy link
Contributor

/assign

@aayushrangwala
Copy link
Contributor

@invidian I see the cleanup code to handling the removal of these /tmp directories as well. Maybe those were the directories left when the test suite was manually cancelled by the external interruption or the envtest version must be older. Please verify again by cleaning these directories and retry the suite and check if the directories are still not being cleaned

@invidian
Copy link
Member Author

invidian commented May 2, 2021

Hmm, I use USE_EXISTING_CLUSTER=true with sigs.k8s.io/controller-runtime v0.8.3. But no, the test suite is not manually terminated and yes, definitely it's newly created.

Following code can be used for testing:

package main

import (
        "testing"

        "sigs.k8s.io/controller-runtime/pkg/envtest"
)

func TestHelloWorld(t *testing.T) {
        testEnv := &envtest.Environment{}

        _, err := testEnv.Start()
        if err != nil {
                t.Fatalf("starting test environment: %v", err)
        }

        if err := testEnv.Stop(); err != nil {
                t.Fatalf("stopping test environment: %v", err)
        }
}

Then, run as USE_EXISTING_CLUSTER=true go test -v -count 1 ./ && ls -ld /tmp/envtest-serving-certs-*

Using sigs.k8s.io/controller-runtime v0.9.0-beta.0.0.20210501145159-3b25aa6a620c yells the same result.

@aayushrangwala
Copy link
Contributor

Hmm, I use USE_EXISTING_CLUSTER=true with sigs.k8s.io/controller-runtime v0.8.3. But no, the test suite is not manually terminated and yes, definitely it's newly created.

Following code can be used for testing:

package main

import (
        "testing"

        "sigs.k8s.io/controller-runtime/pkg/envtest"
)

func TestHelloWorld(t *testing.T) {
        testEnv := &envtest.Environment{}

        _, err := testEnv.Start()
        if err != nil {
                t.Fatalf("starting test environment: %v", err)
        }

        if err := testEnv.Stop(); err != nil {
                t.Fatalf("stopping test environment: %v", err)
        }
}

Then, run as USE_EXISTING_CLUSTER=true go test -v -count 1 ./ && ls -ld /tmp/envtest-serving-certs-*

Using sigs.k8s.io/controller-runtime v0.9.0-beta.0.0.20210501145159-3b25aa6a620c yells the same result.

Yes, that make sense. So the behavior while using existing cluster, its not cleaned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants