Skip to content

Commit

Permalink
Refs #37785 - Race condition during container push
Browse files Browse the repository at this point in the history
  • Loading branch information
sjha4 committed Sep 26, 2024
1 parent 9456160 commit a92fcde
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions app/lib/actions/katello/repository/create_root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,34 @@ module Katello
module Repository
class CreateRoot < Actions::EntryAction
def plan(root, relative_path = nil)
begin
root.save!
rescue ActiveRecord::RecordInvalid => e
if root.is_container_push && e.message.include?("Container Repository Name") && e.message.include?("conflicts with an existing repository")
logger.warn("Skipping repository creation as container push repository already exists: #{root.container_push_name}")
return
repository = ::Katello::Repository.new(:environment => root.organization.library, :content_view_version => root.organization.library.default_content_view_version, :root => root)
root.product.with_lock do
begin
root.save!
rescue ActiveRecord::RecordInvalid => e
if root.is_container_push && e.message.include?("Name has already been taken for this product")
Rails.logger.warn("Skipping root repository creation as container push root repository already exists: #{root.container_push_name}")
return
end
raise e
end
repository.container_repository_name = relative_path if root.docker? && root.is_container_push
repository.relative_path = relative_path || repository.custom_repo_path
begin
repository.save!
rescue ActiveRecord::RecordInvalid => e
if root.is_container_push && e.message.include?("Container Repository Name") && e.message.include?("conflicts with an existing repository")
Rails.logger.warn("Skipping repository creation as container push repository already exists: #{root.container_push_name}")
return
end
raise e
end
raise e
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 if root.docker? && root.is_container_push
repository.relative_path = relative_path || repository.custom_repo_path
repository.save!


action_subject(repository)
plan_action(::Actions::Katello::Repository::Create, repository)
end

def humanized_name
_("Create")
end
Expand Down

0 comments on commit a92fcde

Please sign in to comment.