Commit 321cc836 authored by Giorgenes Gelatti's avatar Giorgenes Gelatti

Handle tag delete 404

When deleting registry tags using dummy images,
the intermediate dummy might be deleted by another
thread and get a 404 when trying to delete it.
The tags go aways regardless so take it as a success
parent 5cf54061
......@@ -67,7 +67,7 @@ class ContainerRepository < ApplicationRecord
def delete_tags!
return unless has_tags?
digests = tags.map { |tag| tag.digest }.to_set
digests = tags.map { |tag| tag.digest }.compact.to_set
digests.all? do |digest|
delete_tag_by_digest(digest)
......
......@@ -48,10 +48,10 @@ module Projects
# rubocop: disable CodeReuse/ActiveRecord
Gitlab::Sentry.track_exception(ArgumentError.new('multiple tag digests')) if tag_digests.many?
# deletes the dummy image
# all created tag digests are the same since they all have the same dummy image.
# Deletes the dummy image
# All created tag digests are the same since they all have the same dummy image.
# a single delete is sufficient to remove all tags with it
if container_repository.client.delete_repository_tag(container_repository.path, tag_digests.first)
if container_repository.delete_tag_by_digest(tag_digests.first)
success(deleted: tag_names)
else
error('could not delete tags')
......
......@@ -36,7 +36,9 @@ module ContainerRegistry
end
def delete_repository_tag(name, reference)
faraday.delete("/v2/#{name}/manifests/#{reference}").success?
result = faraday.delete("/v2/#{name}/manifests/#{reference}")
result.success? || result.status == 404
end
def upload_raw_blob(path, blob)
......@@ -84,7 +86,9 @@ module ContainerRegistry
end
def delete_blob(name, digest)
faraday.delete("/v2/#{name}/blobs/#{digest}").success?
result = faraday.delete("/v2/#{name}/blobs/#{digest}")
result.success? || result.status == 404
end
def put_tag(name, reference, manifest)
......
......@@ -157,6 +157,6 @@ describe Projects::ContainerRepository::CleanupTagsService do
def expect_delete(digest)
expect_any_instance_of(ContainerRegistry::Client)
.to receive(:delete_repository_tag)
.with(repository.path, digest)
.with(repository.path, digest) { true }
end
end
......@@ -87,6 +87,21 @@ describe Projects::ContainerRepository::DeleteTagsService do
is_expected.to include(status: :success)
end
it 'succedes when tag delete returns 404' do
stub_upload("{\n \"config\": {\n }\n}", 'sha256:4435000728ee66e6a80e55637fc22725c256b61de344a2ecdeaac6bdb36e8bc3')
stub_request(:put, "http://registry.gitlab/v2/#{repository.path}/manifests/A")
.to_return(status: 200, body: "", headers: { 'docker-content-digest' => 'sha256:dummy' })
stub_request(:put, "http://registry.gitlab/v2/#{repository.path}/manifests/Ba")
.to_return(status: 200, body: "", headers: { 'docker-content-digest' => 'sha256:dummy' })
stub_request(:delete, "http://registry.gitlab/v2/#{repository.path}/manifests/sha256:dummy")
.to_return(status: 404, body: "", headers: {})
is_expected.to include(status: :success)
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment