-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Remove image via storage if a buildah container is associated #522
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
Remove image via storage if a buildah container is associated #522
Conversation
cmd/podman/rmi.go
Outdated
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 already have a storage.Store in libpod, don't need this
cmd/podman/rmi.go
Outdated
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 have the image already, can't we pass this in?
cmd/podman/rmi.go
Outdated
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 don't need this logic, the standard logic in our image library for removing images should work fine
|
I think we really just need RunningContainers and RemoveContainers here. We can run RunningContainers unconditionally before we try and remove the image but after we remove Podman containers. If it returns that containers are present and --force is present, we use the RemoveContainers code to remove all non-Podman containers associated with the image. If it returns that containers are present and force is not set, we warn that non-Podman containers are using the image, and you should use --force if you want it gone. Then we continue with our removal logic. How does this sound? |
|
I agree with the proposed approach though part of me would prefer it be an import of buildah code ... nevertheless, I think that approach is spot on. |
cmd/podman/rmi.go
Outdated
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 was waffling about keeping these following three functions in here or moving them into libpod/runtime_img.go
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'd go ahead and move them. I am trying to keep the store entirely inside libpod, so directly opening a store and deleting outside of libpod is really undesirable. If we can make these part of runtime.RemoveImage, instead of the code here calling it, I think that'd be fine, and we wouldn't have to leak the store outside of libpod.
libpod/runtime_img.go
Outdated
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 don't think we need this. We can just get storageContainers for the image and return an error if containers exist or remove them if --force is set. We don't need to do it in an error handling block, that makes things a lot harder to follow.
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 sure exactly what you're suggesting here. After line 129 are you saying I should just try getting the storage containers and then error if the image has containers and no force, other wise remove? When we get to this point we've already tried removing the image and that failed due to it being a storage image and a container was associated. I might be able to move the storage image handling that I've below into image.Remove() if that would be preferable. I'll play with that and hit me up on IRC in the morn if I'm off base.
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, should have been more clear - I mean before 129, we can do the check if the container is mounted before the actual remove happens, thus removing the need to check errors.Cause() and perform complicated handling. This might make our fastpath a bit slower (we do a check unconditionally instead of conditionally), but will improve code flow and readability. We can always go back and make things faster later if need be.
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.
This chunk has been reworked and greatly reduced. I still have the error check, but I think it makes more sense now. Cand/will adjust after the next review if you think appropriate.
libpod/image/image.go
Outdated
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 should not need this. I really do not want to return a Store anywhere the user can get one.
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.
If you or @baude have a suggestion around it, I'm happy to do it. I tried using image.imageruntime.store in the call in runtime_img.go below but got:
github.com/projectatomic/libpod/libpod
_output/src/github.com/projectatomic/libpod/libpod/runtime_img.go:135:65: image.imageruntime undefined (cannot refer to unexported field or method imageruntime)
Thought exposing the function would be better. However if I move that code to handle the storage containers into image.go as talked about below, that might solve that problem.
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.
The image runtime's store is guaranteed to be the same as the normal runtime's store - you should just be able to runtime.store instead
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.
Agreed, i went to great pains to avoid this.
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.
ack, I was over complicating it, I can just do r.store in runtime_img.go and it gets me what I need. Thought I'd to pull it from each image and that wasn't resolving.
libpod/runtime_img.go
Outdated
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.
No printing in libpod - return this as an error
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.
will do....
cmd/podman/rmi.go
Outdated
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.
Why is this necessary? Can we not find the image by its ID?
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 did this for the case when a image was tagged. If I do:
podman pull alpine
podman tag alpine tg
podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
tg latest 3fd9065eaf02 2 months ago 4.41MB
docker.io/library/alpine latest 3fd9065eaf02 2 months ago 4.41MB
Both "images" had the same ID, the only way I could differentiate them was to go by their repo.
cmd/podman/rmi.go
Outdated
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.
@TomSweeneyRedHat im confused by this. I'll catch you on IRC for follow-up
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.
@baude and I worked through this before scrum. The issue I was running into was deleting container from an image created by Buildah when the image had a tag added to it. The code as I had it here worked around that, however @baude pointed to a tweak of a if statement down lower that let me remove this code and still get the containers removed. This has all been removed.
libpod/runtime_img.go
Outdated
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 would prefer to see this and subsequent functions take a *image.Image ... then you have the store and storage.Image already. I say that assuming you at one point already had an *image.Image
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.
reworking. I've passed image.Image to the rmStorageContainers and just the id to one other function rather than the whole image.
libpod/runtime_img.go
Outdated
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.
Ill hit you up on irc for clarification on this func as well.
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 only talked briefly about this, but I've removed this as you indicated elsewhere I can get the info here from the runtime (r).
TomSweeneyRedHat
left a comment
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.
New Patch up. I want to test a bit more and just spotted a couple added blank lines. Will test and clean. If you want to review now, great, if not I'll be getting another patch up later today or tomorrow morn.
cmd/podman/rmi.go
Outdated
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.
Shouldn't just call out buildah here - could also be CRI-O.
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.
Ideally, should mention containers/storage specifically, could be a program using c/storage we didn't write
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.
Couple of things here. First, if the err is no ErrImageUserByContainer, isn't the error lost? And second, should your error message also contain the contents of err?
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've changed the error message, bumped it a bit from what @mheon suggested. I don't think the error is lost here, we save it as we do currently in lastError. This only prints out extra verbiage when we have a container tied to the image. The error that prints I didn't think added a lot here, and the error message is currently pretty long so I didn't include it. If you've a strong opinion on adding it I can.
libpod/runtime_img.go
Outdated
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.
Are we retrying on the assumption that the containers using the image were removed? If so, can we get a comment to that effect?
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.
Also, instead of setting error, it's probably better to just return here and below in the else
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.
is there any chance that err might not be ErrImageUsedByContainer ?
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've added a comment.
I think we want to capture the err from this second remove and return it if there's an error. But if you really think it's better, I can just let the original err be returned. As far as returning the errStorage error I was on the fence about returning that or not, but thought it would give a better clue if there was an error. I'll keep them both for now, holler in he morn if you'd like me to remove them.
I think there's a very small chance that the err would be something other then ErrImageUsedByContainer. But if it is, we'll just get the same error from the second image remove and will continue on down the error path. But for the vast majority, it should be the image in use error.
libpod/runtime_img.go
Outdated
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.
&& force?
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.
good call, done.
libpod/runtime_img.go
Outdated
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.
if err := remove.... ; 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.
yep, found a second one too, thx.
|
@TomSweeneyRedHat can you rebase on latest master? The test failures should be fixed |
|
#564 should hopefully fix up the test errors here. |
|
@TomSweeneyRedHat Rebase and try. |
cmd/podman/rmi.go
Outdated
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.
nit: Not crazy about mentioning other tools here since we would love to see other tools start using containers/storage and then this message can become dated.
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 hear you, but my main concern that if a customer got an error that there's a "container associated with containers/storage" would they know enough to check Buildah/CRI-O? I've tried to open it up a bit by adding etc.
libpod/runtime_img.go
Outdated
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.
Remove random whitespace
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.
Done, don't know how I managed that one.
|
A couple of nits, but LGTM |
TomSweeneyRedHat
left a comment
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.
New patch pushed.
cmd/podman/rmi.go
Outdated
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 hear you, but my main concern that if a customer got an error that there's a "container associated with containers/storage" would they know enough to check Buildah/CRI-O? I've tried to open it up a bit by adding etc.
libpod/runtime_img.go
Outdated
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.
Done, don't know how I managed that one.
|
@mheon @baude @umohnani8 PTAL |
libpod/runtime_img.go
Outdated
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.
Shouldn't we throw ErrImageUsedByContainer here if len(ctrIDs) > 0 && !force?
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 was relying on the second image.Remove(force) to provide that error at line 132. However it probably does make more sense to throw the error here and not invoke that image.Remove() again as we know it will fail in this instance. Good thought.
libpod/runtime_img.go
Outdated
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.
Extra whitespace
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.
Fixed, found another rogue one and zapped that too.
|
LGTM |
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
|
Changes LGTM |
|
📌 Commit 21b7c40 has been approved by |
|
Quick test output: |
|
☀️ Test successful - status-papr |
|
Addresses #174 |
Signed-off-by: TomSweeneyRedHat tsweeney@redhat.com
When a removal of an image returns ErrImageUsedByContainer, rather than raising an error immediately we get the image from the containers/storage and see if we can remove containers from there for that image (generally those containers are put into play by Buildah) and then try again to remove the image from Podman.