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

[pkg/oci] Delete image with digest #328

Closed
wants to merge 5 commits into from

Conversation

somtochiama
Copy link
Member

@somtochiama somtochiama commented Aug 25, 2022

Part of flux2#2882.
Follow up to #321

This pull request uses the image digest to delete the image instead of tags.
ECR/GHCR doesn't support using the docker Delete API (which is what crane uses) to delete images; therefore, it won't work for them.

Provider Specific Considerations

  1. GHCR doesn't support deletion using the DELETE Docker API. It returns a 405 Unsupported error. Deleting images is allowed using the Github API. For us to support this, it would require getting an authentication token from the user. For more info, see https://github.com/orgs/community/discussions/26267
  2. ECR also doesn't support deletion using the DELETE Docker API. It returns 404 Not Found.
  3. GCR requires that all tags referencing a layer be deleted first. It returns GOOGLE_MANIFEST_DANGLING_TAG: Manifest is still referenced by one or more tags Currently, we delete the tag first, then delete the image. But if there are other tags still referencing the image, the delete will fail
  4. Azure doesn't support tag deletion, Deletion by digest works okay.
    Notes:
    Deletion by tag means using a tag as reference in the URL -> ghcr.io/podinfo:v0.0.1
    Deletion by image means using a digest as the reference in the URL ghcr.io/podinfo@sha256:4ed5..... This deletes the layer in the container registry

This pull request is currently on hold while we decide if we still want to support deletion and how best to go about it.

Signed-off-by: Somtochi Onyekwere somtochionyekwere@gmail.com

Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
@stefanprodan stefanprodan added the area/oci OCI related issues and pull requests label Aug 25, 2022
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
@makkes
Copy link
Member

makkes commented Aug 29, 2022

Please either add a link to the issue this PR resolves or provide a little more context in the PR description. 🙏🏻

Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
@darkowlzz
Copy link
Contributor

darkowlzz commented Aug 29, 2022

The registry server logs are very verbose and distracting. I'd like to discard them by doing

import (
        ...
	dcontext "github.com/distribution/distribution/v3/context"
	"github.com/sirupsen/logrus"
        ...
)
...
	// Discard the registry server logs.
	config.Log.AccessLog.Disabled = true
	logger := logrus.New()
	logger.SetOutput(io.Discard)
	dcontext.SetDefaultLogger(logrus.NewEntry(logger))

before creating a new registry in

dockerRegistry, err := registry.NewRegistry(ctx, config)
. Would like to do the same in SC tests as well.

oci/client/delete.go Outdated Show resolved Hide resolved
oci/client/delete.go Outdated Show resolved Hide resolved
// as it doesn't let you delete an image if a tag still references it.
// This doesn't work with ECR/GHCR since they don't support DELETE according
// to the docker API spec.
func (c *Client) Delete(ctx context.Context, url string, tag string) error {
Copy link
Contributor

@darkowlzz darkowlzz Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to replace redundant tag argument with a delete option which can have an attribute for deleting by using digest? I believe that'd be less confusing than passing the tag when it's already in the URL. The consumer of this (flux CLI) can conditionally set the delete option based on the host name, if it's ECR or GHCR.

Copy link
Member Author

@somtochiama somtochiama Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right about removing the tag argument but don't think we should add deleting by using digest as an option, since we always delete using the digest (GCP doesn't permit deletion if the image still has a tag, and deleting the tag only deletes the tag, not the image itself. Azure doesn't allow deletion using tags).

We could still add a delete option but right now I am not sure what should be in it.
@stefanprodan suggested putting this issue on hold while we figure out if we do want to add this feature given the limited support for Docker DELETE API in some registries and how best to go about it.

oci/tests/integration/repo_list_test.go Outdated Show resolved Hide resolved
oci/tests/integration/suite_test.go Show resolved Hide resolved
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/oci OCI related issues and pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants