Returns empty relatin when replication is disabled

When the replication is disabled we need to remove
the entries from the tracking database.

Returning an empty relation here allows the
Geo::RegistryConsistencyWorker to find the
unused entries and remove them.
parent ebbe7985
......@@ -257,6 +257,7 @@ class GeoNode < ApplicationRecord
end
def container_repositories
return ContainerRepository.none unless Geo::ContainerRepositoryRegistry.replication_enabled?
return ContainerRepository.all unless selective_sync?
ContainerRepository.project_id_in(projects)
......
......@@ -4,6 +4,10 @@ require 'spec_helper'
RSpec.describe Geo::ContainerRepositoryRegistryFinder, :geo do
include ::EE::GeoHelpers
before do
stub_registry_replication_config(enabled: true)
end
context 'when geo_container_registry_ssot_sync is disabled', :geo_fdw do
let!(:secondary) { create(:geo_node) }
let!(:container_repository) { create(:container_repository) }
......
......@@ -759,6 +759,60 @@ RSpec.describe GeoNode, :request_store, :geo, type: :model do
end
end
describe '#container_repositories' do
let_it_be(:synced_group) { create(:group) }
let_it_be(:nested_group) { create(:group, parent: synced_group) }
let_it_be(:synced_project) { create(:project, group: synced_group) }
let_it_be(:synced_project_in_nested_group) { create(:project, group: nested_group) }
let_it_be(:unsynced_project) { create(:project) }
let_it_be(:project_broken_storage) { create(:project, :broken_storage) }
let_it_be(:container_repository_1) { create(:container_repository, project: synced_project) }
let_it_be(:container_repository_2) { create(:container_repository, project: synced_project_in_nested_group) }
let_it_be(:container_repository_3) { create(:container_repository, project: unsynced_project) }
let_it_be(:container_repository_4) { create(:container_repository, project: project_broken_storage) }
before do
stub_registry_replication_config(enabled: true)
end
context 'with registry replication disabled' do
before do
stub_registry_replication_config(enabled: false)
end
it 'returns an empty relation' do
expect(node.container_repositories).to be_empty
end
end
context 'without selective sync' do
it 'returns all container repositories' do
expect(node.container_repositories).to match_array([container_repository_1, container_repository_2, container_repository_3, container_repository_4])
end
end
context 'with selective sync by namespace' do
before do
node.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'excludes container repositories that are not in selectively synced projects' do
expect(node.container_repositories).to match_array([container_repository_1, container_repository_2])
end
end
context 'with selective sync by shard' do
before do
node.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
it 'excludes container repositories that are not in selectively synced shards' do
expect(node.container_repositories).to match_array([container_repository_4])
end
end
end
describe '#job_artifacts' do
context 'when selective sync is enabled' do
it 'applies a CTE statement' do
......
......@@ -9,6 +9,7 @@ RSpec.describe Geo::RegistryConsistencyService, :geo, :use_clean_rails_memory_st
before do
stub_current_geo_node(secondary)
stub_registry_replication_config(enabled: true)
end
def model_class_factory_name(registry_class)
......
......@@ -14,6 +14,7 @@ RSpec.describe Geo::Secondary::RegistryConsistencyWorker, :geo do
before do
stub_current_geo_node(secondary)
stub_registry_replication_config(enabled: true)
end
it_behaves_like 'reenqueuer'
......
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