Skip to content

Commit 10d6e93

Browse files
ibaumbalasankarc
andcommitted
Merge branch 'fix-kas-redis-fallback' into 'master'
Switch KAS to use the new Redis Helper logic See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/7317 Merged-by: Ian Baum <[email protected]> Approved-by: Ian Baum <[email protected]> Approved-by: Andrew Patterson <[email protected]> Reviewed-by: Balasankar 'Balu' C <[email protected]> Reviewed-by: Ian Baum <[email protected]> Co-authored-by: Balasankar 'Balu' C <[email protected]>
2 parents 1b1888f + fdf94ec commit 10d6e93

File tree

8 files changed

+63
-31
lines changed

8 files changed

+63
-31
lines changed

files/gitlab-config-template/gitlab.rb.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,7 @@ external_url 'GENERATED_EXTERNAL_URL'
21432143
# gitlab_kas['redis_port'] = '6379'
21442144
# gitlab_kas['redis_password'] = nil
21452145

2146-
# gitlab_kas['redis_sentinels'] = {}
2146+
# gitlab_kas['redis_sentinels'] = []
21472147
# gitlab_kas['redis_sentinels_master_name'] = nil
21482148
# gitlab_kas['redis_sentinels_password'] = ''
21492149

files/gitlab-cookbooks/gitlab-kas/attributes/default.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
default['gitlab_kas']['redis_host'] = nil
5252
default['gitlab_kas']['redis_port'] = nil
5353
default['gitlab_kas']['redis_password'] = nil
54-
default['gitlab_kas']['redis_sentinels'] = nil
54+
default['gitlab_kas']['redis_sentinels'] = []
5555
default['gitlab_kas']['redis_sentinels_master_name'] = nil
5656
default['gitlab_kas']['redis_sentinels_password'] = nil
5757
default['gitlab_kas']['redis_ssl'] = nil

files/gitlab-cookbooks/gitlab-kas/libraries/gitlab_kas.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ def validate_secrets
107107
end
108108

109109
def parse_redis_settings
110+
# If KAS has separate Redis instance specified, do not copy any other settings
111+
return if Gitlab['gitlab_kas'].key?('redis_host') || Gitlab['gitlab_kas'].key?('redis_socket')
112+
110113
settings_copied_from_gitlab_rails = %w[
111114
redis_socket
112115
redis_host
@@ -120,10 +123,12 @@ def parse_redis_settings
120123
redis_tls_client_key_file
121124
]
122125
settings_copied_from_gitlab_rails.each do |setting|
123-
Gitlab['gitlab_kas'][setting] = Gitlab['gitlab_rails'][setting] || Gitlab['node']['gitlab']['gitlab_rails'][setting] unless Gitlab['gitlab_kas'].key?(setting)
126+
Gitlab['node'].default['gitlab_kas'][setting] = Gitlab['node']['gitlab']['gitlab_rails'][setting]
127+
Gitlab['gitlab_kas'][setting] = Gitlab['gitlab_rails'][setting] unless Gitlab['gitlab_kas'].key?(setting)
124128
end
125129

126-
Gitlab['gitlab_kas']['redis_sentinels_master_name'] = Gitlab['redis']['master_name'] || Gitlab['node']['redis']['master_name'] unless Gitlab['gitlab_kas'].key?('redis_sentinels_master_name')
130+
Gitlab['node'].default['gitlab_kas']['redis_sentinels_master_name'] = Gitlab['node']['redis']['master_name']
131+
Gitlab['gitlab_kas']['redis_sentinels_master_name'] = Gitlab['redis']['master_name'] unless Gitlab['gitlab_kas'].key?('redis_sentinels_master_name')
127132
end
128133

129134
private

files/gitlab-cookbooks/gitlab-kas/recipes/enable.rb

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#
1717
account_helper = AccountHelper.new(node)
1818
omnibus_helper = OmnibusHelper.new(node)
19-
redis_helper = RedisHelper.new(node)
19+
redis_helper = NewRedisHelper::GitlabKAS.new(node)
2020
logfiles_helper = LogfilesHelper.new(node)
2121
logging_settings = logfiles_helper.logging_settings('gitlab-kas')
2222

@@ -26,23 +26,17 @@
2626
gitlab_kas_config_file = File.join(working_dir, 'gitlab-kas-config.yml')
2727
gitlab_kas_authentication_secret_file = File.join(working_dir, 'authentication_secret_file')
2828
gitlab_kas_private_api_authentication_secret_file = File.join(working_dir, 'private_api_authentication_secret_file')
29-
redis_host, redis_port, redis_password = redis_helper.kas_params
30-
redis_password_present = redis_password && !redis_password.empty?
31-
redis_sentinels = node['gitlab_kas']['redis_sentinels']
32-
redis_sentinels_master_name = node['gitlab_kas']['redis_sentinels_master_name']
33-
redis_sentinels_password = node['gitlab_kas']['redis_sentinels_password']
34-
redis_sentinels_password_present = redis_sentinels_password && !redis_sentinels_password.empty?
3529

