Commit 758c28bb authored by Michael Kozono's avatar Michael Kozono

Merge branch '259681-move-git-access-class-to-replicator' into 'master'

Geo - Make the Git access class configurable per replicator

See merge request gitlab-org/gitlab!44067
parents f9b83b39 2833223b
...@@ -6,18 +6,19 @@ module EE ...@@ -6,18 +6,19 @@ module EE
prepended do prepended do
include ::Gitlab::Geo::ReplicableModel include ::Gitlab::Geo::ReplicableModel
with_replicator Geo::SnippetRepositoryReplicator with_replicator Geo::SnippetRepositoryReplicator
end end
class_methods do class_methods do
def replicables_for_geo_node def replicables_for_geo_node
# Not implemented yet. Should be responible for selective sync # Not implemented yet. Should be responsible for selective sync
all all
end end
end end
# Geo checks this method in FrameworkRepositorySyncService to avoid snapshotting # Geo checks this method in FrameworkRepositorySyncService to avoid
# repositories using object pools # snapshotting repositories using object pools
def pool_repository def pool_repository
nil nil
end end
......
...@@ -8,6 +8,10 @@ module Geo ...@@ -8,6 +8,10 @@ module Geo
::SnippetRepository ::SnippetRepository
end end
def self.git_access_class
::Gitlab::GitAccessSnippet
end
def self.replication_enabled_by_default? def self.replication_enabled_by_default?
false false
end end
...@@ -16,8 +20,14 @@ module Geo ...@@ -16,8 +20,14 @@ module Geo
false false
end end
def repository # Once https://gitlab.com/gitlab-org/gitlab/-/issues/213021 is fixed
model_record.repository # this method can be removed
def jwt_authentication_header
authorization = ::Gitlab::Geo::RepoSyncRequest.new(
scope: repository.full_path.sub('@snippets', 'snippets')
).authorization
{ "http.#{remote_url}.extraHeader" => "Authorization: #{authorization}" }
end end
# Once https://gitlab.com/gitlab-org/gitlab/-/issues/213021 is fixed # Once https://gitlab.com/gitlab-org/gitlab/-/issues/213021 is fixed
...@@ -27,14 +37,8 @@ module Geo ...@@ -27,14 +37,8 @@ module Geo
url.sub('@snippets', 'snippets') url.sub('@snippets', 'snippets')
end end
# Once https://gitlab.com/gitlab-org/gitlab/-/issues/213021 is fixed def repository
# this method can be removed model_record.repository
def jwt_authentication_header
authorization = ::Gitlab::Geo::RepoSyncRequest.new(
scope: repository.full_path.sub('@snippets', 'snippets')
).authorization
{ "http.#{remote_url}.extraHeader" => "Authorization: #{authorization}" }
end end
end end
end end
...@@ -16,12 +16,13 @@ module Geo ...@@ -16,12 +16,13 @@ module Geo
rescue Gitlab::Shell::Error, Gitlab::Git::BaseError => e rescue Gitlab::Shell::Error, Gitlab::Git::BaseError => e
# In some cases repository does not exist, the only way to know about this is to parse the error text. # In some cases repository does not exist, the only way to know about this is to parse the error text.
# If it does not exist we should consider it as successfully downloaded. # If it does not exist we should consider it as successfully downloaded.
if e.message.include? Gitlab::GitAccessDesign::ERROR_MESSAGES[:no_repo] # rubocop:disable Cop/LineBreakAroundConditionalBlock if e.message.include? Gitlab::GitAccessDesign.error_message(:no_repo)
log_info('Design repository is not found, marking it as successfully synced') log_info('Design repository is not found, marking it as successfully synced')
mark_sync_as_successful(missing_on_primary: true) mark_sync_as_successful(missing_on_primary: true)
else else
fail_registry_sync!('Error syncing design repository', e) fail_registry_sync!('Error syncing design repository', e)
end end
ensure ensure
expire_repository_caches expire_repository_caches
end end
......
...@@ -48,12 +48,13 @@ module Geo ...@@ -48,12 +48,13 @@ module Geo
rescue Gitlab::Shell::Error, Gitlab::Git::BaseError => e rescue Gitlab::Shell::Error, Gitlab::Git::BaseError => e
# In some cases repository does not exist, the only way to know about this is to parse the error text. # In some cases repository does not exist, the only way to know about this is to parse the error text.
# If it does not exist we should consider it as successfully downloaded. # If it does not exist we should consider it as successfully downloaded.
if e.message.include? Gitlab::GitAccess::ERROR_MESSAGES[:no_repo] # rubocop:disable Cop/LineBreakAroundConditionalBlock if e.message.include?(replicator.class.git_access_class.error_message(:no_repo))
log_info('Repository is not found, marking it as successfully synced') log_info('Repository is not found, marking it as successfully synced')
mark_sync_as_successful(missing_on_primary: true) mark_sync_as_successful(missing_on_primary: true)
else else
fail_registry_sync!('Error syncing repository', e) fail_registry_sync!('Error syncing repository', e)
end end
ensure ensure
expire_repository_caches expire_repository_caches
end end
......
...@@ -19,7 +19,7 @@ module Geo ...@@ -19,7 +19,7 @@ module Geo
project.repository.after_create project.repository.after_create
rescue Gitlab::Shell::Error, Gitlab::Git::BaseError => e rescue Gitlab::Shell::Error, Gitlab::Git::BaseError => e
# In some cases repository does not exist, the only way to know about this is to parse the error text. # In some cases repository does not exist, the only way to know about this is to parse the error text.
if e.message.include? Gitlab::GitAccess::ERROR_MESSAGES[:no_repo] # rubocop:disable Cop/LineBreakAroundConditionalBlock if e.message.include?(Gitlab::GitAccessProject.error_message(:no_repo))
if repository_presumably_exists_on_primary? if repository_presumably_exists_on_primary?
log_info('Repository is not found, but it seems to exist on the primary') log_info('Repository is not found, but it seems to exist on the primary')
fail_registry_sync!('Repository is not found', e) fail_registry_sync!('Repository is not found', e)
...@@ -30,6 +30,7 @@ module Geo ...@@ -30,6 +30,7 @@ module Geo
else else
fail_registry_sync!('Error syncing repository', e) fail_registry_sync!('Error syncing repository', e)
end end
ensure ensure
expire_repository_caches expire_repository_caches
execute_housekeeping execute_housekeeping
......
...@@ -16,7 +16,7 @@ module Geo ...@@ -16,7 +16,7 @@ module Geo
rescue Gitlab::Shell::Error, Gitlab::Git::BaseError, Wiki::CouldNotCreateWikiError => e rescue Gitlab::Shell::Error, Gitlab::Git::BaseError, Wiki::CouldNotCreateWikiError => e
# In some cases repository does not exist, the only way to know about this is to parse the error text. # In some cases repository does not exist, the only way to know about this is to parse the error text.
# If it does not exist we should consider it as successfully downloaded. # If it does not exist we should consider it as successfully downloaded.
if e.message.include? Gitlab::GitAccessWiki::ERROR_MESSAGES[:no_repo] # rubocop:disable Cop/LineBreakAroundConditionalBlock if e.message.include?(Gitlab::GitAccessWiki.error_message(:no_repo))
if repository_presumably_exists_on_primary? if repository_presumably_exists_on_primary?
log_info('Wiki is not found, but it seems to exist on the primary') log_info('Wiki is not found, but it seems to exist on the primary')
fail_registry_sync!('Wiki is not found', e) fail_registry_sync!('Wiki is not found', e)
...@@ -27,6 +27,7 @@ module Geo ...@@ -27,6 +27,7 @@ module Geo
else else
fail_registry_sync!('Error syncing wiki repository', e) fail_registry_sync!('Error syncing wiki repository', e)
end end
ensure ensure
expire_repository_caches expire_repository_caches
end end
......
...@@ -121,7 +121,7 @@ RSpec.describe Geo::FrameworkRepositorySyncService, :geo do ...@@ -121,7 +121,7 @@ RSpec.describe Geo::FrameworkRepositorySyncService, :geo do
it 'marks sync as successful if no repository found' do it 'marks sync as successful if no repository found' do
allow(repository).to receive(:fetch_as_mirror) allow(repository).to receive(:fetch_as_mirror)
.with(url_to_repo, remote_name: 'geo', forced: true) .with(url_to_repo, remote_name: 'geo', forced: true)
.and_raise(Gitlab::Shell::Error.new(Gitlab::GitAccess::ERROR_MESSAGES[:no_repo])) .and_raise(Gitlab::Shell::Error.new(Gitlab::GitAccessSnippet::ERROR_MESSAGES[:no_repo]))
subject.execute subject.execute
......
...@@ -113,6 +113,12 @@ RSpec.shared_examples 'a repository replicator' do ...@@ -113,6 +113,12 @@ RSpec.shared_examples 'a repository replicator' do
end end
end end
describe '.git_access_class' do
it 'is implemented' do
expect(replicator.class.git_access_class).to be < Gitlab::GitAccess
end
end
describe '#model' do describe '#model' do
let(:invoke_model) { replicator.class.model } let(:invoke_model) { replicator.class.model }
......
...@@ -47,6 +47,16 @@ module Gitlab ...@@ -47,6 +47,16 @@ module Gitlab
:cmd, :changes :cmd, :changes
attr_accessor :container attr_accessor :container
def self.error_message(key)
self.ancestors.each do |cls|
return cls.const_get('ERROR_MESSAGES', false).fetch(key)
rescue NameError, KeyError
next
end
raise ArgumentError, "No error message defined for #{key}"
end
def initialize(actor, container, protocol, authentication_abilities:, namespace_path: nil, repository_path: nil, redirected_path: nil, auth_result_type: nil) def initialize(actor, container, protocol, authentication_abilities:, namespace_path: nil, repository_path: nil, redirected_path: nil, auth_result_type: nil)
@actor = actor @actor = actor
@container = container @container = container
...@@ -413,13 +423,7 @@ module Gitlab ...@@ -413,13 +423,7 @@ module Gitlab
protected protected
def error_message(key) def error_message(key)
self.class.ancestors.each do |cls| self.class.error_message(key)
return cls.const_get('ERROR_MESSAGES', false).fetch(key)
rescue NameError, KeyError
next
end
raise ArgumentError, "No error message defined for #{key}"
end end
def success_result def success_result
......
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