diff --git a/doc/development/new-services.md b/doc/development/new-services.md index ac847a87405d4026e780009585e94b8a163256cd_ZG9jL2RldmVsb3BtZW50L25ldy1zZXJ2aWNlcy5tZA==..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZG9jL2RldmVsb3BtZW50L25ldy1zZXJ2aWNlcy5tZA== 100644 --- a/doc/development/new-services.md +++ b/doc/development/new-services.md @@ -56,12 +56,14 @@ #### Naming convention -A service is referred to mainly in two scenarios - when accessing the Chef -attributes corresponding to the service, and when referring to items such as -the users, groups, and paths corresponding to the service. In the attribute names, we use -underscores to differentiate words in the service name, while in other cases we -use hyphens to differentiate them. For example, if we take GitLab Pages, the -attributes are available as `Gitlab['gitlab_pages']` and `node['gitlab_pages']` -while the default directories and paths might look like -`/var/log/gitlab/gitlab-pages` and `/var/opt/gitlab/gitlab-pages`. +A service is referred to mainly in three scenarios: + +1. Accessing the Chef attributes corresponding to the service +1. Referencing items such as users, groups, and paths corresponding to the + service +1. Passing the service name to methods which look up on service properties + similar to the following examples: + - "Is the service enabled?" + - "Get the log ownership details corresponding to this service" + - "Generate runit configuration for this service" @@ -67,8 +69,15 @@ -NOTE: -The migration of existing services to use the underscored form while -accessing Chef attributes is underway. For current status, check the -corresponding [issue](https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/6873). +For the first case mentioned above, we use underscores to differentiate words in +the service name. For the other two cases, we use hyphens to differentiate words +in the service name. Since the configuration is mainly used as a Ruby object, +using underscores instead of hyphens is more flexible (for example, underscores +make it cleaner to use symbols in configuration hashes). + +For example, if we take GitLab Pages, the attributes are available as +`Gitlab['gitlab_pages']` and `node['gitlab_pages']` while the default +directories and paths might look like `/var/log/gitlab/gitlab-pages` and +`/var/opt/gitlab/gitlab-pages`. Similarly, method calls will look like +`service_enabled?("gitlab-pages")`. ### Create a configuration Mash for your service diff --git a/files/gitlab-cookbooks/gitlab-ee/recipes/default.rb b/files/gitlab-cookbooks/gitlab-ee/recipes/default.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWItZWUvcmVjaXBlcy9kZWZhdWx0LnJi..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWItZWUvcmVjaXBlcy9kZWZhdWx0LnJi 100644 --- a/files/gitlab-cookbooks/gitlab-ee/recipes/default.rb +++ b/files/gitlab-cookbooks/gitlab-ee/recipes/default.rb @@ -24,7 +24,7 @@ geo-postgresql geo-logcursor ].each do |service| - node_attribute_key = SettingsDSL::Utils.sanitized_key(service) + node_attribute_key = SettingsDSL::Utils.node_attribute_key(service) if node['gitlab'][node_attribute_key]['enable'] include_recipe "gitlab-ee::#{service}" else diff --git a/files/gitlab-cookbooks/gitlab-pages/recipes/enable.rb b/files/gitlab-cookbooks/gitlab-pages/recipes/enable.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWItcGFnZXMvcmVjaXBlcy9lbmFibGUucmI=..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWItcGFnZXMvcmVjaXBlcy9lbmFibGUucmI= 100644 --- a/files/gitlab-cookbooks/gitlab-pages/recipes/enable.rb +++ b/files/gitlab-cookbooks/gitlab-pages/recipes/enable.rb @@ -59,7 +59,7 @@ ruby_block "re-populate GitLab Pages configuration options" do block do node.consume_attributes( - { 'gitlab_pages' => Gitlab.hyphenate_config_keys['gitlab_pages'] } + { 'gitlab_pages' => Gitlab.sanitized_config['gitlab_pages'] } ) end end diff --git a/files/gitlab-cookbooks/gitlab/libraries/gitlab_rails.rb b/files/gitlab-cookbooks/gitlab/libraries/gitlab_rails.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL2dpdGxhYl9yYWlscy5yYg==..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL2dpdGxhYl9yYWlscy5yYg== 100644 --- a/files/gitlab-cookbooks/gitlab/libraries/gitlab_rails.rb +++ b/files/gitlab-cookbooks/gitlab/libraries/gitlab_rails.rb @@ -167,7 +167,7 @@ next unless Gitlab[left.first][left.last].nil? better_value_from_gitlab_rb = Gitlab[right.first][right.last] - default_from_attributes = Gitlab['node']['gitlab'][SettingsDSL::Utils.sanitized_key(left.first)][left.last] + default_from_attributes = Gitlab['node']['gitlab'][SettingsDSL::Utils.node_attribute_key(left.first)][left.last] Gitlab[left.first][left.last] = better_value_from_gitlab_rb || default_from_attributes end diff --git a/files/gitlab-cookbooks/gitlab/libraries/helpers/base_pg_helper.rb b/files/gitlab-cookbooks/gitlab/libraries/helpers/base_pg_helper.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL2hlbHBlcnMvYmFzZV9wZ19oZWxwZXIucmI=..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL2hlbHBlcnMvYmFzZV9wZ19oZWxwZXIucmI= 100644 --- a/files/gitlab-cookbooks/gitlab/libraries/helpers/base_pg_helper.rb +++ b/files/gitlab-cookbooks/gitlab/libraries/helpers/base_pg_helper.rb @@ -166,7 +166,7 @@ end def node_attributes - node_attribute_key = SettingsDSL::Utils.sanitized_key(service_name) + node_attribute_key = SettingsDSL::Utils.node_attribute_key(service_name) return node['gitlab'][node_attribute_key] if node['gitlab'].key?(node_attribute_key) node[node_attribute_key] @@ -203,7 +203,7 @@ end def bootstrapped? - node_attribute_key = SettingsDSL::Utils.sanitized_key(service_name) + node_attribute_key = SettingsDSL::Utils.node_attribute_key(service_name) # As part of https://gitlab.com/gitlab-org/omnibus-gitlab/issues/2078 services are # being split to their own dedicated cookbooks, and attributes are being moved from @@ -246,7 +246,7 @@ end def database_version - node_attribute_key = SettingsDSL::Utils.sanitized_key(service_name) + node_attribute_key = SettingsDSL::Utils.node_attribute_key(service_name) # As part of https://gitlab.com/gitlab-org/omnibus-gitlab/issues/2078 services are # being split to their own dedicated cookbooks, and attributes are being moved from diff --git a/files/gitlab-cookbooks/gitlab/libraries/logfiles_helper.rb b/files/gitlab-cookbooks/gitlab/libraries/logfiles_helper.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL2xvZ2ZpbGVzX2hlbHBlci5yYg==..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL2xvZ2ZpbGVzX2hlbHBlci5yYg== 100644 --- a/files/gitlab-cookbooks/gitlab/libraries/logfiles_helper.rb +++ b/files/gitlab-cookbooks/gitlab/libraries/logfiles_helper.rb @@ -65,7 +65,7 @@ def service_parent(service) available_settings = Gitlab.settings - setting_name = SettingsDSL::Utils.underscored_form(service) + setting_name = SettingsDSL::Utils.node_attribute_key(service) raise "Service #{service} is not a valid service." unless available_settings.include?(setting_name) @@ -82,7 +82,7 @@ node['spamcheck']['classifier'] end else - node_attribute_key = SettingsDSL::Utils.sanitized_key(service) + node_attribute_key = SettingsDSL::Utils.node_attribute_key(service) if parent = service_parent(service) node[parent][node_attribute_key] else @@ -165,7 +165,9 @@ end def logging_settings(service) - service = SettingsDSL::Utils.hyphenated_form(service) + # Ensure we are using the hyphenated form of the service name as that is + # expected by various methods being called here + service = SettingsDSL::Utils.service_name(service) { log_directory: logdir(service), log_directory_owner: logdir_owner(service), diff --git a/files/gitlab-cookbooks/gitlab/libraries/logging.rb b/files/gitlab-cookbooks/gitlab/libraries/logging.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL2xvZ2dpbmcucmI=..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL2xvZ2dpbmcucmI= 100644 --- a/files/gitlab-cookbooks/gitlab/libraries/logging.rb +++ b/files/gitlab-cookbooks/gitlab/libraries/logging.rb @@ -64,7 +64,7 @@ puma storage-check ).each do |runit_sv| - Gitlab[SettingsDSL::Utils.underscored_form(runit_sv)]['svlogd_prefix'] ||= "#{Gitlab['node']['hostname']} #{runit_sv}: " + Gitlab[SettingsDSL::Utils.node_attribute_key(runit_sv)]['svlogd_prefix'] ||= "#{Gitlab['node']['hostname']} #{runit_sv}: " end end end diff --git a/files/gitlab-cookbooks/gitlab/libraries/nginx.rb b/files/gitlab-cookbooks/gitlab/libraries/nginx.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL25naW54LnJi..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL25naW54LnJi 100644 --- a/files/gitlab-cookbooks/gitlab/libraries/nginx.rb +++ b/files/gitlab-cookbooks/gitlab/libraries/nginx.rb @@ -48,5 +48,5 @@ # This conditional is required until all services are extracted to # their own cookbook. Mattermost exists directly on node while # others exists on node['gitlab'] - service_name_key = SettingsDSL::Utils.sanitized_key(right.first) + node_attribute_key = SettingsDSL::Utils.node_attribute_key(right.first) service_attribute_key = right.last @@ -52,4 +52,4 @@ service_attribute_key = right.last - default_set_gitlab_port = if Gitlab['node']['gitlab'].key?(service_name_key) - Gitlab['node']['gitlab'][service_name_key][service_attribute_key] + default_set_gitlab_port = if Gitlab['node']['gitlab'].key?(node_attribute_key) + Gitlab['node']['gitlab'][node_attribute_key][service_attribute_key] else @@ -55,5 +55,5 @@ else - Gitlab['node'][service_name_key][service_attribute_key] + Gitlab['node'][node_attribute_key][service_attribute_key] end user_set_gitlab_port = Gitlab[right.first][right.last] @@ -75,7 +75,7 @@ def parse_proxy_headers(app, ssl, allow_other_schemes = false) values_from_gitlab_rb = Gitlab[app]['proxy_set_headers'] - dashed_app = SettingsDSL::Utils.sanitized_key(app) + dashed_app = SettingsDSL::Utils.node_attribute_key(app) default_from_attributes = Gitlab['node']['gitlab'][dashed_app]['proxy_set_headers'].to_hash default_from_attributes['X-Forwarded-Ssl'] = 'on' if ssl diff --git a/files/gitlab-cookbooks/gitlab/recipes/default.rb b/files/gitlab-cookbooks/gitlab/recipes/default.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvcmVjaXBlcy9kZWZhdWx0LnJi..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvcmVjaXBlcy9kZWZhdWx0LnJi 100644 --- a/files/gitlab-cookbooks/gitlab/recipes/default.rb +++ b/files/gitlab-cookbooks/gitlab/recipes/default.rb @@ -123,7 +123,7 @@ praefect gitlab-kas ).each do |service| - node_attribute_key = SettingsDSL::Utils.sanitized_key(service) + node_attribute_key = SettingsDSL::Utils.node_attribute_key(service) if node[node_attribute_key]['enable'] include_recipe "#{service}::enable" else @@ -161,7 +161,7 @@ bootstrap storage-check ].each do |service| - node_attribute_key = SettingsDSL::Utils.sanitized_key(service) + node_attribute_key = SettingsDSL::Utils.node_attribute_key(service) if node["gitlab"][node_attribute_key]["enable"] include_recipe "gitlab::#{service}" else @@ -176,12 +176,8 @@ gitlab-kas letsencrypt ).each do |cookbook| - # `service_name` variable represents the key used to access the node - # attributes corresponding to the service. Will be in underscored or - # hyphenated form depending on whether it has been migrated to use the - # underscored form yet or not. - service_name = SettingsDSL::Utils.sanitized_key(cookbook) - if node[service_name]["enable"] + node_attribute_key = SettingsDSL::Utils.node_attribute_key(cookbook) + if node[node_attribute_key]["enable"] include_recipe "#{cookbook}::enable" else include_recipe "#{cookbook}::disable" diff --git a/files/gitlab-cookbooks/gitlab/templates/default/remote_syslog.yml.erb b/files/gitlab-cookbooks/gitlab/templates/default/remote_syslog.yml.erb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvdGVtcGxhdGVzL2RlZmF1bHQvcmVtb3RlX3N5c2xvZy55bWwuZXJi..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvdGVtcGxhdGVzL2RlZmF1bHQvcmVtb3RlX3N5c2xvZy55bWwuZXJi 100644 --- a/files/gitlab-cookbooks/gitlab/templates/default/remote_syslog.yml.erb +++ b/files/gitlab-cookbooks/gitlab/templates/default/remote_syslog.yml.erb @@ -1,6 +1,6 @@ files: <% @services.each do |service| %> - <% node_attribute_key = SettingsDSL::Utils.sanitized_key(service) %> + <% node_attribute_key = SettingsDSL::Utils.node_attribute_key(service) %> <% log_dir = LogfilesHelper.new(node).logdir(service) %> - <%= File.join(log_dir, "*.log") %> <% end %> diff --git a/files/gitlab-cookbooks/mattermost/recipes/enable.rb b/files/gitlab-cookbooks/mattermost/recipes/enable.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9tYXR0ZXJtb3N0L3JlY2lwZXMvZW5hYmxlLnJi..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9tYXR0ZXJtb3N0L3JlY2lwZXMvZW5hYmxlLnJi 100644 --- a/files/gitlab-cookbooks/mattermost/recipes/enable.rb +++ b/files/gitlab-cookbooks/mattermost/recipes/enable.rb @@ -116,7 +116,7 @@ ruby_block "populate mattermost configuration options" do block do node.consume_attributes( - { 'mattermost' => Gitlab.hyphenate_config_keys['mattermost'] } + { 'mattermost' => Gitlab.sanitized_config['mattermost'] } ) end end diff --git a/files/gitlab-cookbooks/monitoring/libraries/prometheus.rb b/files/gitlab-cookbooks/monitoring/libraries/prometheus.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9tb25pdG9yaW5nL2xpYnJhcmllcy9wcm9tZXRoZXVzLnJi..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9tb25pdG9yaW5nL2xpYnJhcmllcy9wcm9tZXRoZXVzLnJi 100644 --- a/files/gitlab-cookbooks/monitoring/libraries/prometheus.rb +++ b/files/gitlab-cookbooks/monitoring/libraries/prometheus.rb @@ -26,7 +26,7 @@ module Prometheus class << self def services - Services.find_by_group('monitoring').map { |name| SettingsDSL::Utils.sanitized_key(name) } + Services.find_by_group('monitoring').map { |name| SettingsDSL::Utils.node_attribute_key(name) } end def parse_variables @@ -469,7 +469,7 @@ 'consul_sd_configs' => [{ 'services' => ["#{exporter}-exporter"] }] } else - node_attribute_key = SettingsDSL::Utils.sanitized_key("#{exporter}-exporter") + node_attribute_key = SettingsDSL::Utils.node_attribute_key("#{exporter}-exporter") default_config = Gitlab['node']['monitoring'][node_attribute_key].to_hash user_config = Gitlab["#{exporter}_exporter"] diff --git a/files/gitlab-cookbooks/monitoring/recipes/default.rb b/files/gitlab-cookbooks/monitoring/recipes/default.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9tb25pdG9yaW5nL3JlY2lwZXMvZGVmYXVsdC5yYg==..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9tb25pdG9yaW5nL3JlY2lwZXMvZGVmYXVsdC5yYg== 100644 --- a/files/gitlab-cookbooks/monitoring/recipes/default.rb +++ b/files/gitlab-cookbooks/monitoring/recipes/default.rb @@ -17,7 +17,7 @@ # Configure Prometheus Services Prometheus.services.each do |service| - cookbook_name = SettingsDSL::Utils.hyphenated_form(service) + cookbook_name = SettingsDSL::Utils.service_name(service) if node['monitoring'][service]['enable'] include_recipe "monitoring::#{cookbook_name}" else diff --git a/files/gitlab-cookbooks/monitoring/recipes/grafana.rb b/files/gitlab-cookbooks/monitoring/recipes/grafana.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9tb25pdG9yaW5nL3JlY2lwZXMvZ3JhZmFuYS5yYg==..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9tb25pdG9yaW5nL3JlY2lwZXMvZ3JhZmFuYS5yYg== 100644 --- a/files/gitlab-cookbooks/monitoring/recipes/grafana.rb +++ b/files/gitlab-cookbooks/monitoring/recipes/grafana.rb @@ -114,7 +114,7 @@ ruby_block "populate Grafana configuration options" do block do node.consume_attributes( - { 'monitoring' => { 'grafana' => Gitlab.hyphenate_config_keys['monitoring']['grafana'] } } + { 'monitoring' => { 'grafana' => Gitlab.sanitized_config['monitoring']['grafana'] } } ) end end diff --git a/files/gitlab-cookbooks/package/libraries/config/roles/geo_secondary.rb b/files/gitlab-cookbooks/package/libraries/config/roles/geo_secondary.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9jb25maWcvcm9sZXMvZ2VvX3NlY29uZGFyeS5yYg==..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9jb25maWcvcm9sZXMvZ2VvX3NlY29uZGFyeS5yYg== 100644 --- a/files/gitlab-cookbooks/package/libraries/config/roles/geo_secondary.rb +++ b/files/gitlab-cookbooks/package/libraries/config/roles/geo_secondary.rb @@ -43,7 +43,7 @@ # If the service is explicitly enabled return true if Gitlab[svc]['enable'] # If the service is auto-enabled, and not explicitly disabled - return true if Gitlab[:node]['gitlab'][SettingsDSL::Utils.sanitized_key(svc)]['enable'] && Gitlab[svc]['enable'].nil? + return true if Gitlab[:node]['gitlab'][SettingsDSL::Utils.node_attribute_key(svc)]['enable'] && Gitlab[svc]['enable'].nil? end return true if Gitlab['gitaly']['enable'] || (Gitlab[:node]['gitaly']['enable'] && Gitlab['gitaly']['enable'].nil?) diff --git a/files/gitlab-cookbooks/package/libraries/deprecations.rb b/files/gitlab-cookbooks/package/libraries/deprecations.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9kZXByZWNhdGlvbnMucmI=..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9kZXByZWNhdGlvbnMucmI= 100644 --- a/files/gitlab-cookbooks/package/libraries/deprecations.rb +++ b/files/gitlab-cookbooks/package/libraries/deprecations.rb @@ -542,5 +542,5 @@ config_keys = deprecation[:config_keys].dup config_keys.shift if ATTRIBUTE_BLOCKS.include?(config_keys[0]) key = if config_keys.length == 1 - SettingsDSL::Utils.underscored_form(config_keys[0]) + SettingsDSL::Utils.node_attribute_key(config_keys[0]) elsif config_keys.first.eql?('roles') @@ -546,3 +546,3 @@ elsif config_keys.first.eql?('roles') - "#{SettingsDSL::Utils.underscored_form(config_keys[1])}_role" + "#{SettingsDSL::Utils.node_attribute_key(config_keys[1])}_role" else @@ -548,5 +548,5 @@ else - "#{SettingsDSL::Utils.underscored_form(config_keys[0])}['#{config_keys.drop(1).join("']['")}']" + "#{SettingsDSL::Utils.node_attribute_key(config_keys[0])}['#{config_keys.drop(1).join("']['")}']" end if type == :deprecation diff --git a/files/gitlab-cookbooks/package/libraries/helpers/roles_helper.rb b/files/gitlab-cookbooks/package/libraries/helpers/roles_helper.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9oZWxwZXJzL3JvbGVzX2hlbHBlci5yYg==..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9oZWxwZXJzL3JvbGVzX2hlbHBlci5yYg== 100644 --- a/files/gitlab-cookbooks/package/libraries/helpers/roles_helper.rb +++ b/files/gitlab-cookbooks/package/libraries/helpers/roles_helper.rb @@ -24,7 +24,7 @@ # convert hyphens to underscores to avoid user errors # split or space or comma (allow both to avoid user errors) - active = [Gitlab['roles']].flatten.map { |role| SettingsDSL::Utils.underscored_form(role) } + active = [Gitlab['roles']].flatten.map { |role| SettingsDSL::Utils.node_attribute_key(role) } valid_roles = Gitlab.available_roles.keys.map { |key| "#{key}_role" } invalid_roles = active - valid_roles diff --git a/files/gitlab-cookbooks/package/libraries/helpers/services_helper.rb b/files/gitlab-cookbooks/package/libraries/helpers/services_helper.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9oZWxwZXJzL3NlcnZpY2VzX2hlbHBlci5yYg==..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9oZWxwZXJzL3NlcnZpY2VzX2hlbHBlci5yYg== 100644 --- a/files/gitlab-cookbooks/package/libraries/helpers/services_helper.rb +++ b/files/gitlab-cookbooks/package/libraries/helpers/services_helper.rb @@ -233,7 +233,7 @@ # @param [String] service_name # @return [Array] def service_attribute_path(service_name) - service = SettingsDSL::Utils.sanitized_key(service_name) + service = SettingsDSL::Utils.node_attribute_key(service_name) return ['monitoring', service] if Gitlab[:node]['monitoring']&.attribute?(service) return [service] if Gitlab[:node].attribute?(service) diff --git a/files/gitlab-cookbooks/package/libraries/omnibus_helper.rb b/files/gitlab-cookbooks/package/libraries/omnibus_helper.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9vbW5pYnVzX2hlbHBlci5yYg==..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9vbW5pYnVzX2hlbHBlci5yYg== 100644 --- a/files/gitlab-cookbooks/package/libraries/omnibus_helper.rb +++ b/files/gitlab-cookbooks/package/libraries/omnibus_helper.rb @@ -26,7 +26,7 @@ end def service_enabled?(service_name) - node_attribute_key = SettingsDSL::Utils.sanitized_key(service_name) + node_attribute_key = SettingsDSL::Utils.node_attribute_key(service_name) # As part of https://gitlab.com/gitlab-org/omnibus-gitlab/issues/2078 services are # being split to their own dedicated cookbooks, and attributes are being moved from # node['gitlab'][service_name] to node[service_name]. Until they've been moved, we diff --git a/files/gitlab-cookbooks/package/libraries/settings_dsl.rb b/files/gitlab-cookbooks/package/libraries/settings_dsl.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9zZXR0aW5nc19kc2wucmI=..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9zZXR0aW5nc19kc2wucmI= 100644 --- a/files/gitlab-cookbooks/package/libraries/settings_dsl.rb +++ b/files/gitlab-cookbooks/package/libraries/settings_dsl.rb @@ -25,43 +25,6 @@ require_relative 'gitlab_cluster' module SettingsDSL - SERVICES_SKIP_HYPHENATION = %w[ - gitlab_pages - gitlab_sshd - node_exporter - redis_exporter - postgres_exporter - pgbouncer_exporter - gitlab_shell - suggested_reviewers - gitlab_exporter - remote_syslog - gitlab_workhorse - mattermost_nginx - pages_nginx - registry_nginx - gitlab_kas_nginx - gitlab_kas - geo_secondary - geo_logcursor - geo_postgresql - gitlab_rails - external_url - gitlab_kas_external_url - mattermost_external_url - pages_external_url - registry_external_url - gitlab_ci - high_availability - manage_accounts - manage_storage_directories - omnibus_gitconfig - prometheus_monitoring - runtime_dir - storage_check - web_server - ].freeze - def self.extended(base) # Setup getter/setters for roles and settings class << base @@ -163,7 +126,7 @@ end end - def hyphenate_config_keys + def sanitized_config results = { "gitlab" => {}, "roles" => {}, "monitoring" => {} } # Add the settings to the results @@ -172,8 +135,8 @@ target = value[:parent] ? results[value[:parent]] : results - target[Utils.sanitized_key(key)] = Gitlab[key] + target[Utils.node_attribute_key(key)] = Gitlab[key] end # Add the roles the the results @available_roles.each do |key, value| @@ -176,8 +139,8 @@ end # Add the roles the the results @available_roles.each do |key, value| - results['roles'][Utils.sanitized_key(key)] = Gitlab["#{key}_role"] + results['roles'][Utils.node_attribute_key(key)] = Gitlab["#{key}_role"] end results @@ -235,8 +198,8 @@ handler = value.handler handler.parse_variables if handler.respond_to?(:parse_variables) end - # The last step is to convert underscores to hyphens in top-level keys - strip_nils(hyphenate_config_keys) + + strip_nils(sanitized_config) end def strip_nils(attributes) @@ -292,7 +255,8 @@ class Utils class << self - def hyphenated_form(key) - key.tr('_', '-') + # In service names, words are seperated with a hyphen + def service_name(service) + service.tr('_', '-') end @@ -297,13 +261,9 @@ end - def underscored_form(key) - key.tr('-', '_') - end - - def sanitized_key(key) - return underscored_form(key) if SERVICES_SKIP_HYPHENATION.include?(underscored_form(key)) - - hyphenated_form(key) + # Node attributes corresponding to a service are formatted by replacing + # hyphens in the service names with underscores + def node_attribute_key(service) + service.tr('-', '_') end end end diff --git a/files/gitlab-cookbooks/pgbouncer/libraries/pgbouncer_helper.rb b/files/gitlab-cookbooks/pgbouncer/libraries/pgbouncer_helper.rb index ac847a87405d4026e780009585e94b8a163256cd_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wZ2JvdW5jZXIvbGlicmFyaWVzL3BnYm91bmNlcl9oZWxwZXIucmI=..d14fa645b7745b007b4bc2c75ca56299f75eb928_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9wZ2JvdW5jZXIvbGlicmFyaWVzL3BnYm91bmNlcl9oZWxwZXIucmI= 100644 --- a/files/gitlab-cookbooks/pgbouncer/libraries/pgbouncer_helper.rb +++ b/files/gitlab-cookbooks/pgbouncer/libraries/pgbouncer_helper.rb @@ -45,7 +45,7 @@ end def create_pgbouncer_user?(db) - node_attribute_key = SettingsDSL::Utils.sanitized_key(db) + node_attribute_key = SettingsDSL::Utils.node_attribute_key(db) # As part of https://gitlab.com/gitlab-org/omnibus-gitlab/issues/2078 services are # being split to their own dedicated cookbooks, and attributes are being moved from # node['gitlab'][service_name] to node[service_name]. Until they've been moved, we diff --git a/spec/chef/cookbooks/package/libraries/config/gitlab_spec.rb b/spec/chef/cookbooks/package/libraries/config/gitlab_spec.rb index ac847a87405d4026e780009585e94b8a163256cd_c3BlYy9jaGVmL2Nvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9jb25maWcvZ2l0bGFiX3NwZWMucmI=..d14fa645b7745b007b4bc2c75ca56299f75eb928_c3BlYy9jaGVmL2Nvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9jb25maWcvZ2l0bGFiX3NwZWMucmI= 100644 --- a/spec/chef/cookbooks/package/libraries/config/gitlab_spec.rb +++ b/spec/chef/cookbooks/package/libraries/config/gitlab_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'chef_helper' RSpec.describe Gitlab do context 'when using an attribute_block' do @@ -7,10 +7,10 @@ expect(Gitlab.attribute('test_attribute')[:parent]).to eq 'gitlab' end expect(Gitlab['test_attribute']).not_to be_nil - expect(Gitlab.hyphenate_config_keys['gitlab']).to include('test-attribute') + expect(Gitlab.sanitized_config['gitlab']).to include('test_attribute') end end it 'sets top level attributes when no parent is provided' do Gitlab.attribute('test_attribute') expect(Gitlab['test_attribute']).not_to be_nil @@ -11,12 +11,12 @@ end end it 'sets top level attributes when no parent is provided' do Gitlab.attribute('test_attribute') expect(Gitlab['test_attribute']).not_to be_nil - expect(Gitlab.hyphenate_config_keys).to include('test-attribute') + expect(Gitlab.sanitized_config).to include('test_attribute') end it 'properly defines roles' do role = Gitlab.role('test_node') expect(Gitlab['test_node_role']).not_to be_nil @@ -18,9 +18,9 @@ end it 'properly defines roles' do role = Gitlab.role('test_node') expect(Gitlab['test_node_role']).not_to be_nil - expect(Gitlab.hyphenate_config_keys['roles']).to include('test-node') + expect(Gitlab.sanitized_config['roles']).to include('test_node') expect(role).to include(manage_services: true) end @@ -41,7 +41,7 @@ allow(Gitlab).to receive(:[]).with('edition').and_return(:ce) expect(Gitlab.ee_attribute('test_attribute')[:ee]).to eq true expect(Gitlab['test_attribute']).not_to be_nil - expect(Gitlab.hyphenate_config_keys).not_to include('test-attribute') + expect(Gitlab.sanitized_config).not_to include('test_attribute') end it 'enables ee attributes when EE is enabled' do @@ -49,7 +49,7 @@ allow(Gitlab).to receive(:[]).with('edition').and_return(:ee) expect(Gitlab.ee_attribute('test_attribute')[:ee]).to eq true expect(Gitlab['test_attribute']).not_to be_nil - expect(Gitlab.hyphenate_config_keys).to include('test-attribute') + expect(Gitlab.sanitized_config).to include('test_attribute') end it 'sorts attributes by sequence' do diff --git a/spec/chef/cookbooks/package/libraries/omnibus_helper_spec.rb b/spec/chef/cookbooks/package/libraries/omnibus_helper_spec.rb index ac847a87405d4026e780009585e94b8a163256cd_c3BlYy9jaGVmL2Nvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9vbW5pYnVzX2hlbHBlcl9zcGVjLnJi..d14fa645b7745b007b4bc2c75ca56299f75eb928_c3BlYy9jaGVmL2Nvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9vbW5pYnVzX2hlbHBlcl9zcGVjLnJi 100644 --- a/spec/chef/cookbooks/package/libraries/omnibus_helper_spec.rb +++ b/spec/chef/cookbooks/package/libraries/omnibus_helper_spec.rb @@ -3,13 +3,6 @@ require 'chef_helper' require 'time' -module SettingsDSL - original_skip_hyphenation_services = SettingsDSL::SERVICES_SKIP_HYPHENATION.dup - SettingsDSL.send(:remove_const, :SERVICES_SKIP_HYPHENATION) - - SERVICES_SKIP_HYPHENATION = original_skip_hyphenation_services + %w[old_service new_service another_service] -end - RSpec.describe OmnibusHelper do cached(:chef_run) { converge_config } let(:node) { chef_run.node } diff --git a/spec/chef/cookbooks/package/libraries/settings_dsl_spec.rb b/spec/chef/cookbooks/package/libraries/settings_dsl_spec.rb index ac847a87405d4026e780009585e94b8a163256cd_c3BlYy9jaGVmL2Nvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9zZXR0aW5nc19kc2xfc3BlYy5yYg==..d14fa645b7745b007b4bc2c75ca56299f75eb928_c3BlYy9jaGVmL2Nvb2tib29rcy9wYWNrYWdlL2xpYnJhcmllcy9zZXR0aW5nc19kc2xfc3BlYy5yYg== 100644 --- a/spec/chef/cookbooks/package/libraries/settings_dsl_spec.rb +++ b/spec/chef/cookbooks/package/libraries/settings_dsl_spec.rb @@ -3,23 +3,10 @@ RSpec.describe SettingsDSL::Utils do subject { described_class } - describe '.hyphenated_form' do - it 'returns original string if no underscore exists' do - expect(subject.hyphenated_form('foo-bar')).to eq('foo-bar') - end - - it 'returns string with underscores replaced by hyphens' do - expect(subject.hyphenated_form('foo_bar')).to eq('foo-bar') - end - end - - describe '.underscored_form' do - it 'returns original string if no hyphen exists' do - expect(subject.underscored_form('foo_bar')).to eq('foo_bar') - end - - it 'returns string with hyphens replaced by underscores' do - expect(subject.underscored_form('foo-bar')).to eq('foo_bar') + describe '.service_name' do + it 'returns hyphenated form of service name' do + expect(subject.service_name('foo-bar')).to eq('foo-bar') + expect(subject.service_name('foo_bar')).to eq('foo-bar') end end @@ -23,51 +10,10 @@ end end - describe '.sanitized_key' do - it 'returns underscored form for services specified to skip hyphenation' do - [ - %w[gitlab-pages gitlab_pages], - %w[gitlab-sshd gitlab_sshd], - %w[node-exporter node_exporter], - %w[redis-exporter redis_exporter], - %w[postgres-exporter postgres_exporter], - %w[pgbouncer-exporter pgbouncer_exporter], - %w[gitlab-shell gitlab_shell], - %w[suggested-reviewers suggested_reviewers], - %w[gitlab-exporter gitlab_exporter], - %w[remote-syslog remote_syslog], - %w[gitlab-workhorse gitlab_workhorse], - %w[gitlab-kas gitlab_kas], - %w[geo-secondary geo_secondary], - %w[geo-logcursor geo_logcursor], - %w[geo-postgresql geo_postgresql], - %w[gitlab-rails gitlab_rails], - %w[external-url external_url], - %w[gitlab-kas-external-url gitlab_kas_external_url], - %w[mattermost-external-url mattermost_external_url], - %w[pages-external-url pages_external_url], - %w[registry-external-url registry_external_url], - %w[gitlab-ci gitlab_ci], - %w[high-availability high_availability], - %w[manage-accounts manage_accounts], - %w[manage-storage-directories manage_storage_directories], - %w[omnibus-gitconfig omnibus_gitconfig], - %w[prometheus-monitoring prometheus_monitoring], - %w[runtime-dir runtime_dir], - %w[storage-check storage_check], - %w[web-server web_server], - ].each do |input, output| - expect(subject.sanitized_key(input)).to eq(output) - end - end - - it 'returns hyphenated form for services not specified to skip hyphenation' do - [ - %w[foo-bar foo-bar], - %w[foo_bar foo-bar], - ].each do |input, output| - expect(subject.sanitized_key(input)).to eq(output) - end + describe '.node_attribute_key' do + it 'returns underscored form of service name' do + expect(subject.node_attribute_key('foo-bar')).to eq('foo_bar') + expect(subject.node_attribute_key('foo_bar')).to eq('foo_bar') end end