From 793ef64472dff9c1b5a85f11662b2ce43ece6e35 Mon Sep 17 00:00:00 2001 From: 212597596 Date: Fri, 1 Sep 2023 13:08:55 +0300 Subject: [PATCH 01/21] Improving DRY principle support on gitea Ingress host name --- templates/gitea/ingress.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/gitea/ingress.yaml b/templates/gitea/ingress.yaml index 12100a6..9991eec 100644 --- a/templates/gitea/ingress.yaml +++ b/templates/gitea/ingress.yaml @@ -28,14 +28,14 @@ spec: {{- range .Values.ingress.tls }} - hosts: {{- range .hosts }} - - {{ . | quote }} + - {{ tpl . $ | quote }} {{- end }} secretName: {{ .secretName }} {{- end }} {{- end }} rules: {{- range .Values.ingress.hosts }} - - host: {{ .host | quote }} + - host: {{ tpl .host $ | quote }} http: paths: {{- range .paths }} From accf620a3034258b1eac455af6f387dc865627a7 Mon Sep 17 00:00:00 2001 From: Ceddaerrix Date: Fri, 1 Sep 2023 10:12:59 +0000 Subject: [PATCH 02/21] Improving DRY principle support on gitea Ingress host name --- templates/gitea/ingress.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/gitea/ingress.yaml b/templates/gitea/ingress.yaml index 12100a6..9991eec 100644 --- a/templates/gitea/ingress.yaml +++ b/templates/gitea/ingress.yaml @@ -28,14 +28,14 @@ spec: {{- range .Values.ingress.tls }} - hosts: {{- range .hosts }} - - {{ . | quote }} + - {{ tpl . $ | quote }} {{- end }} secretName: {{ .secretName }} {{- end }} {{- end }} rules: {{- range .Values.ingress.hosts }} - - host: {{ .host | quote }} + - host: {{ tpl .host $ | quote }} http: paths: {{- range .paths }} From 87dd3f80669928bef3ef7055868e969b8c05eba3 Mon Sep 17 00:00:00 2001 From: Ceddaerrix Date: Tue, 19 Sep 2023 11:11:52 +0000 Subject: [PATCH 03/21] Creating file for unit test of ingress configuration --- .../deployment/ingress-configuration.yaml | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 unittests/deployment/ingress-configuration.yaml diff --git a/unittests/deployment/ingress-configuration.yaml b/unittests/deployment/ingress-configuration.yaml new file mode 100644 index 0000000..689b7bb --- /dev/null +++ b/unittests/deployment/ingress-configuration.yaml @@ -0,0 +1,24 @@ +suite: ingress template +release: + name: gitea-unittests + namespace: testing +templates: + - templates/gitea/ingress.yaml +tests: + - it: hostname using TPL + template: templates/gitea/ingress.yaml + set: + global.giteaHostName: "gitea.example.com" + ingress.enabled: true + ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}" + ingress.tls: + - secretName: gitea-tls + hosts: + - "{{ .Values.global.giteaHostName }}" + asserts: + - equal: + path: spec.tls[0].hosts[0] + value: "gitea.example.com" + - equal: + path: spec.rules[0].host + value: "gitea.example.com" \ No newline at end of file From b143e50567b43777118c7bd000eea6e6231029c8 Mon Sep 17 00:00:00 2001 From: Ceddaerrix Date: Tue, 19 Sep 2023 11:27:04 +0000 Subject: [PATCH 04/21] Editing asserts indentation --- unittests/deployment/ingress-configuration.yaml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/unittests/deployment/ingress-configuration.yaml b/unittests/deployment/ingress-configuration.yaml index 689b7bb..e47114b 100644 --- a/unittests/deployment/ingress-configuration.yaml +++ b/unittests/deployment/ingress-configuration.yaml @@ -6,7 +6,6 @@ templates: - templates/gitea/ingress.yaml tests: - it: hostname using TPL - template: templates/gitea/ingress.yaml set: global.giteaHostName: "gitea.example.com" ingress.enabled: true @@ -17,8 +16,8 @@ tests: - "{{ .Values.global.giteaHostName }}" asserts: - equal: - path: spec.tls[0].hosts[0] - value: "gitea.example.com" + path: spec.tls[0].hosts[0] + value: "gitea.example.com" - equal: - path: spec.rules[0].host - value: "gitea.example.com" \ No newline at end of file + path: spec.rules[0].host + value: "gitea.example.com" \ No newline at end of file From 1de07a6c48f9671668c8df7ae26082e81050fbf3 Mon Sep 17 00:00:00 2001 From: Ceddaerrix Date: Tue, 19 Sep 2023 11:30:06 +0000 Subject: [PATCH 05/21] Correcting lint errors in ingress-configuration.yaml --- unittests/deployment/ingress-configuration.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/unittests/deployment/ingress-configuration.yaml b/unittests/deployment/ingress-configuration.yaml index e47114b..6a36eb0 100644 --- a/unittests/deployment/ingress-configuration.yaml +++ b/unittests/deployment/ingress-configuration.yaml @@ -6,11 +6,11 @@ templates: - templates/gitea/ingress.yaml tests: - it: hostname using TPL - set: + set: global.giteaHostName: "gitea.example.com" ingress.enabled: true ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}" - ingress.tls: + ingress.tls: - secretName: gitea-tls hosts: - "{{ .Values.global.giteaHostName }}" @@ -20,4 +20,4 @@ tests: value: "gitea.example.com" - equal: path: spec.rules[0].host - value: "gitea.example.com" \ No newline at end of file + value: "gitea.example.com" From d96bce3aee08ee1c442e6396ea2a8dcd89062271 Mon Sep 17 00:00:00 2001 From: Ceddaerrix Date: Tue, 10 Oct 2023 12:38:01 +0000 Subject: [PATCH 06/21] Improving DRY support on gitea host name Adding TPL function to 'gitea.inline_configuration.defaults.server' since (index .Values.ingress.hosts 0).host for server "DOMAIN" key --- templates/_helpers.tpl | 802 ++++++++++++++++++++--------------------- 1 file changed, 401 insertions(+), 401 deletions(-) diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 565f335..e2b9e13 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -1,401 +1,401 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} - -{{- /* multiple replicas assertions */ -}} -{{- if gt .Values.replicaCount 1.0 -}} - {{- fail "When using multiple replicas, a RWX file system is required" -}} - {{- if eq (get (.Values.persistence.accessModes 0) "ReadWriteOnce") -}} - {{- fail "When using multiple replicas, a RWX file system is required" -}} - {{- end }} - - {{- if eq (get .Values.gitea.config.indexer "ISSUE_INDEXER_TYPE") "bleve" -}} - {{- fail "When using multiple replicas, the repo indexer must be set to 'meilisearch' or 'elasticsearch'" -}} - {{- end }} - - {{- if and (eq .Values.gitea.config.indexer.REPO_INDEXER_TYPE "bleve") (eq .Values.gitea.config.indexer.REPO_INDEXER_ENABLED "true") -}} - {{- fail "When using multiple replicas, the repo indexer must be set to 'meilisearch' or 'elasticsearch'" -}} - {{- end }} - - {{- if eq .Values.gitea.config.indexer.ISSUE_INDEXER_TYPE "bleve" -}} - {{- (printf "DEBUG: When using multiple replicas, the repo indexer must be set to 'meilisearch' or 'elasticsearch'") | fail -}} - {{- end }} -{{- end }} - -{{- define "gitea.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -If release name contains chart name it will be used as a full name. -*/}} -{{- define "gitea.fullname" -}} -{{- if .Values.fullnameOverride -}} -{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} -{{- else -}} -{{- $name := default .Chart.Name .Values.nameOverride -}} -{{- if contains $name .Release.Name -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "gitea.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create image name and tag used by the deployment. -*/}} -{{- define "gitea.image" -}} -{{- $registry := .Values.global.imageRegistry | default .Values.image.registry -}} -{{- $repository := .Values.image.repository -}} -{{- $separator := ":" -}} -{{- $tag := .Values.image.tag | default .Chart.AppVersion -}} -{{- $rootless := ternary "-rootless" "" (.Values.image.rootless) -}} -{{- $digest := "" -}} -{{- if .Values.image.digest }} - {{- $digest = (printf "@%s" (.Values.image.digest | toString)) -}} -{{- end -}} -{{- if $registry }} - {{- printf "%s/%s%s%s%s%s" $registry $repository $separator $tag $rootless $digest -}} -{{- else -}} - {{- printf "%s%s%s%s%s" $repository $separator $tag $rootless $digest -}} -{{- end -}} -{{- end -}} - -{{/* -Docker Image Registry Secret Names evaluating values as templates -*/}} -{{- define "gitea.images.pullSecrets" -}} -{{- $pullSecrets := .Values.imagePullSecrets -}} -{{- range .Values.global.imagePullSecrets -}} - {{- $pullSecrets = append $pullSecrets (dict "name" .) -}} -{{- end -}} -{{- if (not (empty $pullSecrets)) }} -imagePullSecrets: -{{ toYaml $pullSecrets }} -{{- end }} -{{- end -}} - - -{{/* -Storage Class -*/}} -{{- define "gitea.persistence.storageClass" -}} -{{- $storageClass := .Values.global.storageClass | default .Values.persistence.storageClass }} -{{- if $storageClass }} -storageClassName: {{ $storageClass | quote }} -{{- end }} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "gitea.labels" -}} -helm.sh/chart: {{ include "gitea.chart" . }} -app: {{ include "gitea.name" . }} -{{ include "gitea.selectorLabels" . }} -app.kubernetes.io/version: {{ .Values.image.tag | default .Chart.AppVersion | quote }} -version: {{ .Values.image.tag | default .Chart.AppVersion | quote }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "gitea.selectorLabels" -}} -app.kubernetes.io/name: {{ include "gitea.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{- define "postgresql-ha.dns" -}} -{{- if (index .Values "postgresql-ha").enabled -}} -{{- printf "%s-postgresql-ha-postgresql.%s.svc.%s:%g" .Release.Name .Release.Namespace .Values.clusterDomain (index .Values "postgresql-ha" "service" "ports" "postgresql") -}} -{{- end -}} -{{- end -}} - -{{- define "postgresql.dns" -}} -{{- if (index .Values "postgresql").enabled -}} -{{- printf "%s-postgresql.%s.svc.%s:%g" .Release.Name .Release.Namespace .Values.clusterDomain .Values.postgresql.global.postgresql.service.ports.postgresql -}} -{{- end -}} -{{- end -}} - -{{- define "redis.dns" -}} -{{- if (index .Values "redis-cluster").enabled -}} -{{- printf "redis+cluster://:%s@%s-redis-cluster-headless.%s.svc.%s:%g/0?pool_size=100&idle_timeout=180s&" (index .Values "redis-cluster").global.redis.password .Release.Name .Release.Namespace .Values.clusterDomain (index .Values "redis-cluster").service.ports.redis -}} -{{- end -}} -{{- end -}} - -{{- define "redis.port" -}} -{{- if (index .Values "redis-cluster").enabled -}} -{{ (index .Values "redis-cluster").service.ports.redis }} -{{- end -}} -{{- end -}} - -{{- define "redis.servicename" -}} -{{- if (index .Values "redis-cluster").enabled -}} -{{- printf "%s-redis-cluster-headless.%s.svc.%s" .Release.Name .Release.Namespace .Values.clusterDomain -}} -{{- end -}} -{{- end -}} - -{{- define "gitea.default_domain" -}} -{{- printf "%s-gitea.%s.svc.%s" (include "gitea.fullname" .) .Release.Namespace .Values.clusterDomain | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{- define "gitea.ldap_settings" -}} -{{- $idx := index . 0 }} -{{- $values := index . 1 }} - -{{- if not (hasKey $values "bindDn") -}} -{{- $_ := set $values "bindDn" "" -}} -{{- end -}} - -{{- if not (hasKey $values "bindPassword") -}} -{{- $_ := set $values "bindPassword" "" -}} -{{- end -}} - -{{- $flags := list "notActive" "skipTlsVerify" "allowDeactivateAll" "synchronizeUsers" "attributesInBind" -}} -{{- range $key, $val := $values -}} -{{- if and (ne $key "enabled") (ne $key "existingSecret") -}} -{{- if eq $key "bindDn" -}} -{{- printf "--%s \"${GITEA_LDAP_BIND_DN_%d}\" " ($key | kebabcase) ($idx) -}} -{{- else if eq $key "bindPassword" -}} -{{- printf "--%s \"${GITEA_LDAP_PASSWORD_%d}\" " ($key | kebabcase) ($idx) -}} -{{- else if eq $key "port" -}} -{{- printf "--%s %d " $key ($val | int) -}} -{{- else if has $key $flags -}} -{{- printf "--%s " ($key | kebabcase) -}} -{{- else -}} -{{- printf "--%s %s " ($key | kebabcase) ($val | squote) -}} -{{- end -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{- define "gitea.oauth_settings" -}} -{{- $idx := index . 0 }} -{{- $values := index . 1 }} - -{{- if not (hasKey $values "key") -}} -{{- $_ := set $values "key" (printf "${GITEA_OAUTH_KEY_%d}" $idx) -}} -{{- end -}} - -{{- if not (hasKey $values "secret") -}} -{{- $_ := set $values "secret" (printf "${GITEA_OAUTH_SECRET_%d}" $idx) -}} -{{- end -}} - -{{- range $key, $val := $values -}} -{{- if ne $key "existingSecret" -}} -{{- printf "--%s %s " ($key | kebabcase) ($val | quote) -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{- define "gitea.public_protocol" -}} -{{- if and .Values.ingress.enabled (gt (len .Values.ingress.tls) 0) -}} -https -{{- else -}} -{{ .Values.gitea.config.server.PROTOCOL }} -{{- end -}} -{{- end -}} - -{{- define "gitea.inline_configuration" -}} - {{- include "gitea.inline_configuration.init" . -}} - {{- include "gitea.inline_configuration.defaults" . -}} - - {{- $generals := list -}} - {{- $inlines := dict -}} - - {{- range $key, $value := .Values.gitea.config }} - {{- if kindIs "map" $value }} - {{- if gt (len $value) 0 }} - {{- $section := default list (get $inlines $key) -}} - {{- range $n_key, $n_value := $value }} - {{- $section = append $section (printf "%s=%v" $n_key $n_value) -}} - {{- end }} - {{- $_ := set $inlines $key (join "\n" $section) -}} - {{- end -}} - {{- else }} - {{- if or (eq $key "APP_NAME") (eq $key "RUN_USER") (eq $key "RUN_MODE") -}} - {{- $generals = append $generals (printf "%s=%s" $key $value) -}} - {{- else -}} - {{- (printf "Key %s cannot be on top level of configuration" $key) | fail -}} - {{- end -}} - - {{- end }} - {{- end }} - - {{- $_ := set $inlines "_generals_" (join "\n" $generals) -}} - {{- toYaml $inlines -}} -{{- end -}} - -{{- define "gitea.inline_configuration.init" -}} - {{- if not (hasKey .Values.gitea.config "cache") -}} - {{- $_ := set .Values.gitea.config "cache" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "server") -}} - {{- $_ := set .Values.gitea.config "server" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "metrics") -}} - {{- $_ := set .Values.gitea.config "metrics" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "database") -}} - {{- $_ := set .Values.gitea.config "database" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "security") -}} - {{- $_ := set .Values.gitea.config "security" dict -}} - {{- end -}} - {{- if not .Values.gitea.config.repository -}} - {{- $_ := set .Values.gitea.config "repository" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "oauth2") -}} - {{- $_ := set .Values.gitea.config "oauth2" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "session") -}} - {{- $_ := set .Values.gitea.config "session" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "queue") -}} - {{- $_ := set .Values.gitea.config "queue" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "queue.issue_indexer") -}} - {{- $_ := set .Values.gitea.config "queue.issue_indexer" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "indexer") -}} - {{- $_ := set .Values.gitea.config "indexer" dict -}} - {{- end -}} -{{- end -}} - -{{- define "gitea.inline_configuration.defaults" -}} - {{- include "gitea.inline_configuration.defaults.server" . -}} - {{- include "gitea.inline_configuration.defaults.database" . -}} - - {{- if not .Values.gitea.config.repository.ROOT -}} - {{- $_ := set .Values.gitea.config.repository "ROOT" "/data/git/gitea-repositories" -}} - {{- end -}} - {{- if not .Values.gitea.config.security.INSTALL_LOCK -}} - {{- $_ := set .Values.gitea.config.security "INSTALL_LOCK" "true" -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config.metrics "ENABLED") -}} - {{- $_ := set .Values.gitea.config.metrics "ENABLED" .Values.gitea.metrics.enabled -}} - {{- end -}} - {{- if (index .Values "redis-cluster").enabled -}} - {{- $_ := set .Values.gitea.config.cache "ENABLED" "true" -}} - {{- $_ := set .Values.gitea.config.cache "ADAPTER" "redis" -}} - {{- if not (.Values.gitea.config.cache.HOST) -}} - {{- $_ := set .Values.gitea.config.cache "HOST" (include "redis.dns" .) -}} - {{- end -}} - {{- end -}} - {{- /* redis queue */ -}} - {{- if (index .Values "redis-cluster").enabled -}} - {{- $_ := set .Values.gitea.config.queue "TYPE" "redis" -}} - {{- $_ := set .Values.gitea.config.queue "CONN_STR" (include "redis.dns" .) -}} - {{- end -}} - {{- if not (get .Values.gitea.config.session "PROVIDER") -}} - {{- $_ := set .Values.gitea.config.session "PROVIDER" "redis" -}} - {{- end -}} - {{- if not (get .Values.gitea.config.session "PROVIDER_CONFIG") -}} - {{- $_ := set .Values.gitea.config.session "PROVIDER_CONFIG" (include "redis.dns" .) -}} - {{- end -}} - {{- if not .Values.gitea.config.indexer.ISSUE_INDEXER_TYPE -}} - {{- $_ := set .Values.gitea.config.indexer "ISSUE_INDEXER_TYPE" "db" -}} - {{- end -}} -{{- end -}} - -{{- define "gitea.inline_configuration.defaults.server" -}} - {{- if not (hasKey .Values.gitea.config.server "HTTP_PORT") -}} - {{- $_ := set .Values.gitea.config.server "HTTP_PORT" .Values.service.http.port -}} - {{- end -}} - {{- if not .Values.gitea.config.server.PROTOCOL -}} - {{- $_ := set .Values.gitea.config.server "PROTOCOL" "http" -}} - {{- end -}} - {{- if not (.Values.gitea.config.server.DOMAIN) -}} - {{- if gt (len .Values.ingress.hosts) 0 -}} - {{- $_ := set .Values.gitea.config.server "DOMAIN" (index .Values.ingress.hosts 0).host -}} - {{- else -}} - {{- $_ := set .Values.gitea.config.server "DOMAIN" (include "gitea.default_domain" .) -}} - {{- end -}} - {{- end -}} - {{- if not .Values.gitea.config.server.ROOT_URL -}} - {{- $_ := set .Values.gitea.config.server "ROOT_URL" (printf "%s://%s" (include "gitea.public_protocol" .) .Values.gitea.config.server.DOMAIN) -}} - {{- end -}} - {{- if not .Values.gitea.config.server.SSH_DOMAIN -}} - {{- $_ := set .Values.gitea.config.server "SSH_DOMAIN" .Values.gitea.config.server.DOMAIN -}} - {{- end -}} - {{- if not .Values.gitea.config.server.SSH_PORT -}} - {{- $_ := set .Values.gitea.config.server "SSH_PORT" .Values.service.ssh.port -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config.server "SSH_LISTEN_PORT") -}} - {{- if not .Values.image.rootless -}} - {{- $_ := set .Values.gitea.config.server "SSH_LISTEN_PORT" .Values.gitea.config.server.SSH_PORT -}} - {{- else -}} - {{- $_ := set .Values.gitea.config.server "SSH_LISTEN_PORT" "2222" -}} - {{- end -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config.server "START_SSH_SERVER") -}} - {{- if .Values.image.rootless -}} - {{- $_ := set .Values.gitea.config.server "START_SSH_SERVER" "true" -}} - {{- end -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config.server "APP_DATA_PATH") -}} - {{- $_ := set .Values.gitea.config.server "APP_DATA_PATH" "/data" -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config.server "ENABLE_PPROF") -}} - {{- $_ := set .Values.gitea.config.server "ENABLE_PPROF" false -}} - {{- end -}} -{{- end -}} - -{{- define "gitea.inline_configuration.defaults.database" -}} - {{- if (index .Values "postgresql-ha" "enabled") -}} - {{- $_ := set .Values.gitea.config.database "DB_TYPE" "postgres" -}} - {{- if not (.Values.gitea.config.database.HOST) -}} - {{- $_ := set .Values.gitea.config.database "HOST" (include "postgresql-ha.dns" .) -}} - {{- end -}} - {{- $_ := set .Values.gitea.config.database "NAME" (index .Values "postgresql-ha" "global" "postgresql" "database") -}} - {{- $_ := set .Values.gitea.config.database "USER" (index .Values "postgresql-ha" "global" "postgresql" "username") -}} - {{- $_ := set .Values.gitea.config.database "PASSWD" (index .Values "postgresql-ha" "global" "postgresql" "password") -}} - {{- end -}} - {{- if (index .Values "postgresql" "enabled") -}} - {{- $_ := set .Values.gitea.config.database "DB_TYPE" "postgres" -}} - {{- if not (.Values.gitea.config.database.HOST) -}} - {{- $_ := set .Values.gitea.config.database "HOST" (include "postgresql.dns" .) -}} - {{- end -}} - {{- $_ := set .Values.gitea.config.database "NAME" .Values.postgresql.global.postgresql.auth.database -}} - {{- $_ := set .Values.gitea.config.database "USER" .Values.postgresql.global.postgresql.auth.username -}} - {{- $_ := set .Values.gitea.config.database "PASSWD" .Values.postgresql.global.postgresql.auth.password -}} - {{- end -}} -{{- end -}} - -{{- define "gitea.init-additional-mounts" -}} - {{- /* Honor the deprecated extraVolumeMounts variable when defined */ -}} - {{- if gt (len .Values.extraInitVolumeMounts) 0 -}} - {{- toYaml .Values.extraInitVolumeMounts -}} - {{- else if gt (len .Values.extraVolumeMounts) 0 -}} - {{- toYaml .Values.extraVolumeMounts -}} - {{- end -}} -{{- end -}} - -{{- define "gitea.container-additional-mounts" -}} - {{- /* Honor the deprecated extraVolumeMounts variable when defined */ -}} - {{- if gt (len .Values.extraContainerVolumeMounts) 0 -}} - {{- toYaml .Values.extraContainerVolumeMounts -}} - {{- else if gt (len .Values.extraVolumeMounts) 0 -}} - {{- toYaml .Values.extraVolumeMounts -}} - {{- end -}} -{{- end -}} - -{{- define "gitea.gpg-key-secret-name" -}} -{{ default (printf "%s-gpg-key" (include "gitea.fullname" .)) .Values.signing.existingSecret }} -{{- end -}} - -{{- define "gitea.serviceAccountName" -}} -{{ .Values.serviceAccount.name | default (include "gitea.fullname" .) }} -{{- end -}} +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} + +{{- /* multiple replicas assertions */ -}} +{{- if gt .Values.replicaCount 1.0 -}} + {{- fail "When using multiple replicas, a RWX file system is required" -}} + {{- if eq (get (.Values.persistence.accessModes 0) "ReadWriteOnce") -}} + {{- fail "When using multiple replicas, a RWX file system is required" -}} + {{- end }} + + {{- if eq (get .Values.gitea.config.indexer "ISSUE_INDEXER_TYPE") "bleve" -}} + {{- fail "When using multiple replicas, the repo indexer must be set to 'meilisearch' or 'elasticsearch'" -}} + {{- end }} + + {{- if and (eq .Values.gitea.config.indexer.REPO_INDEXER_TYPE "bleve") (eq .Values.gitea.config.indexer.REPO_INDEXER_ENABLED "true") -}} + {{- fail "When using multiple replicas, the repo indexer must be set to 'meilisearch' or 'elasticsearch'" -}} + {{- end }} + + {{- if eq .Values.gitea.config.indexer.ISSUE_INDEXER_TYPE "bleve" -}} + {{- (printf "DEBUG: When using multiple replicas, the repo indexer must be set to 'meilisearch' or 'elasticsearch'") | fail -}} + {{- end }} +{{- end }} + +{{- define "gitea.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "gitea.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "gitea.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create image name and tag used by the deployment. +*/}} +{{- define "gitea.image" -}} +{{- $registry := .Values.global.imageRegistry | default .Values.image.registry -}} +{{- $repository := .Values.image.repository -}} +{{- $separator := ":" -}} +{{- $tag := .Values.image.tag | default .Chart.AppVersion -}} +{{- $rootless := ternary "-rootless" "" (.Values.image.rootless) -}} +{{- $digest := "" -}} +{{- if .Values.image.digest }} + {{- $digest = (printf "@%s" (.Values.image.digest | toString)) -}} +{{- end -}} +{{- if $registry }} + {{- printf "%s/%s%s%s%s%s" $registry $repository $separator $tag $rootless $digest -}} +{{- else -}} + {{- printf "%s%s%s%s%s" $repository $separator $tag $rootless $digest -}} +{{- end -}} +{{- end -}} + +{{/* +Docker Image Registry Secret Names evaluating values as templates +*/}} +{{- define "gitea.images.pullSecrets" -}} +{{- $pullSecrets := .Values.imagePullSecrets -}} +{{- range .Values.global.imagePullSecrets -}} + {{- $pullSecrets = append $pullSecrets (dict "name" .) -}} +{{- end -}} +{{- if (not (empty $pullSecrets)) }} +imagePullSecrets: +{{ toYaml $pullSecrets }} +{{- end }} +{{- end -}} + + +{{/* +Storage Class +*/}} +{{- define "gitea.persistence.storageClass" -}} +{{- $storageClass := .Values.global.storageClass | default .Values.persistence.storageClass }} +{{- if $storageClass }} +storageClassName: {{ $storageClass | quote }} +{{- end }} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "gitea.labels" -}} +helm.sh/chart: {{ include "gitea.chart" . }} +app: {{ include "gitea.name" . }} +{{ include "gitea.selectorLabels" . }} +app.kubernetes.io/version: {{ .Values.image.tag | default .Chart.AppVersion | quote }} +version: {{ .Values.image.tag | default .Chart.AppVersion | quote }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + +{{/* +Selector labels +*/}} +{{- define "gitea.selectorLabels" -}} +app.kubernetes.io/name: {{ include "gitea.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} + +{{- define "postgresql-ha.dns" -}} +{{- if (index .Values "postgresql-ha").enabled -}} +{{- printf "%s-postgresql-ha-postgresql.%s.svc.%s:%g" .Release.Name .Release.Namespace .Values.clusterDomain (index .Values "postgresql-ha" "service" "ports" "postgresql") -}} +{{- end -}} +{{- end -}} + +{{- define "postgresql.dns" -}} +{{- if (index .Values "postgresql").enabled -}} +{{- printf "%s-postgresql.%s.svc.%s:%g" .Release.Name .Release.Namespace .Values.clusterDomain .Values.postgresql.global.postgresql.service.ports.postgresql -}} +{{- end -}} +{{- end -}} + +{{- define "redis.dns" -}} +{{- if (index .Values "redis-cluster").enabled -}} +{{- printf "redis+cluster://:%s@%s-redis-cluster-headless.%s.svc.%s:%g/0?pool_size=100&idle_timeout=180s&" (index .Values "redis-cluster").global.redis.password .Release.Name .Release.Namespace .Values.clusterDomain (index .Values "redis-cluster").service.ports.redis -}} +{{- end -}} +{{- end -}} + +{{- define "redis.port" -}} +{{- if (index .Values "redis-cluster").enabled -}} +{{ (index .Values "redis-cluster").service.ports.redis }} +{{- end -}} +{{- end -}} + +{{- define "redis.servicename" -}} +{{- if (index .Values "redis-cluster").enabled -}} +{{- printf "%s-redis-cluster-headless.%s.svc.%s" .Release.Name .Release.Namespace .Values.clusterDomain -}} +{{- end -}} +{{- end -}} + +{{- define "gitea.default_domain" -}} +{{- printf "%s-gitea.%s.svc.%s" (include "gitea.fullname" .) .Release.Namespace .Values.clusterDomain | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{- define "gitea.ldap_settings" -}} +{{- $idx := index . 0 }} +{{- $values := index . 1 }} + +{{- if not (hasKey $values "bindDn") -}} +{{- $_ := set $values "bindDn" "" -}} +{{- end -}} + +{{- if not (hasKey $values "bindPassword") -}} +{{- $_ := set $values "bindPassword" "" -}} +{{- end -}} + +{{- $flags := list "notActive" "skipTlsVerify" "allowDeactivateAll" "synchronizeUsers" "attributesInBind" -}} +{{- range $key, $val := $values -}} +{{- if and (ne $key "enabled") (ne $key "existingSecret") -}} +{{- if eq $key "bindDn" -}} +{{- printf "--%s \"${GITEA_LDAP_BIND_DN_%d}\" " ($key | kebabcase) ($idx) -}} +{{- else if eq $key "bindPassword" -}} +{{- printf "--%s \"${GITEA_LDAP_PASSWORD_%d}\" " ($key | kebabcase) ($idx) -}} +{{- else if eq $key "port" -}} +{{- printf "--%s %d " $key ($val | int) -}} +{{- else if has $key $flags -}} +{{- printf "--%s " ($key | kebabcase) -}} +{{- else -}} +{{- printf "--%s %s " ($key | kebabcase) ($val | squote) -}} +{{- end -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{- define "gitea.oauth_settings" -}} +{{- $idx := index . 0 }} +{{- $values := index . 1 }} + +{{- if not (hasKey $values "key") -}} +{{- $_ := set $values "key" (printf "${GITEA_OAUTH_KEY_%d}" $idx) -}} +{{- end -}} + +{{- if not (hasKey $values "secret") -}} +{{- $_ := set $values "secret" (printf "${GITEA_OAUTH_SECRET_%d}" $idx) -}} +{{- end -}} + +{{- range $key, $val := $values -}} +{{- if ne $key "existingSecret" -}} +{{- printf "--%s %s " ($key | kebabcase) ($val | quote) -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{- define "gitea.public_protocol" -}} +{{- if and .Values.ingress.enabled (gt (len .Values.ingress.tls) 0) -}} +https +{{- else -}} +{{ .Values.gitea.config.server.PROTOCOL }} +{{- end -}} +{{- end -}} + +{{- define "gitea.inline_configuration" -}} + {{- include "gitea.inline_configuration.init" . -}} + {{- include "gitea.inline_configuration.defaults" . -}} + + {{- $generals := list -}} + {{- $inlines := dict -}} + + {{- range $key, $value := .Values.gitea.config }} + {{- if kindIs "map" $value }} + {{- if gt (len $value) 0 }} + {{- $section := default list (get $inlines $key) -}} + {{- range $n_key, $n_value := $value }} + {{- $section = append $section (printf "%s=%v" $n_key $n_value) -}} + {{- end }} + {{- $_ := set $inlines $key (join "\n" $section) -}} + {{- end -}} + {{- else }} + {{- if or (eq $key "APP_NAME") (eq $key "RUN_USER") (eq $key "RUN_MODE") -}} + {{- $generals = append $generals (printf "%s=%s" $key $value) -}} + {{- else -}} + {{- (printf "Key %s cannot be on top level of configuration" $key) | fail -}} + {{- end -}} + + {{- end }} + {{- end }} + + {{- $_ := set $inlines "_generals_" (join "\n" $generals) -}} + {{- toYaml $inlines -}} +{{- end -}} + +{{- define "gitea.inline_configuration.init" -}} + {{- if not (hasKey .Values.gitea.config "cache") -}} + {{- $_ := set .Values.gitea.config "cache" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "server") -}} + {{- $_ := set .Values.gitea.config "server" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "metrics") -}} + {{- $_ := set .Values.gitea.config "metrics" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "database") -}} + {{- $_ := set .Values.gitea.config "database" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "security") -}} + {{- $_ := set .Values.gitea.config "security" dict -}} + {{- end -}} + {{- if not .Values.gitea.config.repository -}} + {{- $_ := set .Values.gitea.config "repository" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "oauth2") -}} + {{- $_ := set .Values.gitea.config "oauth2" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "session") -}} + {{- $_ := set .Values.gitea.config "session" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "queue") -}} + {{- $_ := set .Values.gitea.config "queue" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "queue.issue_indexer") -}} + {{- $_ := set .Values.gitea.config "queue.issue_indexer" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "indexer") -}} + {{- $_ := set .Values.gitea.config "indexer" dict -}} + {{- end -}} +{{- end -}} + +{{- define "gitea.inline_configuration.defaults" -}} + {{- include "gitea.inline_configuration.defaults.server" . -}} + {{- include "gitea.inline_configuration.defaults.database" . -}} + + {{- if not .Values.gitea.config.repository.ROOT -}} + {{- $_ := set .Values.gitea.config.repository "ROOT" "/data/git/gitea-repositories" -}} + {{- end -}} + {{- if not .Values.gitea.config.security.INSTALL_LOCK -}} + {{- $_ := set .Values.gitea.config.security "INSTALL_LOCK" "true" -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config.metrics "ENABLED") -}} + {{- $_ := set .Values.gitea.config.metrics "ENABLED" .Values.gitea.metrics.enabled -}} + {{- end -}} + {{- if (index .Values "redis-cluster").enabled -}} + {{- $_ := set .Values.gitea.config.cache "ENABLED" "true" -}} + {{- $_ := set .Values.gitea.config.cache "ADAPTER" "redis" -}} + {{- if not (.Values.gitea.config.cache.HOST) -}} + {{- $_ := set .Values.gitea.config.cache "HOST" (include "redis.dns" .) -}} + {{- end -}} + {{- end -}} + {{- /* redis queue */ -}} + {{- if (index .Values "redis-cluster").enabled -}} + {{- $_ := set .Values.gitea.config.queue "TYPE" "redis" -}} + {{- $_ := set .Values.gitea.config.queue "CONN_STR" (include "redis.dns" .) -}} + {{- end -}} + {{- if not (get .Values.gitea.config.session "PROVIDER") -}} + {{- $_ := set .Values.gitea.config.session "PROVIDER" "redis" -}} + {{- end -}} + {{- if not (get .Values.gitea.config.session "PROVIDER_CONFIG") -}} + {{- $_ := set .Values.gitea.config.session "PROVIDER_CONFIG" (include "redis.dns" .) -}} + {{- end -}} + {{- if not .Values.gitea.config.indexer.ISSUE_INDEXER_TYPE -}} + {{- $_ := set .Values.gitea.config.indexer "ISSUE_INDEXER_TYPE" "db" -}} + {{- end -}} +{{- end -}} + +{{- define "gitea.inline_configuration.defaults.server" -}} + {{- if not (hasKey .Values.gitea.config.server "HTTP_PORT") -}} + {{- $_ := set .Values.gitea.config.server "HTTP_PORT" .Values.service.http.port -}} + {{- end -}} + {{- if not .Values.gitea.config.server.PROTOCOL -}} + {{- $_ := set .Values.gitea.config.server "PROTOCOL" "http" -}} + {{- end -}} + {{- if not (.Values.gitea.config.server.DOMAIN) -}} + {{- if gt (len .Values.ingress.hosts) 0 -}} + {{- $_ := set .Values.gitea.config.server "DOMAIN" ( tpl (index .Values.ingress.hosts 0).host $) -}} + {{- else -}} + {{- $_ := set .Values.gitea.config.server "DOMAIN" (include "gitea.default_domain" .) -}} + {{- end -}} + {{- end -}} + {{- if not .Values.gitea.config.server.ROOT_URL -}} + {{- $_ := set .Values.gitea.config.server "ROOT_URL" (printf "%s://%s" (include "gitea.public_protocol" .) .Values.gitea.config.server.DOMAIN) -}} + {{- end -}} + {{- if not .Values.gitea.config.server.SSH_DOMAIN -}} + {{- $_ := set .Values.gitea.config.server "SSH_DOMAIN" .Values.gitea.config.server.DOMAIN -}} + {{- end -}} + {{- if not .Values.gitea.config.server.SSH_PORT -}} + {{- $_ := set .Values.gitea.config.server "SSH_PORT" .Values.service.ssh.port -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config.server "SSH_LISTEN_PORT") -}} + {{- if not .Values.image.rootless -}} + {{- $_ := set .Values.gitea.config.server "SSH_LISTEN_PORT" .Values.gitea.config.server.SSH_PORT -}} + {{- else -}} + {{- $_ := set .Values.gitea.config.server "SSH_LISTEN_PORT" "2222" -}} + {{- end -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config.server "START_SSH_SERVER") -}} + {{- if .Values.image.rootless -}} + {{- $_ := set .Values.gitea.config.server "START_SSH_SERVER" "true" -}} + {{- end -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config.server "APP_DATA_PATH") -}} + {{- $_ := set .Values.gitea.config.server "APP_DATA_PATH" "/data" -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config.server "ENABLE_PPROF") -}} + {{- $_ := set .Values.gitea.config.server "ENABLE_PPROF" false -}} + {{- end -}} +{{- end -}} + +{{- define "gitea.inline_configuration.defaults.database" -}} + {{- if (index .Values "postgresql-ha" "enabled") -}} + {{- $_ := set .Values.gitea.config.database "DB_TYPE" "postgres" -}} + {{- if not (.Values.gitea.config.database.HOST) -}} + {{- $_ := set .Values.gitea.config.database "HOST" (include "postgresql-ha.dns" .) -}} + {{- end -}} + {{- $_ := set .Values.gitea.config.database "NAME" (index .Values "postgresql-ha" "global" "postgresql" "database") -}} + {{- $_ := set .Values.gitea.config.database "USER" (index .Values "postgresql-ha" "global" "postgresql" "username") -}} + {{- $_ := set .Values.gitea.config.database "PASSWD" (index .Values "postgresql-ha" "global" "postgresql" "password") -}} + {{- end -}} + {{- if (index .Values "postgresql" "enabled") -}} + {{- $_ := set .Values.gitea.config.database "DB_TYPE" "postgres" -}} + {{- if not (.Values.gitea.config.database.HOST) -}} + {{- $_ := set .Values.gitea.config.database "HOST" (include "postgresql.dns" .) -}} + {{- end -}} + {{- $_ := set .Values.gitea.config.database "NAME" .Values.postgresql.global.postgresql.auth.database -}} + {{- $_ := set .Values.gitea.config.database "USER" .Values.postgresql.global.postgresql.auth.username -}} + {{- $_ := set .Values.gitea.config.database "PASSWD" .Values.postgresql.global.postgresql.auth.password -}} + {{- end -}} +{{- end -}} + +{{- define "gitea.init-additional-mounts" -}} + {{- /* Honor the deprecated extraVolumeMounts variable when defined */ -}} + {{- if gt (len .Values.extraInitVolumeMounts) 0 -}} + {{- toYaml .Values.extraInitVolumeMounts -}} + {{- else if gt (len .Values.extraVolumeMounts) 0 -}} + {{- toYaml .Values.extraVolumeMounts -}} + {{- end -}} +{{- end -}} + +{{- define "gitea.container-additional-mounts" -}} + {{- /* Honor the deprecated extraVolumeMounts variable when defined */ -}} + {{- if gt (len .Values.extraContainerVolumeMounts) 0 -}} + {{- toYaml .Values.extraContainerVolumeMounts -}} + {{- else if gt (len .Values.extraVolumeMounts) 0 -}} + {{- toYaml .Values.extraVolumeMounts -}} + {{- end -}} +{{- end -}} + +{{- define "gitea.gpg-key-secret-name" -}} +{{ default (printf "%s-gpg-key" (include "gitea.fullname" .)) .Values.signing.existingSecret }} +{{- end -}} + +{{- define "gitea.serviceAccountName" -}} +{{ .Values.serviceAccount.name | default (include "gitea.fullname" .) }} +{{- end -}} From 2ef96c449b9e589f84eb4915c35e0e91cd6aa937 Mon Sep 17 00:00:00 2001 From: Ceddaerrix Date: Tue, 10 Oct 2023 12:43:41 +0000 Subject: [PATCH 07/21] Add unittests/deployment/inline-config.yaml --- unittests/deployment/inline-config.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 unittests/deployment/inline-config.yaml diff --git a/unittests/deployment/inline-config.yaml b/unittests/deployment/inline-config.yaml new file mode 100644 index 0000000..e69de29 From 3645ddd2763ecdc29cb1bd977b5bd88cd3964976 Mon Sep 17 00:00:00 2001 From: Ceddaerrix Date: Tue, 10 Oct 2023 12:56:36 +0000 Subject: [PATCH 08/21] Improving DRY support - adding unit test for templates/gitea/config.yaml first document --- unittests/deployment/inline-config.yaml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/unittests/deployment/inline-config.yaml b/unittests/deployment/inline-config.yaml index e69de29..b96792c 100644 --- a/unittests/deployment/inline-config.yaml +++ b/unittests/deployment/inline-config.yaml @@ -0,0 +1,25 @@ +suite: config template +release: + name: gitea-unittests + namespace: testing +templates: + - templates/gitea/config.yaml +tests: + - it: inline config stringData.server using TPL + set: + global.giteaHostName: "gitea.example.com" + ingress.enabled: true + ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}" + ingress.tls: + - secretName: gitea-tls + hosts: + - "{{ .Values.global.giteaHostName }}" + asserts: + - equal: + path: stringData.server.DOMAIN + value: "gitea.example.com" + documentIndex: 0 + - equal: + path: stringData.server.ROOT_URL + value: "https://gitea.example.com" + documentIndex: 0 \ No newline at end of file From 0682c36c1055bb665081c22227ad51f67884d37a Mon Sep 17 00:00:00 2001 From: Ceddaerrix Date: Wed, 11 Oct 2023 05:59:35 +0000 Subject: [PATCH 09/21] Reverting last change in '_helpers.tpl' "gitea.inline_configuration.defaults.server" --- templates/_helpers.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index e2b9e13..3853703 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -319,7 +319,7 @@ https {{- end -}} {{- if not (.Values.gitea.config.server.DOMAIN) -}} {{- if gt (len .Values.ingress.hosts) 0 -}} - {{- $_ := set .Values.gitea.config.server "DOMAIN" ( tpl (index .Values.ingress.hosts 0).host $) -}} + {{- $_ := set .Values.gitea.config.server "DOMAIN" (index .Values.ingress.hosts 0).host -}} {{- else -}} {{- $_ := set .Values.gitea.config.server "DOMAIN" (include "gitea.default_domain" .) -}} {{- end -}} From a85a6dc3e6245cd161b7500c0c09f390132b5f75 Mon Sep 17 00:00:00 2001 From: Ceddaerrix Date: Wed, 11 Oct 2023 06:00:57 +0000 Subject: [PATCH 10/21] Reintroducing change in '_helpers.tpl' "gitea.inline_configuration.defaults.server" (line 322) --- templates/_helpers.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 3853703..e2b9e13 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -319,7 +319,7 @@ https {{- end -}} {{- if not (.Values.gitea.config.server.DOMAIN) -}} {{- if gt (len .Values.ingress.hosts) 0 -}} - {{- $_ := set .Values.gitea.config.server "DOMAIN" (index .Values.ingress.hosts 0).host -}} + {{- $_ := set .Values.gitea.config.server "DOMAIN" ( tpl (index .Values.ingress.hosts 0).host $) -}} {{- else -}} {{- $_ := set .Values.gitea.config.server "DOMAIN" (include "gitea.default_domain" .) -}} {{- end -}} From f6cde62585ec47025cebc0de53dc2970394516ea Mon Sep 17 00:00:00 2001 From: 212597596 Date: Tue, 31 Oct 2023 11:15:55 +0200 Subject: [PATCH 11/21] Enforcing unix line ending --- templates/_helpers.tpl | 802 ++++++++++++------------ unittests/deployment/inline-config.yaml | 48 +- 2 files changed, 425 insertions(+), 425 deletions(-) diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index e2b9e13..ab761dd 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -1,401 +1,401 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} - -{{- /* multiple replicas assertions */ -}} -{{- if gt .Values.replicaCount 1.0 -}} - {{- fail "When using multiple replicas, a RWX file system is required" -}} - {{- if eq (get (.Values.persistence.accessModes 0) "ReadWriteOnce") -}} - {{- fail "When using multiple replicas, a RWX file system is required" -}} - {{- end }} - - {{- if eq (get .Values.gitea.config.indexer "ISSUE_INDEXER_TYPE") "bleve" -}} - {{- fail "When using multiple replicas, the repo indexer must be set to 'meilisearch' or 'elasticsearch'" -}} - {{- end }} - - {{- if and (eq .Values.gitea.config.indexer.REPO_INDEXER_TYPE "bleve") (eq .Values.gitea.config.indexer.REPO_INDEXER_ENABLED "true") -}} - {{- fail "When using multiple replicas, the repo indexer must be set to 'meilisearch' or 'elasticsearch'" -}} - {{- end }} - - {{- if eq .Values.gitea.config.indexer.ISSUE_INDEXER_TYPE "bleve" -}} - {{- (printf "DEBUG: When using multiple replicas, the repo indexer must be set to 'meilisearch' or 'elasticsearch'") | fail -}} - {{- end }} -{{- end }} - -{{- define "gitea.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -If release name contains chart name it will be used as a full name. -*/}} -{{- define "gitea.fullname" -}} -{{- if .Values.fullnameOverride -}} -{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} -{{- else -}} -{{- $name := default .Chart.Name .Values.nameOverride -}} -{{- if contains $name .Release.Name -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "gitea.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create image name and tag used by the deployment. -*/}} -{{- define "gitea.image" -}} -{{- $registry := .Values.global.imageRegistry | default .Values.image.registry -}} -{{- $repository := .Values.image.repository -}} -{{- $separator := ":" -}} -{{- $tag := .Values.image.tag | default .Chart.AppVersion -}} -{{- $rootless := ternary "-rootless" "" (.Values.image.rootless) -}} -{{- $digest := "" -}} -{{- if .Values.image.digest }} - {{- $digest = (printf "@%s" (.Values.image.digest | toString)) -}} -{{- end -}} -{{- if $registry }} - {{- printf "%s/%s%s%s%s%s" $registry $repository $separator $tag $rootless $digest -}} -{{- else -}} - {{- printf "%s%s%s%s%s" $repository $separator $tag $rootless $digest -}} -{{- end -}} -{{- end -}} - -{{/* -Docker Image Registry Secret Names evaluating values as templates -*/}} -{{- define "gitea.images.pullSecrets" -}} -{{- $pullSecrets := .Values.imagePullSecrets -}} -{{- range .Values.global.imagePullSecrets -}} - {{- $pullSecrets = append $pullSecrets (dict "name" .) -}} -{{- end -}} -{{- if (not (empty $pullSecrets)) }} -imagePullSecrets: -{{ toYaml $pullSecrets }} -{{- end }} -{{- end -}} - - -{{/* -Storage Class -*/}} -{{- define "gitea.persistence.storageClass" -}} -{{- $storageClass := .Values.global.storageClass | default .Values.persistence.storageClass }} -{{- if $storageClass }} -storageClassName: {{ $storageClass | quote }} -{{- end }} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "gitea.labels" -}} -helm.sh/chart: {{ include "gitea.chart" . }} -app: {{ include "gitea.name" . }} -{{ include "gitea.selectorLabels" . }} -app.kubernetes.io/version: {{ .Values.image.tag | default .Chart.AppVersion | quote }} -version: {{ .Values.image.tag | default .Chart.AppVersion | quote }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "gitea.selectorLabels" -}} -app.kubernetes.io/name: {{ include "gitea.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{- define "postgresql-ha.dns" -}} -{{- if (index .Values "postgresql-ha").enabled -}} -{{- printf "%s-postgresql-ha-postgresql.%s.svc.%s:%g" .Release.Name .Release.Namespace .Values.clusterDomain (index .Values "postgresql-ha" "service" "ports" "postgresql") -}} -{{- end -}} -{{- end -}} - -{{- define "postgresql.dns" -}} -{{- if (index .Values "postgresql").enabled -}} -{{- printf "%s-postgresql.%s.svc.%s:%g" .Release.Name .Release.Namespace .Values.clusterDomain .Values.postgresql.global.postgresql.service.ports.postgresql -}} -{{- end -}} -{{- end -}} - -{{- define "redis.dns" -}} -{{- if (index .Values "redis-cluster").enabled -}} -{{- printf "redis+cluster://:%s@%s-redis-cluster-headless.%s.svc.%s:%g/0?pool_size=100&idle_timeout=180s&" (index .Values "redis-cluster").global.redis.password .Release.Name .Release.Namespace .Values.clusterDomain (index .Values "redis-cluster").service.ports.redis -}} -{{- end -}} -{{- end -}} - -{{- define "redis.port" -}} -{{- if (index .Values "redis-cluster").enabled -}} -{{ (index .Values "redis-cluster").service.ports.redis }} -{{- end -}} -{{- end -}} - -{{- define "redis.servicename" -}} -{{- if (index .Values "redis-cluster").enabled -}} -{{- printf "%s-redis-cluster-headless.%s.svc.%s" .Release.Name .Release.Namespace .Values.clusterDomain -}} -{{- end -}} -{{- end -}} - -{{- define "gitea.default_domain" -}} -{{- printf "%s-gitea.%s.svc.%s" (include "gitea.fullname" .) .Release.Namespace .Values.clusterDomain | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{- define "gitea.ldap_settings" -}} -{{- $idx := index . 0 }} -{{- $values := index . 1 }} - -{{- if not (hasKey $values "bindDn") -}} -{{- $_ := set $values "bindDn" "" -}} -{{- end -}} - -{{- if not (hasKey $values "bindPassword") -}} -{{- $_ := set $values "bindPassword" "" -}} -{{- end -}} - -{{- $flags := list "notActive" "skipTlsVerify" "allowDeactivateAll" "synchronizeUsers" "attributesInBind" -}} -{{- range $key, $val := $values -}} -{{- if and (ne $key "enabled") (ne $key "existingSecret") -}} -{{- if eq $key "bindDn" -}} -{{- printf "--%s \"${GITEA_LDAP_BIND_DN_%d}\" " ($key | kebabcase) ($idx) -}} -{{- else if eq $key "bindPassword" -}} -{{- printf "--%s \"${GITEA_LDAP_PASSWORD_%d}\" " ($key | kebabcase) ($idx) -}} -{{- else if eq $key "port" -}} -{{- printf "--%s %d " $key ($val | int) -}} -{{- else if has $key $flags -}} -{{- printf "--%s " ($key | kebabcase) -}} -{{- else -}} -{{- printf "--%s %s " ($key | kebabcase) ($val | squote) -}} -{{- end -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{- define "gitea.oauth_settings" -}} -{{- $idx := index . 0 }} -{{- $values := index . 1 }} - -{{- if not (hasKey $values "key") -}} -{{- $_ := set $values "key" (printf "${GITEA_OAUTH_KEY_%d}" $idx) -}} -{{- end -}} - -{{- if not (hasKey $values "secret") -}} -{{- $_ := set $values "secret" (printf "${GITEA_OAUTH_SECRET_%d}" $idx) -}} -{{- end -}} - -{{- range $key, $val := $values -}} -{{- if ne $key "existingSecret" -}} -{{- printf "--%s %s " ($key | kebabcase) ($val | quote) -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{- define "gitea.public_protocol" -}} -{{- if and .Values.ingress.enabled (gt (len .Values.ingress.tls) 0) -}} -https -{{- else -}} -{{ .Values.gitea.config.server.PROTOCOL }} -{{- end -}} -{{- end -}} - -{{- define "gitea.inline_configuration" -}} - {{- include "gitea.inline_configuration.init" . -}} - {{- include "gitea.inline_configuration.defaults" . -}} - - {{- $generals := list -}} - {{- $inlines := dict -}} - - {{- range $key, $value := .Values.gitea.config }} - {{- if kindIs "map" $value }} - {{- if gt (len $value) 0 }} - {{- $section := default list (get $inlines $key) -}} - {{- range $n_key, $n_value := $value }} - {{- $section = append $section (printf "%s=%v" $n_key $n_value) -}} - {{- end }} - {{- $_ := set $inlines $key (join "\n" $section) -}} - {{- end -}} - {{- else }} - {{- if or (eq $key "APP_NAME") (eq $key "RUN_USER") (eq $key "RUN_MODE") -}} - {{- $generals = append $generals (printf "%s=%s" $key $value) -}} - {{- else -}} - {{- (printf "Key %s cannot be on top level of configuration" $key) | fail -}} - {{- end -}} - - {{- end }} - {{- end }} - - {{- $_ := set $inlines "_generals_" (join "\n" $generals) -}} - {{- toYaml $inlines -}} -{{- end -}} - -{{- define "gitea.inline_configuration.init" -}} - {{- if not (hasKey .Values.gitea.config "cache") -}} - {{- $_ := set .Values.gitea.config "cache" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "server") -}} - {{- $_ := set .Values.gitea.config "server" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "metrics") -}} - {{- $_ := set .Values.gitea.config "metrics" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "database") -}} - {{- $_ := set .Values.gitea.config "database" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "security") -}} - {{- $_ := set .Values.gitea.config "security" dict -}} - {{- end -}} - {{- if not .Values.gitea.config.repository -}} - {{- $_ := set .Values.gitea.config "repository" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "oauth2") -}} - {{- $_ := set .Values.gitea.config "oauth2" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "session") -}} - {{- $_ := set .Values.gitea.config "session" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "queue") -}} - {{- $_ := set .Values.gitea.config "queue" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "queue.issue_indexer") -}} - {{- $_ := set .Values.gitea.config "queue.issue_indexer" dict -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config "indexer") -}} - {{- $_ := set .Values.gitea.config "indexer" dict -}} - {{- end -}} -{{- end -}} - -{{- define "gitea.inline_configuration.defaults" -}} - {{- include "gitea.inline_configuration.defaults.server" . -}} - {{- include "gitea.inline_configuration.defaults.database" . -}} - - {{- if not .Values.gitea.config.repository.ROOT -}} - {{- $_ := set .Values.gitea.config.repository "ROOT" "/data/git/gitea-repositories" -}} - {{- end -}} - {{- if not .Values.gitea.config.security.INSTALL_LOCK -}} - {{- $_ := set .Values.gitea.config.security "INSTALL_LOCK" "true" -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config.metrics "ENABLED") -}} - {{- $_ := set .Values.gitea.config.metrics "ENABLED" .Values.gitea.metrics.enabled -}} - {{- end -}} - {{- if (index .Values "redis-cluster").enabled -}} - {{- $_ := set .Values.gitea.config.cache "ENABLED" "true" -}} - {{- $_ := set .Values.gitea.config.cache "ADAPTER" "redis" -}} - {{- if not (.Values.gitea.config.cache.HOST) -}} - {{- $_ := set .Values.gitea.config.cache "HOST" (include "redis.dns" .) -}} - {{- end -}} - {{- end -}} - {{- /* redis queue */ -}} - {{- if (index .Values "redis-cluster").enabled -}} - {{- $_ := set .Values.gitea.config.queue "TYPE" "redis" -}} - {{- $_ := set .Values.gitea.config.queue "CONN_STR" (include "redis.dns" .) -}} - {{- end -}} - {{- if not (get .Values.gitea.config.session "PROVIDER") -}} - {{- $_ := set .Values.gitea.config.session "PROVIDER" "redis" -}} - {{- end -}} - {{- if not (get .Values.gitea.config.session "PROVIDER_CONFIG") -}} - {{- $_ := set .Values.gitea.config.session "PROVIDER_CONFIG" (include "redis.dns" .) -}} - {{- end -}} - {{- if not .Values.gitea.config.indexer.ISSUE_INDEXER_TYPE -}} - {{- $_ := set .Values.gitea.config.indexer "ISSUE_INDEXER_TYPE" "db" -}} - {{- end -}} -{{- end -}} - -{{- define "gitea.inline_configuration.defaults.server" -}} - {{- if not (hasKey .Values.gitea.config.server "HTTP_PORT") -}} - {{- $_ := set .Values.gitea.config.server "HTTP_PORT" .Values.service.http.port -}} - {{- end -}} - {{- if not .Values.gitea.config.server.PROTOCOL -}} - {{- $_ := set .Values.gitea.config.server "PROTOCOL" "http" -}} - {{- end -}} - {{- if not (.Values.gitea.config.server.DOMAIN) -}} - {{- if gt (len .Values.ingress.hosts) 0 -}} - {{- $_ := set .Values.gitea.config.server "DOMAIN" ( tpl (index .Values.ingress.hosts 0).host $) -}} - {{- else -}} - {{- $_ := set .Values.gitea.config.server "DOMAIN" (include "gitea.default_domain" .) -}} - {{- end -}} - {{- end -}} - {{- if not .Values.gitea.config.server.ROOT_URL -}} - {{- $_ := set .Values.gitea.config.server "ROOT_URL" (printf "%s://%s" (include "gitea.public_protocol" .) .Values.gitea.config.server.DOMAIN) -}} - {{- end -}} - {{- if not .Values.gitea.config.server.SSH_DOMAIN -}} - {{- $_ := set .Values.gitea.config.server "SSH_DOMAIN" .Values.gitea.config.server.DOMAIN -}} - {{- end -}} - {{- if not .Values.gitea.config.server.SSH_PORT -}} - {{- $_ := set .Values.gitea.config.server "SSH_PORT" .Values.service.ssh.port -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config.server "SSH_LISTEN_PORT") -}} - {{- if not .Values.image.rootless -}} - {{- $_ := set .Values.gitea.config.server "SSH_LISTEN_PORT" .Values.gitea.config.server.SSH_PORT -}} - {{- else -}} - {{- $_ := set .Values.gitea.config.server "SSH_LISTEN_PORT" "2222" -}} - {{- end -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config.server "START_SSH_SERVER") -}} - {{- if .Values.image.rootless -}} - {{- $_ := set .Values.gitea.config.server "START_SSH_SERVER" "true" -}} - {{- end -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config.server "APP_DATA_PATH") -}} - {{- $_ := set .Values.gitea.config.server "APP_DATA_PATH" "/data" -}} - {{- end -}} - {{- if not (hasKey .Values.gitea.config.server "ENABLE_PPROF") -}} - {{- $_ := set .Values.gitea.config.server "ENABLE_PPROF" false -}} - {{- end -}} -{{- end -}} - -{{- define "gitea.inline_configuration.defaults.database" -}} - {{- if (index .Values "postgresql-ha" "enabled") -}} - {{- $_ := set .Values.gitea.config.database "DB_TYPE" "postgres" -}} - {{- if not (.Values.gitea.config.database.HOST) -}} - {{- $_ := set .Values.gitea.config.database "HOST" (include "postgresql-ha.dns" .) -}} - {{- end -}} - {{- $_ := set .Values.gitea.config.database "NAME" (index .Values "postgresql-ha" "global" "postgresql" "database") -}} - {{- $_ := set .Values.gitea.config.database "USER" (index .Values "postgresql-ha" "global" "postgresql" "username") -}} - {{- $_ := set .Values.gitea.config.database "PASSWD" (index .Values "postgresql-ha" "global" "postgresql" "password") -}} - {{- end -}} - {{- if (index .Values "postgresql" "enabled") -}} - {{- $_ := set .Values.gitea.config.database "DB_TYPE" "postgres" -}} - {{- if not (.Values.gitea.config.database.HOST) -}} - {{- $_ := set .Values.gitea.config.database "HOST" (include "postgresql.dns" .) -}} - {{- end -}} - {{- $_ := set .Values.gitea.config.database "NAME" .Values.postgresql.global.postgresql.auth.database -}} - {{- $_ := set .Values.gitea.config.database "USER" .Values.postgresql.global.postgresql.auth.username -}} - {{- $_ := set .Values.gitea.config.database "PASSWD" .Values.postgresql.global.postgresql.auth.password -}} - {{- end -}} -{{- end -}} - -{{- define "gitea.init-additional-mounts" -}} - {{- /* Honor the deprecated extraVolumeMounts variable when defined */ -}} - {{- if gt (len .Values.extraInitVolumeMounts) 0 -}} - {{- toYaml .Values.extraInitVolumeMounts -}} - {{- else if gt (len .Values.extraVolumeMounts) 0 -}} - {{- toYaml .Values.extraVolumeMounts -}} - {{- end -}} -{{- end -}} - -{{- define "gitea.container-additional-mounts" -}} - {{- /* Honor the deprecated extraVolumeMounts variable when defined */ -}} - {{- if gt (len .Values.extraContainerVolumeMounts) 0 -}} - {{- toYaml .Values.extraContainerVolumeMounts -}} - {{- else if gt (len .Values.extraVolumeMounts) 0 -}} - {{- toYaml .Values.extraVolumeMounts -}} - {{- end -}} -{{- end -}} - -{{- define "gitea.gpg-key-secret-name" -}} -{{ default (printf "%s-gpg-key" (include "gitea.fullname" .)) .Values.signing.existingSecret }} -{{- end -}} - -{{- define "gitea.serviceAccountName" -}} -{{ .Values.serviceAccount.name | default (include "gitea.fullname" .) }} -{{- end -}} +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} + +{{- /* multiple replicas assertions */ -}} +{{- if gt .Values.replicaCount 1.0 -}} + {{- fail "When using multiple replicas, a RWX file system is required" -}} + {{- if eq (get (.Values.persistence.accessModes 0) "ReadWriteOnce") -}} + {{- fail "When using multiple replicas, a RWX file system is required" -}} + {{- end }} + + {{- if eq (get .Values.gitea.config.indexer "ISSUE_INDEXER_TYPE") "bleve" -}} + {{- fail "When using multiple replicas, the repo indexer must be set to 'meilisearch' or 'elasticsearch'" -}} + {{- end }} + + {{- if and (eq .Values.gitea.config.indexer.REPO_INDEXER_TYPE "bleve") (eq .Values.gitea.config.indexer.REPO_INDEXER_ENABLED "true") -}} + {{- fail "When using multiple replicas, the repo indexer must be set to 'meilisearch' or 'elasticsearch'" -}} + {{- end }} + + {{- if eq .Values.gitea.config.indexer.ISSUE_INDEXER_TYPE "bleve" -}} + {{- (printf "DEBUG: When using multiple replicas, the repo indexer must be set to 'meilisearch' or 'elasticsearch'") | fail -}} + {{- end }} +{{- end }} + +{{- define "gitea.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "gitea.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "gitea.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create image name and tag used by the deployment. +*/}} +{{- define "gitea.image" -}} +{{- $registry := .Values.global.imageRegistry | default .Values.image.registry -}} +{{- $repository := .Values.image.repository -}} +{{- $separator := ":" -}} +{{- $tag := .Values.image.tag | default .Chart.AppVersion -}} +{{- $rootless := ternary "-rootless" "" (.Values.image.rootless) -}} +{{- $digest := "" -}} +{{- if .Values.image.digest }} + {{- $digest = (printf "@%s" (.Values.image.digest | toString)) -}} +{{- end -}} +{{- if $registry }} + {{- printf "%s/%s%s%s%s%s" $registry $repository $separator $tag $rootless $digest -}} +{{- else -}} + {{- printf "%s%s%s%s%s" $repository $separator $tag $rootless $digest -}} +{{- end -}} +{{- end -}} + +{{/* +Docker Image Registry Secret Names evaluating values as templates +*/}} +{{- define "gitea.images.pullSecrets" -}} +{{- $pullSecrets := .Values.imagePullSecrets -}} +{{- range .Values.global.imagePullSecrets -}} + {{- $pullSecrets = append $pullSecrets (dict "name" .) -}} +{{- end -}} +{{- if (not (empty $pullSecrets)) }} +imagePullSecrets: +{{ toYaml $pullSecrets }} +{{- end }} +{{- end -}} + + +{{/* +Storage Class +*/}} +{{- define "gitea.persistence.storageClass" -}} +{{- $storageClass := .Values.global.storageClass | default .Values.persistence.storageClass }} +{{- if $storageClass }} +storageClassName: {{ $storageClass | quote }} +{{- end }} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "gitea.labels" -}} +helm.sh/chart: {{ include "gitea.chart" . }} +app: {{ include "gitea.name" . }} +{{ include "gitea.selectorLabels" . }} +app.kubernetes.io/version: {{ .Values.image.tag | default .Chart.AppVersion | quote }} +version: {{ .Values.image.tag | default .Chart.AppVersion | quote }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + +{{/* +Selector labels +*/}} +{{- define "gitea.selectorLabels" -}} +app.kubernetes.io/name: {{ include "gitea.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} + +{{- define "postgresql-ha.dns" -}} +{{- if (index .Values "postgresql-ha").enabled -}} +{{- printf "%s-postgresql-ha-postgresql.%s.svc.%s:%g" .Release.Name .Release.Namespace .Values.clusterDomain (index .Values "postgresql-ha" "service" "ports" "postgresql") -}} +{{- end -}} +{{- end -}} + +{{- define "postgresql.dns" -}} +{{- if (index .Values "postgresql").enabled -}} +{{- printf "%s-postgresql.%s.svc.%s:%g" .Release.Name .Release.Namespace .Values.clusterDomain .Values.postgresql.global.postgresql.service.ports.postgresql -}} +{{- end -}} +{{- end -}} + +{{- define "redis.dns" -}} +{{- if (index .Values "redis-cluster").enabled -}} +{{- printf "redis+cluster://:%s@%s-redis-cluster-headless.%s.svc.%s:%g/0?pool_size=100&idle_timeout=180s&" (index .Values "redis-cluster").global.redis.password .Release.Name .Release.Namespace .Values.clusterDomain (index .Values "redis-cluster").service.ports.redis -}} +{{- end -}} +{{- end -}} + +{{- define "redis.port" -}} +{{- if (index .Values "redis-cluster").enabled -}} +{{ (index .Values "redis-cluster").service.ports.redis }} +{{- end -}} +{{- end -}} + +{{- define "redis.servicename" -}} +{{- if (index .Values "redis-cluster").enabled -}} +{{- printf "%s-redis-cluster-headless.%s.svc.%s" .Release.Name .Release.Namespace .Values.clusterDomain -}} +{{- end -}} +{{- end -}} + +{{- define "gitea.default_domain" -}} +{{- printf "%s-gitea.%s.svc.%s" (include "gitea.fullname" .) .Release.Namespace .Values.clusterDomain | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{- define "gitea.ldap_settings" -}} +{{- $idx := index . 0 }} +{{- $values := index . 1 }} + +{{- if not (hasKey $values "bindDn") -}} +{{- $_ := set $values "bindDn" "" -}} +{{- end -}} + +{{- if not (hasKey $values "bindPassword") -}} +{{- $_ := set $values "bindPassword" "" -}} +{{- end -}} + +{{- $flags := list "notActive" "skipTlsVerify" "allowDeactivateAll" "synchronizeUsers" "attributesInBind" -}} +{{- range $key, $val := $values -}} +{{- if and (ne $key "enabled") (ne $key "existingSecret") -}} +{{- if eq $key "bindDn" -}} +{{- printf "--%s \"${GITEA_LDAP_BIND_DN_%d}\" " ($key | kebabcase) ($idx) -}} +{{- else if eq $key "bindPassword" -}} +{{- printf "--%s \"${GITEA_LDAP_PASSWORD_%d}\" " ($key | kebabcase) ($idx) -}} +{{- else if eq $key "port" -}} +{{- printf "--%s %d " $key ($val | int) -}} +{{- else if has $key $flags -}} +{{- printf "--%s " ($key | kebabcase) -}} +{{- else -}} +{{- printf "--%s %s " ($key | kebabcase) ($val | squote) -}} +{{- end -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{- define "gitea.oauth_settings" -}} +{{- $idx := index . 0 }} +{{- $values := index . 1 }} + +{{- if not (hasKey $values "key") -}} +{{- $_ := set $values "key" (printf "${GITEA_OAUTH_KEY_%d}" $idx) -}} +{{- end -}} + +{{- if not (hasKey $values "secret") -}} +{{- $_ := set $values "secret" (printf "${GITEA_OAUTH_SECRET_%d}" $idx) -}} +{{- end -}} + +{{- range $key, $val := $values -}} +{{- if ne $key "existingSecret" -}} +{{- printf "--%s %s " ($key | kebabcase) ($val | quote) -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{- define "gitea.public_protocol" -}} +{{- if and .Values.ingress.enabled (gt (len .Values.ingress.tls) 0) -}} +https +{{- else -}} +{{ .Values.gitea.config.server.PROTOCOL }} +{{- end -}} +{{- end -}} + +{{- define "gitea.inline_configuration" -}} + {{- include "gitea.inline_configuration.init" . -}} + {{- include "gitea.inline_configuration.defaults" . -}} + + {{- $generals := list -}} + {{- $inlines := dict -}} + + {{- range $key, $value := .Values.gitea.config }} + {{- if kindIs "map" $value }} + {{- if gt (len $value) 0 }} + {{- $section := default list (get $inlines $key) -}} + {{- range $n_key, $n_value := $value }} + {{- $section = append $section (printf "%s=%v" $n_key $n_value) -}} + {{- end }} + {{- $_ := set $inlines $key (join "\n" $section) -}} + {{- end -}} + {{- else }} + {{- if or (eq $key "APP_NAME") (eq $key "RUN_USER") (eq $key "RUN_MODE") -}} + {{- $generals = append $generals (printf "%s=%s" $key $value) -}} + {{- else -}} + {{- (printf "Key %s cannot be on top level of configuration" $key) | fail -}} + {{- end -}} + + {{- end }} + {{- end }} + + {{- $_ := set $inlines "_generals_" (join "\n" $generals) -}} + {{- toYaml $inlines -}} +{{- end -}} + +{{- define "gitea.inline_configuration.init" -}} + {{- if not (hasKey .Values.gitea.config "cache") -}} + {{- $_ := set .Values.gitea.config "cache" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "server") -}} + {{- $_ := set .Values.gitea.config "server" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "metrics") -}} + {{- $_ := set .Values.gitea.config "metrics" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "database") -}} + {{- $_ := set .Values.gitea.config "database" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "security") -}} + {{- $_ := set .Values.gitea.config "security" dict -}} + {{- end -}} + {{- if not .Values.gitea.config.repository -}} + {{- $_ := set .Values.gitea.config "repository" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "oauth2") -}} + {{- $_ := set .Values.gitea.config "oauth2" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "session") -}} + {{- $_ := set .Values.gitea.config "session" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "queue") -}} + {{- $_ := set .Values.gitea.config "queue" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "queue.issue_indexer") -}} + {{- $_ := set .Values.gitea.config "queue.issue_indexer" dict -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config "indexer") -}} + {{- $_ := set .Values.gitea.config "indexer" dict -}} + {{- end -}} +{{- end -}} + +{{- define "gitea.inline_configuration.defaults" -}} + {{- include "gitea.inline_configuration.defaults.server" . -}} + {{- include "gitea.inline_configuration.defaults.database" . -}} + + {{- if not .Values.gitea.config.repository.ROOT -}} + {{- $_ := set .Values.gitea.config.repository "ROOT" "/data/git/gitea-repositories" -}} + {{- end -}} + {{- if not .Values.gitea.config.security.INSTALL_LOCK -}} + {{- $_ := set .Values.gitea.config.security "INSTALL_LOCK" "true" -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config.metrics "ENABLED") -}} + {{- $_ := set .Values.gitea.config.metrics "ENABLED" .Values.gitea.metrics.enabled -}} + {{- end -}} + {{- if (index .Values "redis-cluster").enabled -}} + {{- $_ := set .Values.gitea.config.cache "ENABLED" "true" -}} + {{- $_ := set .Values.gitea.config.cache "ADAPTER" "redis" -}} + {{- if not (.Values.gitea.config.cache.HOST) -}} + {{- $_ := set .Values.gitea.config.cache "HOST" (include "redis.dns" .) -}} + {{- end -}} + {{- end -}} + {{- /* redis queue */ -}} + {{- if (index .Values "redis-cluster").enabled -}} + {{- $_ := set .Values.gitea.config.queue "TYPE" "redis" -}} + {{- $_ := set .Values.gitea.config.queue "CONN_STR" (include "redis.dns" .) -}} + {{- end -}} + {{- if not (get .Values.gitea.config.session "PROVIDER") -}} + {{- $_ := set .Values.gitea.config.session "PROVIDER" "redis" -}} + {{- end -}} + {{- if not (get .Values.gitea.config.session "PROVIDER_CONFIG") -}} + {{- $_ := set .Values.gitea.config.session "PROVIDER_CONFIG" (include "redis.dns" .) -}} + {{- end -}} + {{- if not .Values.gitea.config.indexer.ISSUE_INDEXER_TYPE -}} + {{- $_ := set .Values.gitea.config.indexer "ISSUE_INDEXER_TYPE" "db" -}} + {{- end -}} +{{- end -}} + +{{- define "gitea.inline_configuration.defaults.server" -}} + {{- if not (hasKey .Values.gitea.config.server "HTTP_PORT") -}} + {{- $_ := set .Values.gitea.config.server "HTTP_PORT" .Values.service.http.port -}} + {{- end -}} + {{- if not .Values.gitea.config.server.PROTOCOL -}} + {{- $_ := set .Values.gitea.config.server "PROTOCOL" "http" -}} + {{- end -}} + {{- if not (.Values.gitea.config.server.DOMAIN) -}} + {{- if gt (len .Values.ingress.hosts) 0 -}} + {{- $_ := set .Values.gitea.config.server "DOMAIN" ( tpl (index .Values.ingress.hosts 0).host $) -}} + {{- else -}} + {{- $_ := set .Values.gitea.config.server "DOMAIN" (include "gitea.default_domain" .) -}} + {{- end -}} + {{- end -}} + {{- if not .Values.gitea.config.server.ROOT_URL -}} + {{- $_ := set .Values.gitea.config.server "ROOT_URL" (printf "%s://%s" (include "gitea.public_protocol" .) .Values.gitea.config.server.DOMAIN) -}} + {{- end -}} + {{- if not .Values.gitea.config.server.SSH_DOMAIN -}} + {{- $_ := set .Values.gitea.config.server "SSH_DOMAIN" .Values.gitea.config.server.DOMAIN -}} + {{- end -}} + {{- if not .Values.gitea.config.server.SSH_PORT -}} + {{- $_ := set .Values.gitea.config.server "SSH_PORT" .Values.service.ssh.port -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config.server "SSH_LISTEN_PORT") -}} + {{- if not .Values.image.rootless -}} + {{- $_ := set .Values.gitea.config.server "SSH_LISTEN_PORT" .Values.gitea.config.server.SSH_PORT -}} + {{- else -}} + {{- $_ := set .Values.gitea.config.server "SSH_LISTEN_PORT" "2222" -}} + {{- end -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config.server "START_SSH_SERVER") -}} + {{- if .Values.image.rootless -}} + {{- $_ := set .Values.gitea.config.server "START_SSH_SERVER" "true" -}} + {{- end -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config.server "APP_DATA_PATH") -}} + {{- $_ := set .Values.gitea.config.server "APP_DATA_PATH" "/data" -}} + {{- end -}} + {{- if not (hasKey .Values.gitea.config.server "ENABLE_PPROF") -}} + {{- $_ := set .Values.gitea.config.server "ENABLE_PPROF" false -}} + {{- end -}} +{{- end -}} + +{{- define "gitea.inline_configuration.defaults.database" -}} + {{- if (index .Values "postgresql-ha" "enabled") -}} + {{- $_ := set .Values.gitea.config.database "DB_TYPE" "postgres" -}} + {{- if not (.Values.gitea.config.database.HOST) -}} + {{- $_ := set .Values.gitea.config.database "HOST" (include "postgresql-ha.dns" .) -}} + {{- end -}} + {{- $_ := set .Values.gitea.config.database "NAME" (index .Values "postgresql-ha" "global" "postgresql" "database") -}} + {{- $_ := set .Values.gitea.config.database "USER" (index .Values "postgresql-ha" "global" "postgresql" "username") -}} + {{- $_ := set .Values.gitea.config.database "PASSWD" (index .Values "postgresql-ha" "global" "postgresql" "password") -}} + {{- end -}} + {{- if (index .Values "postgresql" "enabled") -}} + {{- $_ := set .Values.gitea.config.database "DB_TYPE" "postgres" -}} + {{- if not (.Values.gitea.config.database.HOST) -}} + {{- $_ := set .Values.gitea.config.database "HOST" (include "postgresql.dns" .) -}} + {{- end -}} + {{- $_ := set .Values.gitea.config.database "NAME" .Values.postgresql.global.postgresql.auth.database -}} + {{- $_ := set .Values.gitea.config.database "USER" .Values.postgresql.global.postgresql.auth.username -}} + {{- $_ := set .Values.gitea.config.database "PASSWD" .Values.postgresql.global.postgresql.auth.password -}} + {{- end -}} +{{- end -}} + +{{- define "gitea.init-additional-mounts" -}} + {{- /* Honor the deprecated extraVolumeMounts variable when defined */ -}} + {{- if gt (len .Values.extraInitVolumeMounts) 0 -}} + {{- toYaml .Values.extraInitVolumeMounts -}} + {{- else if gt (len .Values.extraVolumeMounts) 0 -}} + {{- toYaml .Values.extraVolumeMounts -}} + {{- end -}} +{{- end -}} + +{{- define "gitea.container-additional-mounts" -}} + {{- /* Honor the deprecated extraVolumeMounts variable when defined */ -}} + {{- if gt (len .Values.extraContainerVolumeMounts) 0 -}} + {{- toYaml .Values.extraContainerVolumeMounts -}} + {{- else if gt (len .Values.extraVolumeMounts) 0 -}} + {{- toYaml .Values.extraVolumeMounts -}} + {{- end -}} +{{- end -}} + +{{- define "gitea.gpg-key-secret-name" -}} +{{ default (printf "%s-gpg-key" (include "gitea.fullname" .)) .Values.signing.existingSecret }} +{{- end -}} + +{{- define "gitea.serviceAccountName" -}} +{{ .Values.serviceAccount.name | default (include "gitea.fullname" .) }} +{{- end -}} diff --git a/unittests/deployment/inline-config.yaml b/unittests/deployment/inline-config.yaml index b96792c..50480fb 100644 --- a/unittests/deployment/inline-config.yaml +++ b/unittests/deployment/inline-config.yaml @@ -1,25 +1,25 @@ -suite: config template -release: - name: gitea-unittests - namespace: testing -templates: - - templates/gitea/config.yaml -tests: - - it: inline config stringData.server using TPL - set: - global.giteaHostName: "gitea.example.com" - ingress.enabled: true - ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}" - ingress.tls: - - secretName: gitea-tls - hosts: - - "{{ .Values.global.giteaHostName }}" - asserts: - - equal: - path: stringData.server.DOMAIN - value: "gitea.example.com" - documentIndex: 0 - - equal: - path: stringData.server.ROOT_URL - value: "https://gitea.example.com" +suite: config template +release: + name: gitea-unittests + namespace: testing +templates: + - templates/gitea/config.yaml +tests: + - it: inline config stringData.server using TPL + set: + global.giteaHostName: "gitea.example.com" + ingress.enabled: true + ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}" + ingress.tls: + - secretName: gitea-tls + hosts: + - "{{ .Values.global.giteaHostName }}" + asserts: + - equal: + path: stringData.server.DOMAIN + value: "gitea.example.com" + documentIndex: 0 + - equal: + path: stringData.server.ROOT_URL + value: "https://gitea.example.com" documentIndex: 0 \ No newline at end of file From 57e8697d52ea0767b94addbf9f467942a3913412 Mon Sep 17 00:00:00 2001 From: 212597596 Date: Tue, 31 Oct 2023 12:00:34 +0200 Subject: [PATCH 12/21] Converting assets to matchRegex --- unittests/deployment/inline-config.yaml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/unittests/deployment/inline-config.yaml b/unittests/deployment/inline-config.yaml index 50480fb..641dd4f 100644 --- a/unittests/deployment/inline-config.yaml +++ b/unittests/deployment/inline-config.yaml @@ -15,11 +15,15 @@ tests: hosts: - "{{ .Values.global.giteaHostName }}" asserts: - - equal: - path: stringData.server.DOMAIN - value: "gitea.example.com" + - matchRegex: + path: stringData.server + pattern: DOMAIN\: "gitea.example.com" documentIndex: 0 - - equal: - path: stringData.server.ROOT_URL - value: "https://gitea.example.com" + - matchRegex: + path: stringData.server + pattern: ROOT_URL\: "https://gitea.example.com" + documentIndex: 0 + - matchRegex: + path: stringData.server + pattern: SSH_DOMAIN\: "gitea.example.com" documentIndex: 0 \ No newline at end of file From 83ba8c260abd2773afe4427aec9e678eceaa0b1a Mon Sep 17 00:00:00 2001 From: 212597596 Date: Tue, 31 Oct 2023 12:47:28 +0200 Subject: [PATCH 13/21] Correcting asserts matchRegex patterns --- unittests/deployment/inline-config.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/unittests/deployment/inline-config.yaml b/unittests/deployment/inline-config.yaml index 641dd4f..698d7b2 100644 --- a/unittests/deployment/inline-config.yaml +++ b/unittests/deployment/inline-config.yaml @@ -15,15 +15,18 @@ tests: hosts: - "{{ .Values.global.giteaHostName }}" asserts: + - matchRegex: + path: metadata.name + pattern: -inline-config$ - matchRegex: path: stringData.server - pattern: DOMAIN\: "gitea.example.com" + pattern: DOMAIN=gitea\.example\.com documentIndex: 0 - matchRegex: path: stringData.server - pattern: ROOT_URL\: "https://gitea.example.com" + pattern: ROOT_URL=https://gitea\.example\.com documentIndex: 0 - matchRegex: path: stringData.server - pattern: SSH_DOMAIN\: "gitea.example.com" + pattern: SSH_DOMAIN=gitea\.example\.com documentIndex: 0 \ No newline at end of file From 3fb40da20c9cfbb919cb1c147a23aae13625b248 Mon Sep 17 00:00:00 2001 From: Ceddaerrix Date: Wed, 1 Nov 2023 07:11:53 +0000 Subject: [PATCH 14/21] Correcting pattern of first matchRegex --- unittests/deployment/inline-config.yaml | 62 ++++++++++++------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/unittests/deployment/inline-config.yaml b/unittests/deployment/inline-config.yaml index 698d7b2..685ad73 100644 --- a/unittests/deployment/inline-config.yaml +++ b/unittests/deployment/inline-config.yaml @@ -1,32 +1,32 @@ -suite: config template -release: - name: gitea-unittests - namespace: testing -templates: - - templates/gitea/config.yaml -tests: - - it: inline config stringData.server using TPL - set: - global.giteaHostName: "gitea.example.com" - ingress.enabled: true - ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}" - ingress.tls: - - secretName: gitea-tls - hosts: - - "{{ .Values.global.giteaHostName }}" - asserts: - - matchRegex: - path: metadata.name - pattern: -inline-config$ - - matchRegex: - path: stringData.server - pattern: DOMAIN=gitea\.example\.com - documentIndex: 0 - - matchRegex: - path: stringData.server - pattern: ROOT_URL=https://gitea\.example\.com - documentIndex: 0 - - matchRegex: - path: stringData.server - pattern: SSH_DOMAIN=gitea\.example\.com +suite: config template +release: + name: gitea-unittests + namespace: testing +templates: + - templates/gitea/config.yaml +tests: + - it: inline config stringData.server using TPL + set: + global.giteaHostName: "gitea.example.com" + ingress.enabled: true + ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}" + ingress.tls: + - secretName: gitea-tls + hosts: + - "{{ .Values.global.giteaHostName }}" + asserts: + - matchRegex: + path: metadata.name + pattern: .*-inline-config$ + - matchRegex: + path: stringData.server + pattern: DOMAIN=gitea\.example\.com + documentIndex: 0 + - matchRegex: + path: stringData.server + pattern: ROOT_URL=https://gitea\.example\.com + documentIndex: 0 + - matchRegex: + path: stringData.server + pattern: SSH_DOMAIN=gitea\.example\.com documentIndex: 0 \ No newline at end of file From 560e6aa5f60b820979cc5014e01f5b412e8394f7 Mon Sep 17 00:00:00 2001 From: 212597596 Date: Wed, 1 Nov 2023 09:18:30 +0200 Subject: [PATCH 15/21] Correcting first assert --- unittests/deployment/inline-config.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unittests/deployment/inline-config.yaml b/unittests/deployment/inline-config.yaml index 685ad73..437f458 100644 --- a/unittests/deployment/inline-config.yaml +++ b/unittests/deployment/inline-config.yaml @@ -15,7 +15,8 @@ tests: hosts: - "{{ .Values.global.giteaHostName }}" asserts: - - matchRegex: + - documentIndex: 0 + matchRegex: path: metadata.name pattern: .*-inline-config$ - matchRegex: From ba74af0f015e6016f9be4f16a059fd8870d26382 Mon Sep 17 00:00:00 2001 From: 212597596 Date: Wed, 1 Nov 2023 09:21:41 +0200 Subject: [PATCH 16/21] Adding EOL to unittests/deployment/inline-config.yaml --- unittests/deployment/inline-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/deployment/inline-config.yaml b/unittests/deployment/inline-config.yaml index 437f458..9d47b9b 100644 --- a/unittests/deployment/inline-config.yaml +++ b/unittests/deployment/inline-config.yaml @@ -30,4 +30,4 @@ tests: - matchRegex: path: stringData.server pattern: SSH_DOMAIN=gitea\.example\.com - documentIndex: 0 \ No newline at end of file + documentIndex: 0 From 6b8f45b711de4f04f154e392acd90d9b6d09bc41 Mon Sep 17 00:00:00 2001 From: Ceddaerrix Date: Wed, 1 Nov 2023 07:25:09 +0000 Subject: [PATCH 17/21] Update unittests/deployment/inline-config.yaml --- unittests/deployment/inline-config.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/unittests/deployment/inline-config.yaml b/unittests/deployment/inline-config.yaml index 9d47b9b..ea49668 100644 --- a/unittests/deployment/inline-config.yaml +++ b/unittests/deployment/inline-config.yaml @@ -19,15 +19,15 @@ tests: matchRegex: path: metadata.name pattern: .*-inline-config$ - - matchRegex: + - documentIndex: 0 + matchRegex: path: stringData.server pattern: DOMAIN=gitea\.example\.com - documentIndex: 0 - - matchRegex: + - documentIndex: 0 + matchRegex: path: stringData.server pattern: ROOT_URL=https://gitea\.example\.com - documentIndex: 0 - - matchRegex: + - documentIndex: 0 + matchRegex: path: stringData.server pattern: SSH_DOMAIN=gitea\.example\.com - documentIndex: 0 From fd0888331e37217b83646a403de8055cedef9251 Mon Sep 17 00:00:00 2001 From: 212597596 Date: Wed, 1 Nov 2023 09:31:46 +0200 Subject: [PATCH 18/21] Fixing lint issues in unittests/deployment/inline-config.yaml --- unittests/deployment/inline-config.yaml | 66 ++++++++++++------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/unittests/deployment/inline-config.yaml b/unittests/deployment/inline-config.yaml index ea49668..545bb36 100644 --- a/unittests/deployment/inline-config.yaml +++ b/unittests/deployment/inline-config.yaml @@ -1,33 +1,33 @@ -suite: config template -release: - name: gitea-unittests - namespace: testing -templates: - - templates/gitea/config.yaml -tests: - - it: inline config stringData.server using TPL - set: - global.giteaHostName: "gitea.example.com" - ingress.enabled: true - ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}" - ingress.tls: - - secretName: gitea-tls - hosts: - - "{{ .Values.global.giteaHostName }}" - asserts: - - documentIndex: 0 - matchRegex: - path: metadata.name - pattern: .*-inline-config$ - - documentIndex: 0 - matchRegex: - path: stringData.server - pattern: DOMAIN=gitea\.example\.com - - documentIndex: 0 - matchRegex: - path: stringData.server - pattern: ROOT_URL=https://gitea\.example\.com - - documentIndex: 0 - matchRegex: - path: stringData.server - pattern: SSH_DOMAIN=gitea\.example\.com +suite: config template +release: + name: gitea-unittests + namespace: testing +templates: + - templates/gitea/config.yaml +tests: + - it: inline config stringData.server using TPL + set: + global.giteaHostName: "gitea.example.com" + ingress.enabled: true + ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}" + ingress.tls: + - secretName: gitea-tls + hosts: + - "{{ .Values.global.giteaHostName }}" + asserts: + - documentIndex: 0 + matchRegex: + path: metadata.name + pattern: .*-inline-config$ + - documentIndex: 0 + matchRegex: + path: stringData.server + pattern: DOMAIN=gitea\.example\.com + - documentIndex: 0 + matchRegex: + path: stringData.server + pattern: ROOT_URL=https://gitea\.example\.com + - documentIndex: 0 + matchRegex: + path: stringData.server + pattern: SSH_DOMAIN=gitea\.example\.com From ffb15f0583744c51090f8e43886030fcab5e232f Mon Sep 17 00:00:00 2001 From: 212597596 Date: Wed, 5 Jun 2024 18:27:53 +0300 Subject: [PATCH 19/21] Adding use of TPL to PVC storageClass & ingressClass --- templates/_helpers.tpl | 2 +- templates/gitea/ingress.yaml | 2 +- templates/gitea/pvc.yaml | 2 +- .../deployment/ingress-configuration.yaml | 24 +++++++++++++++++++ unittests/pvc/pvc-configuration.yaml | 19 +++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 unittests/pvc/pvc-configuration.yaml diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 003d39f..07f886e 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -91,7 +91,7 @@ imagePullSecrets: Storage Class */}} {{- define "gitea.persistence.storageClass" -}} -{{- $storageClass := .Values.global.storageClass | default .Values.persistence.storageClass }} +{{- $storageClass := (tpl .Values.global.storageClass $ ) | default (tpl .Values.persistence.storageClass $ ) }} {{- if $storageClass }} storageClassName: {{ $storageClass | quote }} {{- end }} diff --git a/templates/gitea/ingress.yaml b/templates/gitea/ingress.yaml index 9991eec..cd743fe 100644 --- a/templates/gitea/ingress.yaml +++ b/templates/gitea/ingress.yaml @@ -21,7 +21,7 @@ metadata: {{- end }} spec: {{- if .Values.ingress.className }} - ingressClassName: {{ .Values.ingress.className }} + ingressClassName: {{ tpl .Values.ingress.className . }} {{- end }} {{- if .Values.ingress.tls }} tls: diff --git a/templates/gitea/pvc.yaml b/templates/gitea/pvc.yaml index 995bd10..d753f1a 100644 --- a/templates/gitea/pvc.yaml +++ b/templates/gitea/pvc.yaml @@ -15,7 +15,7 @@ spec: {{- end }} volumeMode: Filesystem {{- if .Values.persistence.storageClass }} - storageClassName: {{ .Values.persistence.storageClass }} + storageClassName: {{ tpl .Values.persistence.storageClass . }} {{- end }} {{- with .Values.persistence.volumeName }} volumeName: {{ . }} diff --git a/unittests/deployment/ingress-configuration.yaml b/unittests/deployment/ingress-configuration.yaml index 6a36eb0..39c631d 100644 --- a/unittests/deployment/ingress-configuration.yaml +++ b/unittests/deployment/ingress-configuration.yaml @@ -15,9 +15,33 @@ tests: hosts: - "{{ .Values.global.giteaHostName }}" asserts: + - iskind: + of: Ingress - equal: path: spec.tls[0].hosts[0] value: "gitea.example.com" - equal: path: spec.rules[0].host value: "gitea.example.com" + - it: hostname using TPL + set: + global.ingress.className: "ingress-class" + ingress.className: "{{ .Values.global.ingress.className }}" + ingress.enabled: true + ingress.hosts[0].host: "some-host" + ingress.tls: + - secretName: gitea-tls + hosts: + - "some-host" + asserts: + - iskind: + of: Ingress + - equal: + path: spec.tls[0].hosts[0] + value: "some-host" + - equal: + path: spec.rules[0].host + value: "some-host" + - equal: + path: spec.ingressClassName + value: "ingress-class" diff --git a/unittests/pvc/pvc-configuration.yaml b/unittests/pvc/pvc-configuration.yaml new file mode 100644 index 0000000..3662eb8 --- /dev/null +++ b/unittests/pvc/pvc-configuration.yaml @@ -0,0 +1,19 @@ +suite: PVC template +release: + name: gitea-unittests + namespace: testing +templates: + - templates/gitea/pvc.yaml +tests: + - it: Storage Class using TPL + set: + global.persistence.storageClass: "storage-class" + persistence.enabled: true + persistence.create: true + persistence.storageClass: "{{ .Values.global.persistence.storageClass }}" + asserts: + - iskind: + of: PersistentVolumeClaim + - equal: + path: spec.storageClassName + value: "storage-class" From 29f9cf0b930d543d258e5c3d056399ba1ab8f609 Mon Sep 17 00:00:00 2001 From: 212597596 Date: Wed, 5 Jun 2024 18:27:53 +0300 Subject: [PATCH 20/21] Adding use of TPL to PVC storageClass & ingressClass --- templates/_helpers.tpl | 2 +- templates/gitea/ingress.yaml | 2 +- templates/gitea/pvc.yaml | 2 +- .../deployment/ingress-configuration.yaml | 24 +++++++++++++++++++ unittests/pvc/pvc-configuration.yaml | 19 +++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 unittests/pvc/pvc-configuration.yaml diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 003d39f..07f886e 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -91,7 +91,7 @@ imagePullSecrets: Storage Class */}} {{- define "gitea.persistence.storageClass" -}} -{{- $storageClass := .Values.global.storageClass | default .Values.persistence.storageClass }} +{{- $storageClass := (tpl .Values.global.storageClass $ ) | default (tpl .Values.persistence.storageClass $ ) }} {{- if $storageClass }} storageClassName: {{ $storageClass | quote }} {{- end }} diff --git a/templates/gitea/ingress.yaml b/templates/gitea/ingress.yaml index 9991eec..cd743fe 100644 --- a/templates/gitea/ingress.yaml +++ b/templates/gitea/ingress.yaml @@ -21,7 +21,7 @@ metadata: {{- end }} spec: {{- if .Values.ingress.className }} - ingressClassName: {{ .Values.ingress.className }} + ingressClassName: {{ tpl .Values.ingress.className . }} {{- end }} {{- if .Values.ingress.tls }} tls: diff --git a/templates/gitea/pvc.yaml b/templates/gitea/pvc.yaml index 995bd10..d753f1a 100644 --- a/templates/gitea/pvc.yaml +++ b/templates/gitea/pvc.yaml @@ -15,7 +15,7 @@ spec: {{- end }} volumeMode: Filesystem {{- if .Values.persistence.storageClass }} - storageClassName: {{ .Values.persistence.storageClass }} + storageClassName: {{ tpl .Values.persistence.storageClass . }} {{- end }} {{- with .Values.persistence.volumeName }} volumeName: {{ . }} diff --git a/unittests/deployment/ingress-configuration.yaml b/unittests/deployment/ingress-configuration.yaml index 6a36eb0..39c631d 100644 --- a/unittests/deployment/ingress-configuration.yaml +++ b/unittests/deployment/ingress-configuration.yaml @@ -15,9 +15,33 @@ tests: hosts: - "{{ .Values.global.giteaHostName }}" asserts: + - iskind: + of: Ingress - equal: path: spec.tls[0].hosts[0] value: "gitea.example.com" - equal: path: spec.rules[0].host value: "gitea.example.com" + - it: hostname using TPL + set: + global.ingress.className: "ingress-class" + ingress.className: "{{ .Values.global.ingress.className }}" + ingress.enabled: true + ingress.hosts[0].host: "some-host" + ingress.tls: + - secretName: gitea-tls + hosts: + - "some-host" + asserts: + - iskind: + of: Ingress + - equal: + path: spec.tls[0].hosts[0] + value: "some-host" + - equal: + path: spec.rules[0].host + value: "some-host" + - equal: + path: spec.ingressClassName + value: "ingress-class" diff --git a/unittests/pvc/pvc-configuration.yaml b/unittests/pvc/pvc-configuration.yaml new file mode 100644 index 0000000..3662eb8 --- /dev/null +++ b/unittests/pvc/pvc-configuration.yaml @@ -0,0 +1,19 @@ +suite: PVC template +release: + name: gitea-unittests + namespace: testing +templates: + - templates/gitea/pvc.yaml +tests: + - it: Storage Class using TPL + set: + global.persistence.storageClass: "storage-class" + persistence.enabled: true + persistence.create: true + persistence.storageClass: "{{ .Values.global.persistence.storageClass }}" + asserts: + - iskind: + of: PersistentVolumeClaim + - equal: + path: spec.storageClassName + value: "storage-class" From 30c8feacd81e808d9d09748a9444c1511feb5699 Mon Sep 17 00:00:00 2001 From: 212597596 Date: Wed, 5 Jun 2024 18:31:51 +0300 Subject: [PATCH 21/21] Correcting unit test isKind syntax --- unittests/deployment/ingress-configuration.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittests/deployment/ingress-configuration.yaml b/unittests/deployment/ingress-configuration.yaml index 39c631d..876b84d 100644 --- a/unittests/deployment/ingress-configuration.yaml +++ b/unittests/deployment/ingress-configuration.yaml @@ -15,7 +15,7 @@ tests: hosts: - "{{ .Values.global.giteaHostName }}" asserts: - - iskind: + - isKind: of: Ingress - equal: path: spec.tls[0].hosts[0] @@ -34,7 +34,7 @@ tests: hosts: - "some-host" asserts: - - iskind: + - isKind: of: Ingress - equal: path: spec.tls[0].hosts[0]