Skip to content

Commit

Permalink
Fixes #37785 - Race condition during container push (Katello#11129)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjha4 authored Sep 11, 2024
1 parent bcc75d9 commit 326474f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
11 changes: 9 additions & 2 deletions app/lib/actions/katello/repository/create_root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ module Katello
module Repository
class CreateRoot < Actions::EntryAction
def plan(root, relative_path = nil)
root.save!
begin
root.save!
rescue ActiveRecord::RecordInvalid
if root.is_container_push
logger.warn("Skipping repository creation as container push repository already exists: #{root.container_push_name}")
return
end
end
repository = ::Katello::Repository.new(:environment => root.organization.library,
:content_view_version => root.organization.library.default_content_view_version,
:root => root)
repository.container_repository_name = relative_path
repository.container_repository_name = relative_path if root.docker? && root.is_container_push
repository.relative_path = relative_path || repository.custom_repo_path
repository.save!

Expand Down
6 changes: 3 additions & 3 deletions app/models/katello/glue/pulp/repos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ def add_repo(repo_param)

# Container push may concurrently call root add several times before the db can update.
if repo_param[:is_container_push]
RootRepository.create_or_find_by!(repo_param)
else
RootRepository.new(repo_param)
root = RootRepository.find_by(repo_param)
return root if root
end
RootRepository.new(repo_param)
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion app/models/katello/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,10 @@ def content_view
self.content_view_version.content_view
end

# Skip setting container name if the repository is not container type or
# if it's a library instance of a container-push repo, indicating that the container name is set by the user.
def skip_container_name?
self.library_instance? && self.root.docker? && self.root.is_container_push
!self.root.docker? || (self.root.is_container_push && self.library_instance?)
end

def library_instance?
Expand Down

0 comments on commit 326474f

Please sign in to comment.