Add option to deploy each service in its own namespace

Summary

I would like to spread each gitlab component in its own namespace.

Current behavior

I can only deploy gitlab services in a single namespace configurable with helm --namespace, this namespace is reused everywhere.

Proposal

This should be configurable in order of preference

  1. Configuring a namespace per subchart, for example gitlab.gitlab-shell.namespace: foo
  2. Setting global.namespacePrefix: [true|false] to build the namespace by concatenating {{ .Release.Namespace}} and {{ template "name" }}

For exemple, a named template to calculate the namespace:

{{/* Calculate the namespace */}}
{{- define "gitlab.namespace" -}}
    {{- $namespacePrefix := .Values.global.namespacePrefix | default false -}}
    {{- if .Values.namespace -}}
        {{- .Values.namespace -}}
    {{- else if $namespacePrefix -}}
        {{- printf "%s-%s" .Release.Namespace (include "name" .) -}}
    {{- else -}}
        {{- .Release.Namespace -}}
    {{- end -}}
{{- end }}

Then, to reference the namespace of a subchart, we could define another template to get the namespace of a component:

{{/* Calculate the namespace of a component */}}
{{- define "gitlab.componentNamespace" -}}
    {{- $name := .name -}}
    {{- $context := .context -}}
    {{- with $context -}}
        {{- $namespacePrefix := .Values.global.namespacePrefix | default false -}}
        {{- if .Values.namespace -}}
            {{- .Values.namespace | trunc 63 | trimSuffix "-" -}}
        {{- else if $namespacePrefix -}}
            {{- printf "%s-%s" .Release.Namespace $name | trunc 63 | trimSuffix "-" -}}
        {{- else -}}
            {{- .Release.Namespace -}}
        {{- end -}}
    {{- end }}
{{- end }}

And then, to use it:

{{- $shellNamespace := include "gitlab.componentNamespace" (dict "name" "gitlab-shell" "context" .) -}}

Versions

  • Chart: 8.8.2
  • Platform:
    • Cloud: Scaleway
    • Self-hosted:
  • Kubernetes: (kubectl version)
    • Client:v1.30.0
    • Server: v1.30.6
  • Helm: (helm version)
    • Client: v3.14.4
Edited by DaD