oras-project / oras-go

ORAS Go library

Home Page:https://oras.land

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add `Untag()` to `oci.Store`

eiffel-fl opened this issue · comments

Hi.

There is currently a way to tag OCI descriptors, but not to untag them.
This can cause problems when you want to remove container image.
Indeed, in the following scenario, we have two tags pointing to the same underlying descriptor, as shown by the digest:

$ ig image list
REPOSITORY            TAG    DIGEST
docker.io/library/bar latest f959f580ba01
docker.io/library/foo latest f959f580ba01

In this case, we should not try to remove the image, as removing the descriptor will remove it for both image, but rather to untag one image:

$ ig remove docker.io/library/foo:latest
$ ig image list
REPOSITORY            TAG    DIGEST
docker.io/library/bar latest f959f580ba01

To do so, I opened #647 but we should first discuss this here before going further with the PR.
If you want more details on my use case, I invite you to check inspektor-gadget/inspektor-gadget#2162.

Best regards.

I think of a design question regarding this feature: If the given reference string is a digest, what should the behavior of Untag() be? What behavior satisfies your scenario? @eiffel-fl

Hi!

I think of a design question regarding this feature: If the given reference string is a digest, what should the behavior of Untag() be? What behavior satisfies your scenario? @eiffel-fl

Maybe it could be better for implementation to have a digest as Untag() argument?
To delete a tag, caller would have to call the following:

	descriptor, err := ociStore.Resolve(ctx, tag)
	if err != nil {
		return nil, fmt.Errorf("resolving src: %w", err)
	}
	ociStore.Untag(ctx, tag)

Also, it would avoid repeating the code as pointed in your comment.

Best regards.

Hi @eiffel-fl,

We have discussed internally in our team, in general we like the idea of Untag and we think you may continue the work in PR #647. You can add unit tests now, we will review it and get it merged.

Here are a few things we would like your Untag implementation to have:

  1. Your implementation is only for oci.Store for now. Probably we need to have Untag for other types later. So how about you add an Untagger interface in content.resolver.go ? It may just look like the Tagger interface. Its signature would be Untag(ctx context.Context, reference string) error.
  2. For the behavior of the Store.Untag() function, if the input is a valid reference, it should perform untag operations. But if the reference is a valid digest of an existing content, it should do nothing. I think your last implementation is good, you just need to add an extra case of handling digest input. You can use s.tagResolver.Resolve(ctx, reference) and check if reference is a valid digest.

Let us know if there are further concerns. If you want, our team can co-author on PR #647 to speed up progress.

Hi @eiffel-fl,

Hi!

We have discussed internally in our team, in general we like the idea of Untag and we think you may continue the work in PR #647. You can add unit tests now, we will review it and get it merged.
Here are a few things we would like your Untag implementation to have:

1. Your implementation is only for `oci.Store` for now. Probably we need to have `Untag` for other types later. So how about you add an `Untagger` interface in `content.resolver.go` ? It may just look like the `Tagger` interface. Its signature would be `Untag(ctx context.Context, reference string) error`.

2. For the behavior of the `Store.Untag()` function, if the input is a valid reference, it should perform untag operations. But if the reference is a valid digest of an existing content, it should do nothing. I think your last implementation is good, you just need to add an extra case of handling digest input. You can use `s.tagResolver.Resolve(ctx, reference)` and check if `reference` is a valid digest.

Let us know if there are further concerns. If you want, our team can co-author on PR #647 to speed up progress.

Sure! I will polish everything, as I first wanted to have your opinion before writing "fully polished code"!
I should be able to handle it, but I do not have a broad knowledge about OCI, so I may ask for advice on the PR itself!

Best regards.

Closing as addressed in #647.