Merge branch 'gitaly_storage_settings' into 'master'

Render storages in config.toml for Gitaly

Closes #2182

See merge request !1471
This commit is contained in:
Marin Jankovski 2017-04-11 15:39:35 +00:00
commit f3205fa238
5 changed files with 86 additions and 9 deletions

View File

@ -8,6 +8,7 @@ omnibus-gitlab repository.
- Remove deprecated satellites configuration
- Add configuration file for Gitaly
- Add support for Gitaly address per shard
- Add support storages in Gitaly config
9.0.4

View File

@ -945,3 +945,4 @@ default['gitlab']['gitaly']['bin_path'] = "/opt/gitlab/embedded/bin/gitaly"
default['gitlab']['gitaly']['socket_path'] = "#{node['gitlab']['gitaly']['dir']}/gitaly.socket"
default['gitlab']['gitaly']['listen_addr'] = nil
default['gitlab']['gitaly']['prometheus_listen_addr'] = nil
default['gitlab']['gitaly']['storage'] = []

View File

@ -152,6 +152,11 @@ module GitlabRails
end
def parse_gitaly_variables
parse_gitaly_enablement
parse_gitaly_storages
end
def parse_gitaly_enablement
return unless Gitlab['gitlab_rails']['gitaly_enabled'].nil?
gitaly_enabled = Gitlab['gitaly']['enable']
@ -160,6 +165,22 @@ module GitlabRails
Gitlab['gitlab_rails']['gitaly_enabled'] = gitaly_enabled
end
# This method cannot be inside of libraries/gitaly.rb for now
# because storage gets parsed in libraries/gitlab_shell.rb
# and libraries/gitlab_rails.rb
def parse_gitaly_storages
return unless Gitlab['gitaly']['storage'].nil?
storages = []
Gitlab['gitlab_rails']['repositories_storages'].each do |key, value|
storages << {
'name' => key,
'path' => value['path']
}
end
Gitlab['gitaly']['storage'] = storages
end
private
def any_service_role_defined?

View File

@ -16,12 +16,12 @@ listen_addr = '<%= @listen_addr %>'
prometheus_listen_addr = '<%= @prometheus_listen_addr %>'
<% end %>
# [[storage]]
# name = "default"
# path = "/home/git/repositories"
# # You can optionally configure more storages for this Gitaly instance to serve up
#
# [[storage]]
# name = "other_storage"
# path = "/mnt/other_storage/repositories"
<% @storage.each do |shard| %>
[[storage]]
<% if shard.has_key?('name') %>
name = '<%= shard['name'] %>'
<% end %>
<% if shard.has_key?('path') %>
path = '<%= shard['path'] %>'
<% end %>
<% end %>

View File

@ -27,6 +27,11 @@ describe 'gitlab::gitaly' do
expect(chef_run).not_to render_file(config_path)
.with_content("prometheus_listen_addr = 'localhost:9000'")
end
it 'populates gitaly config.toml with default storages' do
expect(chef_run).to render_file(config_path)
.with_content(%r{\[\[storage\]\]\s+name = 'default'\s+path = '/var/opt/gitlab/git-data/repositories'})
end
end
context 'with user settings' do
@ -48,6 +53,55 @@ describe 'gitlab::gitaly' do
expect(chef_run).to render_file(config_path)
.with_content("prometheus_listen_addr = 'localhost:9000'")
end
context 'when using gitaly storage configuration' do
before do
stub_gitlab_rb(
gitaly: {
storage: [
{
'name' => 'default',
'path' => '/tmp/path-1'
},
{
'name' => 'nfs1',
'path' => '/mnt/nfs1'
}
]
}
)
end
it 'populates gitaly config.toml with custom storages' do
expect(chef_run).to render_file(config_path)
.with_content(%r{\[\[storage\]\]\s+name = 'default'\s+path = '/tmp/path-1'})
expect(chef_run).to render_file(config_path)
.with_content(%r{\[\[storage\]\]\s+name = 'nfs1'\s+path = '/mnt/nfs1'})
end
end
context 'when using git_data_dirs storage configuration' do
before do
stub_gitlab_rb(
{
git_data_dirs:
{
'default' => { 'path' => '/tmp/default/git-data' },
'nfs1' => { 'path' => '/mnt/nfs1' }
}
}
)
end
it 'populates gitaly config.toml with custom storages' do
expect(chef_run).to render_file(config_path)
.with_content(%r{\[\[storage\]\]\s+name = 'default'\s+path = '/tmp/default/git-data/repositories'})
expect(chef_run).to render_file(config_path)
.with_content(%r{\[\[storage\]\]\s+name = 'nfs1'\s+path = '/mnt/nfs1/repositories'})
expect(chef_run).not_to render_file(config_path)
.with_content('gitaly_address: "/var/opt/gitlab/gitaly/gitaly.socket"')
end
end
end
context 'when gitaly is disabled' do