-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
e2e: Allow ImageCacheDir to be changed with an environment variable #17089
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: sstosh The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
70f62ed
to
b197be5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Changes LGTM with one question.
@edsantiago PTAL
@@ -188,6 +188,7 @@ var _ = Describe("Podman save", func() { | |||
|
|||
cmd = exec.Command("cp", "sign/key.gpg", "/tmp/key.gpg") | |||
Expect(cmd.Run()).To(Succeed()) | |||
defer os.Remove("/tmp/key.gpg") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should that also be under cachedir?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to fix the keyPath
value from /tmp/key.gpg
to cachePath("key.gpg")
in e2e/sign/policy.json
.
podman/test/e2e/sign/policy.json
Line 13 in a702d44
"keyPath": "/tmp/key.gpg" |
I haven't come up with a best way, so I remove the key.gpg
by defer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of maybe see what problem this is trying to solve, but I think this might not be the best way to do it. Blocking because of two concerns.
test/e2e/common_test.go
Outdated
@@ -844,9 +847,27 @@ func populateCache(podman *PodmanTestIntegration) { | |||
fmt.Printf("-----------------------------\n") | |||
} | |||
|
|||
func cachePath(path string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm failing to see how this will use $PODMAN_TEST_IMAGE_CACHE_DIR
. Should it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm bit a confused.
ImageCacheDir
is hard corded (/tmp/podman/imagecachedir
).
Line 16 in a702d44
ImageCacheDir = "/tmp/podman/imagecachedir" |
On the other hand, $PODMAN_TEST_IMAGE_CACHE_DIR
also exists and used.
podman/test/e2e/common_test.go
Lines 344 to 357 in a702d44
func imageTarPath(image string) string { | |
cacheDir := os.Getenv("PODMAN_TEST_IMAGE_CACHE_DIR") | |
if cacheDir == "" { | |
cacheDir = os.Getenv("TMPDIR") | |
if cacheDir == "" { | |
cacheDir = "/tmp" | |
} | |
} | |
// e.g., registry.com/fubar:latest -> registry.com-fubar-latest.tar | |
imageCacheName := strings.ReplaceAll(strings.ReplaceAll(image, ":", "-"), "/", "-") + ".tar" | |
return filepath.Join(cacheDir, imageCacheName) | |
} |
I don't know if it is necessary to separate ImageCacheDir
and $PODMAN_TEST_IMAGE_CACHE_DIR
.
If unnecessary, I think that $PODMAN_TEST_IMAGE_CACHE_DIR
can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for taking so long to respond. I think you've hit on the main issue: $PODMAN_TEST_IMAGE_CACHE_DIR
has nothing whatsoever to do with ImageCacheDir
. It's a confusing similarity. I would suggest leaving the existing $PODMAN_TEST_IMAGE_CACHE_DIR
code untouched. The reason that exists is that ginkgo tests pull enormous images, and that takes half an hour on my slow network. I need to cache those locally.
The rest of your PR, though, still needs touchup. Here's what I suggest:
- leave
imageTarPath()
untouched - Remove lines 845-849, so
cachePath()
always returns$TMPDIR/arg
(defaulting to/tmp
) (as you do now)- Bonus points if you can get rid of
""
requirement, so callers can docachePath()
instead ofcachePath("")
. The former is more readable.
- Bonus points if you can get rid of
- in
removeCache()
, always removecachePath("imagedir")
. Right now you don't remove it if$TMPDIR
is set, and that seems like a logic bug.- bonus points if you find a way to remove using
podman unshare
or some magic namespace code, because that code always always always fails rootless.
- bonus points if you find a way to remove using
Thanks again for your patience and for your contribution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked that the cache directory is failed to remove due to a permission.
When a rootless user, remove the cache with podman unshare rm -rf <cacheDir>
.
podman/test/e2e/common_test.go
Lines 564 to 574 in 63c6a1a
// Nuke tempdir | |
if isRootless() { | |
cmd := exec.Command(p.PodmanBinary, "unshare", "rm", "-rf", p.TempDir) | |
if err := cmd.Run(); err != nil { | |
fmt.Fprintf(os.Stderr, "%v\n", err) | |
} | |
} else { | |
if err := os.RemoveAll(p.TempDir); err != nil { | |
fmt.Printf("%q\n", err) | |
} | |
} |
podman/test/e2e/common_test.go
Lines 873 to 884 in 63c6a1a
// Remove cache dirs | |
imageDir := cachePath("imagedir") | |
if isRootless() { | |
cmd := exec.Command(p.PodmanBinary, "unshare", "rm", "-rf", imageDir) | |
if err := cmd.Run(); err != nil { | |
fmt.Fprintf(os.Stderr, "%v\n", err) | |
} | |
} else { | |
if err := os.RemoveAll(imageDir); err != nil { | |
fmt.Printf("%q\n", err) | |
} | |
} |
test/e2e/common_test.go
Outdated
imageCacheDir = os.Getenv("PODMAN_TEST_IMAGE_CACHE_DIR") | ||
} | ||
|
||
if err := os.RemoveAll(imageCacheDir); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too happy with the possibility of someone (inadvertently or not) setting PODMAN_TEST_IMAGE_CACHE_DIR=/tmp
(or /etc
or even /
) and having that be wiped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed a condition for remove a cache directory.
c34b1e9
to
647fc4a
Compare
test/e2e/create_test.go
Outdated
nonExistentFile := cachePath("nonexistent") | ||
session := podmanTest.Podman([]string{"create", "--authfile", nonExistentFile, "--name=foo", ALPINE}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this, and the other /tmp/nonexistent
changes, are overkill.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reverted cachePath("noexistent")
to /tmp/noexistent
.
3b265fd
to
ab0e361
Compare
ab0e361
to
63c6a1a
Compare
- We can change the ImageCacheDir with `TMPDIR`. - Reduce dependency on `/tmp` for e2e tests. - When a rootless user, the cache directory is failed to remove due to a permission. Therefore, we use `podman unshare rm` to remove the cache. Signed-off-by: Toshiki Sonoda <[email protected]>
I'm really sorry, but I can't review this. I've tried three times, Friday and today, and it's too convoluted. This is not your fault -- our test setup overloads too many things in and too many names (image, cache, tmp) -- but the result is, I can't understand this, can't confirm that it has no unintended consequences, and can't approve it. May I request that you break this down into smaller PRs? Something like: 1) temp/scratch (not cache) filesAdd a new function, func tempFilePath(path string) string {
return filepath.Join(os.TempDir(), path)
// even better would be creating a one-time `os.MkdirTemp("", "podman-e2e-tests.*")
// but that would again lead to a too-complicated PR. Once the code is cleaned up,
// we can look into that as a future improvement.
} ...and use that new function in (In case someone suggests 2) image cacheLeave That leaves the delete code, which still scares the heck out of me, but I think with these two changes the delete code will be easier to understand. Alternatively, perhaps someone else in @containers/podman-maintainers can understand and review and approve this PR as it is. But again, I'm sorry, I cannot. |
Thank you for your review and suggestions.
This PR become longer, so I'll close it once. |
We can change the ImageCacheDir with
TMPDIR
.Reduce dependency on
/tmp
for e2e tests.When a rootless user, the cache directory is failed to
remove due to a permission. Therefore, we use
podman unshare rm
to remove the cache.Signed-off-by: Toshiki Sonoda [email protected]
Does this PR introduce a user-facing change?