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

Tests crash if os.UserCacheDir() returns an unusable directory #1799

Closed
skitt opened this issue Feb 10, 2022 · 0 comments · Fixed by #1800
Closed

Tests crash if os.UserCacheDir() returns an unusable directory #1799

skitt opened this issue Feb 10, 2022 · 0 comments · Fixed by #1800

Comments

@skitt
Copy link
Member

skitt commented Feb 10, 2022

Since commit 58c17f6 (“addr.Suggest should lock a file instead of memory”), pkg/internal/testing/addr/manager.go’s init() function tries to create a directory using either os.UserCacheDir() or os.TempDir(), whichever succeeds first. In many build environments, $HOME is non-empty but points to an unusable directory; in such cases, os.UserCacheDir() returns an unusable directory, which causes init() to panic.

It could instead try os.TempDir(), which is usable in many more scenarios than os.UserCacheDir().

skitt added a commit to skitt/controller-runtime that referenced this issue Feb 10, 2022
Since commit 58c17f6 ("addr.Suggest should lock a file instead of
memory"), pkg/internal/testing/addr/manager.go’s init() function tries
to create a directory using either os.UserCacheDir() or os.TempDir(),
whichever succeeds first. In many build environments, $HOME is
non-empty but points to an unusable directory; in such cases,
os.UserCacheDir() returns an unusable directory, which causes init()
to panic.

This changes init() to first try os.UserCacheDir(), including creating
the desired directory; if that fails, the whole operation is tried
again with os.TempDir().

Fixes: kubernetes-sigs#1799
Signed-off-by: Stephen Kitt <skitt@redhat.com>
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.

1 participant