From a25e251cf42a6f2b09d69f587714e118eb401214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Cunha?= Date: Wed, 5 Nov 2025 18:22:16 +0100 Subject: [PATCH] Adds support for registry.database.enabled: 'prefer' Changelog: added --- charts/registry/templates/_database.tpl | 34 ++++++++++++++++++++++++- doc/charts/registry/_index.md | 4 +-- templates/NOTES.txt | 3 ++- templates/_checkConfig_registry.tpl | 13 ++++++---- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/charts/registry/templates/_database.tpl b/charts/registry/templates/_database.tpl index e2ff01b24c..963c726dc9 100644 --- a/charts/registry/templates/_database.tpl +++ b/charts/registry/templates/_database.tpl @@ -1,3 +1,35 @@ +{{/* +Return the database.enabled value as a string. +Converts boolean values to strings for backward compatibility. +Accepts: true, false, "true", "false", "prefer" +*/}} +{{- define "registry.database.enabled.value" -}} +{{- $enabled := .Values.database.enabled -}} +{{- if kindIs "bool" $enabled -}} +{{- if $enabled -}} +"true" +{{- else -}} +"false" +{{- end -}} +{{- else -}} +{{- $enabled | quote -}} +{{- end -}} +{{- end -}} + +{{/* +Check if database is enabled (returns true for boolean true, "true", or "prefer") +*/}} +{{- define "registry.database.isEnabled" -}} +{{- $enabled := .Values.database.enabled -}} +{{- if kindIs "bool" $enabled -}} +{{- $enabled -}} +{{- else if or (eq $enabled "true") (eq $enabled "prefer") -}} +true +{{- else -}} +false +{{- end -}} +{{- end -}} + {{/* Return database configuration, if settings available. */}} @@ -5,7 +37,7 @@ Return database configuration, if settings available. {{/*Need to use enabled or configure flags for backwards compatibility*/}} {{- if or .Values.database.enabled .Values.database.configure }} database: - enabled: {{ .Values.database.enabled }} + enabled: {{ include "registry.database.enabled.value" . }} host: {{ default (include "gitlab.psql.host" .) .Values.database.host | quote }} port: {{ default (include "gitlab.psql.port" .) .Values.database.port }} user: {{ include "registry.database.username" . }} diff --git a/doc/charts/registry/_index.md b/doc/charts/registry/_index.md index d8b40c6f77..c00fdbcd72 100644 --- a/doc/charts/registry/_index.md +++ b/doc/charts/registry/_index.md @@ -227,7 +227,7 @@ If you chose to deploy this chart as a standalone, remove the `registry` at the | `profiling.stackdriver.service` | `RELEASE-registry` (templated Service name) | Name of the Stackdriver service to record profiles under | | `profiling.stackdriver.projectid` | GCP project where running | GCP project to report profiles to | | `database.configure` | `false` | Populate database configuration in the registry chart without enabling it. Required when [importing an existing registry](metadata_database.md#enable-for-and-import-existing-registries). | -| `database.enabled` | `false` | Enable metadata database. This is an experimental feature and must not be used in production environments. | +| `database.enabled` | `false` | Enable metadata database. Accepts boolean values (`true`, `false`) or string values (`"true"`, `"false"`, `"prefer"`). Boolean values are automatically converted to strings for backward compatibility. | | `database.host` | `global.psql.host` | The database server hostname. | | `database.port` | `global.psql.port` | The database server port. | | `database.user` | | The database username. | @@ -1113,7 +1113,7 @@ This feature requires PostgreSQL 13 or newer. ```yaml database: - enabled: true + enabled: "true" # Can also be true (boolean), "false", or "prefer" host: registry.db.example.com port: 5432 user: registry diff --git a/templates/NOTES.txt b/templates/NOTES.txt index 9e854f4ee4..dbe6b92399 100644 --- a/templates/NOTES.txt +++ b/templates/NOTES.txt @@ -19,7 +19,8 @@ https://docs.gitlab.com/charts/installation/index.html#use-the-reference-archite The minimum required version of PostgreSQL is now 16. See https://docs.gitlab.com/charts/installation/upgrade.html for more details. {{- /* If the Container Registry metadata database is enabled */}} -{{- if eq .Values.registry.database.enabled true }} +{{- $dbEnabled := include "registry.database.isEnabled" . -}} +{{- if eq $dbEnabled "true" }} {{ $WARNING }} The Container Registry metadata database has been enabled. Carefully review the documentation https://docs.gitlab.com/charts/charts/registry/metadata_database.html before enabling the registry database in production! diff --git a/templates/_checkConfig_registry.tpl b/templates/_checkConfig_registry.tpl index bfa4abe319..c77c390f80 100644 --- a/templates/_checkConfig_registry.tpl +++ b/templates/_checkConfig_registry.tpl @@ -50,7 +50,8 @@ Ensure Registry database load balancing is configured properly and dependencies */}} {{- define "gitlab.checkConfig.registry.database.loadBalancing" -}} {{- if $.Values.registry.database.loadBalancing.enabled }} - {{- if not $.Values.registry.database.enabled }} + {{- $dbEnabled := include "registry.database.isEnabled" $ -}} + {{- if ne $dbEnabled "true" }} registry: Enabling database load balancing requires the metadata database to be enabled. See https://docs.gitlab.com/charts/charts/registry#load-balancing @@ -75,7 +76,8 @@ Ensure Registry database metrics is configured properly and dependencies are met */}} {{- define "gitlab.checkConfig.registry.database.metrics" -}} {{- if $.Values.registry.database.metrics.enabled }} - {{- if not $.Values.registry.database.enabled }} + {{- $dbEnabled := include "registry.database.isEnabled" $ -}} + {{- if ne $dbEnabled "true" }} registry: Enabling database metrics requires the metadata database to be enabled. See https://docs.gitlab.com/charts/charts/registry#database-metrics @@ -93,19 +95,20 @@ registry: Ensure Registry Redis cache is configured properly and dependencies are met */}} {{- define "gitlab.checkConfig.registry.redis.cache" -}} -{{- if and $.Values.registry.redis.cache.enabled (not $.Values.registry.database.enabled) }} +{{- $dbEnabled := include "registry.database.isEnabled" $ -}} +{{- if and $.Values.registry.redis.cache.enabled (ne $dbEnabled "true") }} registry: Enabling the Redis cache requires the metadata database to be enabled. See https://docs.gitlab.com/charts/charts/registry#redis-cache {{- end -}} -{{- if and $.Values.registry.database.enabled $.Values.registry.redis.cache.enabled }} +{{- if and (eq $dbEnabled "true") $.Values.registry.redis.cache.enabled }} {{- if and (kindIs "string" $.Values.registry.redis.cache.host) (empty $.Values.registry.redis.cache.host) }} registry: Enabling the Redis cache requires the host to not be empty. See https://docs.gitlab.com/charts/charts/registry#redis-cache {{- end -}} {{- end -}} -{{- if and $.Values.registry.database.enabled $.Values.registry.redis.cache.enabled $.Values.registry.redis.cache.sentinels}} +{{- if and (eq $dbEnabled "true") $.Values.registry.redis.cache.enabled $.Values.registry.redis.cache.sentinels}} {{- if not $.Values.registry.redis.cache.host }} registry: Enabling the Redis cache with sentinels requires the registry.redis.cache.host to be set. -- GitLab