Skip to content

Update delete tag calls to use /v2/<name>/manifests/<tag>

Adie (she/her) requested to merge 421904-use-new-delete-endpoint-registry into master

What does this MR do and why?

In this MR, we ensure that all delete-tag calls use the OCI-compliant endpoint, DELETE /v2/<name>/manifests/<tag>. This means replacing uses of DELETE /v2/<name>/tags/reference/<tag> (an already deprecated endpoint).

The functionality is the same, and so is the input (tag name) and output (OK/NOK). This change was made to achieve compliance with the OCI Distribution Spec.

Previously, we also had two methods to delete tags, one is by name and one is by digest. The endpoint DELETE /v2/<name>/manifests/<tag> accepts both name and digest so we have renamed the function to just delete_tag().

Link to API docs for endpoint: https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs/spec/api.md?ref_type=heads#delete-manifest

How to set up and validate locally

  1. In the Rails Console, we can try out the new function, Container Repository#delete_tag(name_or_digest).
  2. Create a project and push multiple container registry tags to it.
  3. In the Rails console,
    # we get the repo that we have pushed tags po
    repo = ContainerRepository.last 
    
    # we get 1 tag that we will try deleting with name
    tag1 = repo.tags.last
    
    # we get 1 tag that we will try deleting with digest
    tag2 = repo.tags.first
    
    # make sure that there are at least two tags available, and tag1 and is not the same as tag2
    
    repo.delete_tag(tag1.name)
    # You can refresh the UI in the list repository tags to verify that tag1 is deleted
    
    repo.delete_tag(tag2.digest)
    # You can refresh the UI again to verify that tag2 is deleted.
    
    # You may also verify how many tags are left in the console
    repo.tags

By calling ContainerRepository#delete_tag, we are calling the endpoint /v2/#{name}/manifests/#{reference}. You may check in the logs to verify that the endpoint is actually called. You will see something like:

{"method":"DELETE",
"msg":"router info",
"path":"/v2/october-group/proj-1/manifests/tag5",
"root_repo":"october-group",
"vars_name":"october-group/proj-1","vars_reference":"tag5","version":"v3.58.0-gitlab-610-gf06b3122"}
{"auth_project_paths":["october-group/proj-1"]...}
{"host":"gdk.test:5000","level":"info","method":"DELETE","msg":"access","status":202,
"uri":"/v2/october-group/proj-1/manifests/tag5"}

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #421904 (closed)

Edited by Adie (she/her)

Merge request reports