30+
redis_params = redis_helper.redis_params
31+
32+
redis_password = redis_params[:password]
33+
redis_password_present = redis_password && !redis_password.empty?
3634
gitlab_kas_redis_password_file = File.join(working_dir, 'redis_password_file')
35+
36+
redis_sentinels_password = redis_params[:sentinelPassword]
37+
redis_sentinels_password_present = redis_sentinels_password && !redis_sentinels_password.empty?
3738
gitlab_kas_redis_sentinels_password_file = File.join(working_dir, 'redis_sentinels_password_file')
38-
redis_default_port = URI::Redis::DEFAULT_PORT
39-
redis_network = redis_helper.redis_url.scheme == 'unix' ? 'unix' : 'tcp'
40-
redis_ssl = node['gitlab_kas']['redis_ssl']
41-
redis_address = if redis_network == 'tcp'
42-
"#{redis_host}:#{redis_port || redis_default_port}"
43-
else
44-
node['gitlab_kas']['redis_socket']
45-
end
39+
4640
redis_tls_ca_cert_file = node['gitlab_kas']['redis_tls_ca_cert_file']
4741
redis_tls_client_cert_file = node['gitlab_kas']['redis_tls_client_cert_file']
4842
redis_tls_client_key_file = node['gitlab_kas']['redis_tls_client_key_file']
@@ -119,16 +113,16 @@
119113
node['gitlab_kas'].to_hash.merge(
120114
authentication_secret_file: gitlab_kas_authentication_secret_file,
121115
private_api_authentication_secret_file: gitlab_kas_private_api_authentication_secret_file,
122-
redis_network: redis_network,
123-
redis_address: redis_address,
124-
redis_ssl: redis_ssl,
116+
redis_network: redis_params[:network],
117+
redis_address: redis_params[:address],
118+
redis_ssl: redis_params[:ssl],
125119
redis_tls_ca_cert_file: redis_tls_ca_cert_file,
126120
redis_tls_client_cert_file: redis_tls_client_cert_file,
127121
redis_tls_client_key_file: redis_tls_client_key_file,
128-
redis_default_port: redis_default_port,
122+
redis_default_port: URI::Redis::DEFAULT_PORT,
129123
redis_password_file: redis_password_present ? gitlab_kas_redis_password_file : nil,
130-
redis_sentinels_master_name: redis_sentinels_master_name,
131-
redis_sentinels: redis_sentinels,
124+
redis_sentinels_master_name: redis_params[:sentinelMaster],
125+
redis_sentinels: redis_params[:sentinels],
132126
redis_sentinels_password_file: redis_sentinels_password_present ? gitlab_kas_redis_sentinels_password_file : nil
133127
)
134128
)

files/gitlab-cookbooks/gitlab/libraries/redis_helper.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ def workhorse_params
7373
end
7474
end
7575

76-
def kas_params
77-
redis_params(service_config: @node['gitlab_kas'])
78-
end
79-
8076
def validate_instance_shard_config(instance)
8177
gitlab_rails = @node['gitlab']['gitlab_rails']
8278

files/gitlab-cookbooks/package/libraries/helpers/new_redis_helper/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def redis_url
5252
)
5353
end
5454

55-
uri.to_s
55+
uri
5656
end
5757

5858
private
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module NewRedisHelper
2+
class GitlabKAS < NewRedisHelper::Base
3+
def redis_params
4+
{
5+
network: redis_network,
6+
address: redis_address,
7+
password: redis_credentials[:password],
8+
sentinels: redis_sentinels,
9+
sentinelMaster: master_name,
10+
sentinelPassword: redis_sentinels_password,
11+
ssl: redis_ssl
12+
}
13+
end
14+
15+
private
16+
17+
def redis_network
18+
redis_url.scheme == 'unix' ? 'unix' : 'tcp'
19+
end
20+
21+
def redis_address
22+
redis_network == 'tcp' ? "#{redis_host}:#{redis_port || URI::Redis::DEFAULT_PORT}" : redis_socket
23+
end
24+
25+
def master_name
26+
node_attr['redis_sentinels_master_name']
27+
end
28+
29+
def node_access_keys
30+
%w[gitlab_kas]
31+
end
32+
33+
def support_sentinel_groupname?
34+
true
35+
end
36+
end
37+
end

files/gitlab-cookbooks/package/libraries/helpers/new_redis_helper/gitlab_workhorse.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module NewRedisHelper
22
class GitlabWorkhorse < NewRedisHelper::Base
33
def redis_params
44
{
5-
url: redis_url,
5+
url: redis_url.to_s,
66
password: redis_credentials[:password],
77
sentinels: sentinel_urls,
88
sentinelMaster: master_name,

0 commit comments

Comments
 (0)