Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37552 - container push repo content view support #11028

Merged
merged 6 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 111 additions & 59 deletions app/controllers/katello/api/registry/registry_proxies_controller.rb

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions app/controllers/katello/api/v2/environments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ def update
update_params[:name] = params[:environment][:new_name] if params[:environment][:new_name]
@environment.update!(update_params)
if update_params[:registry_name_pattern] || update_params[:registry_unauthenticated_pull]
task = send(async ? :async_task : :sync_task, ::Actions::Katello::Environment::PublishRepositories,
@environment, content_type: Katello::Repository::DOCKER_TYPE)
task = send(async ? :async_task : :sync_task, ::Actions::Katello::Environment::PublishContainerRepositories, @environment)
end

if params.include?(:async) && async && task
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
module Actions
module Katello
module Environment
class PublishRepositories < Actions::EntryAction
class PublishContainerRepositories < Actions::EntryAction
middleware.use ::Actions::Middleware::RemoteAction

input_format do
param :id
param :name
end

def plan(env, options = {})
repositories = options[:content_type] ? env.repositories.with_type(options[:content_type]) : env.repositories
def plan(env)
repositories = env.repositories.docker_type
action_subject(env)
concurrence do
repositories.each do |repository|
sequence do
repository.set_container_repository_name
repository.clear_smart_proxy_sync_histories
plan_action(::Actions::Katello::Repository::InstanceUpdate, repository)
plan_action(::Actions::Katello::Repository::CapsuleSync, repository)
unless repository.root.is_container_push && repository.library_instance?
repository.set_container_repository_name
repository.clear_smart_proxy_sync_histories
plan_action(::Actions::Katello::Repository::InstanceUpdate, repository)
plan_action(::Actions::Katello::Repository::CapsuleSync, repository)
end
end
end

Expand All @@ -31,7 +33,7 @@ def rescue_strategy
end

def humanized_name
_("Publish Lifecycle Environment Repositories")
_("Publish Lifecycle Environment Container Repositories")
end

def humanized_input
Expand Down
6 changes: 3 additions & 3 deletions app/lib/actions/katello/repository/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Actions
module Katello
module Repository
class Create < Actions::EntryAction
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
def plan(repository, args = {})
clone = args[:clone] || false
force_repo_create = args[:force_repo_create] || false
Expand All @@ -15,7 +15,7 @@ def plan(repository, args = {})
sequence do
# Container push repositories will already be in pulp. The version_href is
# directly updated after a push.
unless root.is_container_push
unless root.is_container_push && repository.in_default_view?
create_action = plan_action(Pulp3::Orchestration::Repository::Create,
repository, SmartProxy.pulp_primary, force_repo_create)
return if create_action.error
Expand All @@ -36,7 +36,7 @@ def plan(repository, args = {})
end

# Container push repos do not need metadata generation or ACS (they do not sync)
unless root.is_container_push
unless root.is_container_push && repository.in_default_view?
concurrence do
plan_self(:repository_id => repository.id, :clone => clone)
if !clone && repository.url.present?
Expand Down
1 change: 1 addition & 0 deletions app/lib/actions/katello/repository/metadata_generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Katello
module Repository
class MetadataGenerate < Actions::EntryAction
def plan(repository, options = {})
return if repository.root.is_container_push && repository.library_instance?
action_subject(repository)
repository.check_ready_to_act!
source_repository = options.fetch(:source_repository, nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def plan(target_repo, smart_proxy, source_repositories, options = {})
plan_action(Actions::Pulp3::Repository::SaveVersion, target_repo, tasks: copy_actions.last.output[:pulp_tasks])
end
end
elsif source_repositories.first.root.is_container_push
copy_action = plan_action(Actions::Pulp3::Repository::CopyContent, source_repositories.first, smart_proxy, target_repo,
copy_all: true)
plan_action(Actions::Pulp3::Repository::SaveVersion, target_repo, tasks: copy_action.output[:pulp_tasks])
else
plan_self(source_version_repo_id: source_repositories.first.id,
target_repo_id: target_repo.id)
Expand Down
7 changes: 5 additions & 2 deletions app/lib/actions/pulp3/orchestration/repository/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ def plan(repository, smart_proxy)
plan_action(Actions::Pulp3::Repository::DeleteDistributions, repository.id, smart_proxy)

if repository.content_view.default?
#we're deleting the library instance, so just delete the whole pulp3 repo
# Container push repositories must be deleted through the distribution
return if repository.root.is_container_push

ianballou marked this conversation as resolved.
Show resolved Hide resolved
# We're deleting the library instance, so just delete the whole pulp3 repo
plan_action(Actions::Pulp3::Repository::Delete, repository.id, smart_proxy)
elsif repository.environment.nil?
#we're deleting the archived instance, so delete the version
# We're deleting the archived instance, so delete the version
plan_action(Actions::Pulp3::Repository::DeleteVersion, repository, smart_proxy)
end
end
Expand Down
10 changes: 10 additions & 0 deletions app/services/katello/pulp3/api/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ def recursive_add_api
def container_push_api
PulpContainerClient::RepositoriesContainerPushApi.new(api_client)
end

def container_push_repo_for_name(name)
# There should be only one repository in Pulp with the requested name
container_push_api.list(name: name)&.results&.first
end

def container_push_distribution_for_repository(repository_href)
# There should be only one repository in Pulp with the requested repository_href
distributions_api.list(repository: repository_href)&.results&.first
end
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions test/actions/katello/environment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ class TestBase < ActiveSupport::TestCase
end
end

class PublishContainerRepositoriesTest < TestBase
let(:action_class) { ::Actions::Katello::Environment::PublishContainerRepositories }
let(:action) { create_action action_class }

let(:environment) { stub }

it 'does not plan for container push library repos' do
container_push_repo = ::Katello::RootRepository.find_by(name: 'busybox').library_instance
container_push_repo.root.update(is_container_push: true)
environment.stubs(:repositories).returns(::Katello::Repository.where(id: container_push_repo.id))
container_push_repo.expects(:set_container_repository_name).never
container_push_repo.expects(:clear_smart_proxy_sync_histories).never
action.stubs(:action_subject).with(environment)

plan_action(action, environment)
refute_action_planned(action, ::Actions::Katello::Repository::InstanceUpdate)
refute_action_planned(action, ::Actions::Katello::Repository::CapsuleSync)
end
end

class DestroyTest < TestBase
let(:action_class) { ::Actions::Katello::Environment::Destroy }
let(:action) { create_action action_class }
Expand Down
Loading
Loading