From 326474f524ed4177e079bfc17e57f31e8243d296 Mon Sep 17 00:00:00 2001 From: Samir Jha Date: Wed, 11 Sep 2024 11:59:10 -0400 Subject: [PATCH] Fixes #37785 - Race condition during container push (#11129) --- app/lib/actions/katello/repository/create_root.rb | 11 +++++++++-- app/models/katello/glue/pulp/repos.rb | 6 +++--- app/models/katello/repository.rb | 4 +++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/lib/actions/katello/repository/create_root.rb b/app/lib/actions/katello/repository/create_root.rb index d3ca8182504..94d408b94ee 100644 --- a/app/lib/actions/katello/repository/create_root.rb +++ b/app/lib/actions/katello/repository/create_root.rb @@ -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! diff --git a/app/models/katello/glue/pulp/repos.rb b/app/models/katello/glue/pulp/repos.rb index 95213377cb7..7a59bf54756 100644 --- a/app/models/katello/glue/pulp/repos.rb +++ b/app/models/katello/glue/pulp/repos.rb @@ -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 diff --git a/app/models/katello/repository.rb b/app/models/katello/repository.rb index e713452454d..b5e724b16c9 100644 --- a/app/models/katello/repository.rb +++ b/app/models/katello/repository.rb @@ -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?