feat: adding dry support to gitea additional config from envs parameter #840

Merged
justusbunsi merged 4 commits from Ceddaerrix/gitea-helm-chart:additionalConfigFromEnvs-DRY into main 2025-03-30 14:30:36 +00:00

View File

@@ -256,7 +256,7 @@ https
{{- end }}
{{- $_ := set $inlines "_generals_" (join "\n" $generals) -}}
{{- toYaml $inlines -}}
{{- tpl (toYaml $inlines) $ -}}
Review

‼️ Oh dear, I completely missed this change. It breaks configuring log.ACCESS_LOG_TEMPLATE as mentioned here: #747 (comment).

Before this PR was merged a few minutes ago, I was able to configure following values so that helm template gitea . succeeds:

gitea:  config:  log:  ACCESS_LOG_TEMPLATE: |  {{.Ctx.RemoteHost}} - {{.Identity}} {{.Start.Format "[02/Jan/2006:15:04:05 -0700]" }} "{{.Ctx.Req.Method}} {{.Ctx.Req.URL.RequestURI}} {{.Ctx.Req.Proto}}" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} "{{.Ctx.Req.Referer}}" "{{.Ctx.Req.UserAgent}}" 

With these changes, the same values result in following error:

Error: template: gitea/templates/gitea/deployment.yaml:33:28: executing "gitea/templates/gitea/deployment.yaml" at <include (print $.Template.BasePath "/gitea/config.yaml") .>: error calling include: template: gitea/templates/gitea/config.yaml:10:6: executing "gitea/templates/gitea/config.yaml" at <include "gitea.inline_configuration" .>: error calling include: template: gitea/templates/_helpers.tpl:259:6: executing "gitea.inline_configuration" at <tpl (toYaml $inlines) $>: error calling tpl: error during tpl function execution for "_generals_: \"\"\nactions: ENABLED=false\ncache: |-\n ADAPTER=redis\n HOST=redis+cluster://:@gitea-redis-cluster-headless.default.svc.cluster.local:6379/0?pool_size=100&idle_timeout=180s&\ndatabase: |-\n DB_TYPE=postgres\n HOST=gitea-postgresql-ha-pgpool.default.svc.cluster.local:5432\n NAME={{ .Values.global.databasename }}\n PASSWD={{ .Values.global.password }}\n USER={{ .Values.global.username }}\nindexer: ISSUE_INDEXER_TYPE=db\nlog: |\n ACCESS_LOG_TEMPLATE={{.Ctx.RemoteHost}} - {{.Identity}} {{.Start.Format \"[02/Jan/2006:15:04:05 -0700]\" }} \"{{.Ctx.Req.Method}} {{.Ctx.Req.URL.RequestURI}} {{.Ctx.Req.Proto}}\" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} \"{{.Ctx.Req.Referer}}\" \"{{.Ctx.Req.UserAgent}}\"\nmetrics: ENABLED=false\nqueue: |-\n CONN_STR=redis+cluster://:@gitea-redis-cluster-headless.default.svc.cluster.local:6379/0?pool_size=100&idle_timeout=180s&\n TYPE=redis\nrepository: ROOT=/data/git/gitea-repositories\nsecurity: INSTALL_LOCK=true\nserver: |-\n APP_DATA_PATH=/data\n DOMAIN=git.example.com\n ENABLE_PPROF=false\n HTTP_PORT=3000\n PROTOCOL=http\n ROOT_URL=http://git.example.com\n SSH_DOMAIN=git.example.com\n SSH_LISTEN_PORT=2222\n SSH_PORT=22\n START_SSH_SERVER=true\nsession: |-\n PROVIDER=redis\n PROVIDER_CONFIG=redis+cluster://:@gitea-redis-cluster-headless.default.svc.cluster.local:6379/0?pool_size=100&idle_timeout=180s&": template: gotpl:14:28: executing "gotpl" at <.Ctx.RemoteHost>: nil pointer evaluating interface {}.RemoteHost 

This is the kind of breaking change I wanted to prevent when posting #759 (comment). I think we should make the inline value templating "opt-in".

‼️ Oh dear, I completely missed this change. It breaks configuring `log.ACCESS_LOG_TEMPLATE` as mentioned here: https://gitea.com/gitea/helm-gitea/pulls/747#issuecomment-944341. Before this PR was merged a few minutes ago, I was able to configure following values so that `helm template gitea .` succeeds: ```yaml gitea: config: log: ACCESS_LOG_TEMPLATE: | {{.Ctx.RemoteHost}} - {{.Identity}} {{.Start.Format "[02/Jan/2006:15:04:05 -0700]" }} "{{.Ctx.Req.Method}} {{.Ctx.Req.URL.RequestURI}} {{.Ctx.Req.Proto}}" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} "{{.Ctx.Req.Referer}}" "{{.Ctx.Req.UserAgent}}" ``` With these changes, the same values result in following error: ```text Error: template: gitea/templates/gitea/deployment.yaml:33:28: executing "gitea/templates/gitea/deployment.yaml" at <include (print $.Template.BasePath "/gitea/config.yaml") .>: error calling include: template: gitea/templates/gitea/config.yaml:10:6: executing "gitea/templates/gitea/config.yaml" at <include "gitea.inline_configuration" .>: error calling include: template: gitea/templates/_helpers.tpl:259:6: executing "gitea.inline_configuration" at <tpl (toYaml $inlines) $>: error calling tpl: error during tpl function execution for "_generals_: \"\"\nactions: ENABLED=false\ncache: |-\n ADAPTER=redis\n HOST=redis+cluster://:@gitea-redis-cluster-headless.default.svc.cluster.local:6379/0?pool_size=100&idle_timeout=180s&\ndatabase: |-\n DB_TYPE=postgres\n HOST=gitea-postgresql-ha-pgpool.default.svc.cluster.local:5432\n NAME={{ .Values.global.databasename }}\n PASSWD={{ .Values.global.password }}\n USER={{ .Values.global.username }}\nindexer: ISSUE_INDEXER_TYPE=db\nlog: |\n ACCESS_LOG_TEMPLATE={{.Ctx.RemoteHost}} - {{.Identity}} {{.Start.Format \"[02/Jan/2006:15:04:05 -0700]\" }} \"{{.Ctx.Req.Method}} {{.Ctx.Req.URL.RequestURI}} {{.Ctx.Req.Proto}}\" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} \"{{.Ctx.Req.Referer}}\" \"{{.Ctx.Req.UserAgent}}\"\nmetrics: ENABLED=false\nqueue: |-\n CONN_STR=redis+cluster://:@gitea-redis-cluster-headless.default.svc.cluster.local:6379/0?pool_size=100&idle_timeout=180s&\n TYPE=redis\nrepository: ROOT=/data/git/gitea-repositories\nsecurity: INSTALL_LOCK=true\nserver: |-\n APP_DATA_PATH=/data\n DOMAIN=git.example.com\n ENABLE_PPROF=false\n HTTP_PORT=3000\n PROTOCOL=http\n ROOT_URL=http://git.example.com\n SSH_DOMAIN=git.example.com\n SSH_LISTEN_PORT=2222\n SSH_PORT=22\n START_SSH_SERVER=true\nsession: |-\n PROVIDER=redis\n PROVIDER_CONFIG=redis+cluster://:@gitea-redis-cluster-headless.default.svc.cluster.local:6379/0?pool_size=100&idle_timeout=180s&": template: gotpl:14:28: executing "gotpl" at <.Ctx.RemoteHost>: nil pointer evaluating interface {}.RemoteHost ``` This is the kind of breaking change I wanted to prevent when posting https://gitea.com/gitea/helm-gitea/pulls/759#issuecomment-962987. I think we should make the inline value templating "opt-in".
Review

‼️ Oh dear, I completely missed this change. It breaks configuring log.ACCESS_LOG_TEMPLATE as mentioned here: #747 (comment).

Before this PR was merged a few minutes ago, I was able to configure following values so that helm template gitea . succeeds:

gitea:  config:  log:  ACCESS_LOG_TEMPLATE: |  {{.Ctx.RemoteHost}} - {{.Identity}} {{.Start.Format "[02/Jan/2006:15:04:05 -0700]" }} "{{.Ctx.Req.Method}} {{.Ctx.Req.URL.RequestURI}} {{.Ctx.Req.Proto}}" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} "{{.Ctx.Req.Referer}}" "{{.Ctx.Req.UserAgent}}" 

With these changes, the same values result in following error:

Error: template: gitea/templates/gitea/deployment.yaml:33:28: executing "gitea/templates/gitea/deployment.yaml" at <include (print $.Template.BasePath "/gitea/config.yaml") .>: error calling include: template: gitea/templates/gitea/config.yaml:10:6: executing "gitea/templates/gitea/config.yaml" at <include "gitea.inline_configuration" .>: error calling include: template: gitea/templates/_helpers.tpl:259:6: executing "gitea.inline_configuration" at <tpl (toYaml $inlines) $>: error calling tpl: error during tpl function execution for "_generals_: \"\"\nactions: ENABLED=false\ncache: |-\n ADAPTER=redis\n HOST=redis+cluster://:@gitea-redis-cluster-headless.default.svc.cluster.local:6379/0?pool_size=100&idle_timeout=180s&\ndatabase: |-\n DB_TYPE=postgres\n HOST=gitea-postgresql-ha-pgpool.default.svc.cluster.local:5432\n NAME={{ .Values.global.databasename }}\n PASSWD={{ .Values.global.password }}\n USER={{ .Values.global.username }}\nindexer: ISSUE_INDEXER_TYPE=db\nlog: |\n ACCESS_LOG_TEMPLATE={{.Ctx.RemoteHost}} - {{.Identity}} {{.Start.Format \"[02/Jan/2006:15:04:05 -0700]\" }} \"{{.Ctx.Req.Method}} {{.Ctx.Req.URL.RequestURI}} {{.Ctx.Req.Proto}}\" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} \"{{.Ctx.Req.Referer}}\" \"{{.Ctx.Req.UserAgent}}\"\nmetrics: ENABLED=false\nqueue: |-\n CONN_STR=redis+cluster://:@gitea-redis-cluster-headless.default.svc.cluster.local:6379/0?pool_size=100&idle_timeout=180s&\n TYPE=redis\nrepository: ROOT=/data/git/gitea-repositories\nsecurity: INSTALL_LOCK=true\nserver: |-\n APP_DATA_PATH=/data\n DOMAIN=git.example.com\n ENABLE_PPROF=false\n HTTP_PORT=3000\n PROTOCOL=http\n ROOT_URL=http://git.example.com\n SSH_DOMAIN=git.example.com\n SSH_LISTEN_PORT=2222\n SSH_PORT=22\n START_SSH_SERVER=true\nsession: |-\n PROVIDER=redis\n PROVIDER_CONFIG=redis+cluster://:@gitea-redis-cluster-headless.default.svc.cluster.local:6379/0?pool_size=100&idle_timeout=180s&": template: gotpl:14:28: executing "gotpl" at <.Ctx.RemoteHost>: nil pointer evaluating interface {}.RemoteHost 

This is the kind of breaking change I wanted to prevent when posting #759 (comment). I think we should make the inline value templating "opt-in".

My bad! This one is on me; having providing some input on #759, I missed resetting my local clone on the matter

> ‼️ Oh dear, I completely missed this change. It breaks configuring `log.ACCESS_LOG_TEMPLATE` as mentioned here: https://gitea.com/gitea/helm-gitea/pulls/747#issuecomment-944341. > > Before this PR was merged a few minutes ago, I was able to configure following values so that `helm template gitea .` succeeds: > > ```yaml > gitea: > config: > log: > ACCESS_LOG_TEMPLATE: | > {{.Ctx.RemoteHost}} - {{.Identity}} {{.Start.Format "[02/Jan/2006:15:04:05 -0700]" }} "{{.Ctx.Req.Method}} {{.Ctx.Req.URL.RequestURI}} {{.Ctx.Req.Proto}}" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} "{{.Ctx.Req.Referer}}" "{{.Ctx.Req.UserAgent}}" > ``` > > With these changes, the same values result in following error: > > ```text > Error: template: gitea/templates/gitea/deployment.yaml:33:28: executing "gitea/templates/gitea/deployment.yaml" at <include (print $.Template.BasePath "/gitea/config.yaml") .>: error calling include: template: gitea/templates/gitea/config.yaml:10:6: executing "gitea/templates/gitea/config.yaml" at <include "gitea.inline_configuration" .>: error calling include: template: gitea/templates/_helpers.tpl:259:6: executing "gitea.inline_configuration" at <tpl (toYaml $inlines) $>: error calling tpl: error during tpl function execution for "_generals_: \"\"\nactions: ENABLED=false\ncache: |-\n ADAPTER=redis\n HOST=redis+cluster://:@gitea-redis-cluster-headless.default.svc.cluster.local:6379/0?pool_size=100&idle_timeout=180s&\ndatabase: |-\n DB_TYPE=postgres\n HOST=gitea-postgresql-ha-pgpool.default.svc.cluster.local:5432\n NAME={{ .Values.global.databasename }}\n PASSWD={{ .Values.global.password }}\n USER={{ .Values.global.username }}\nindexer: ISSUE_INDEXER_TYPE=db\nlog: |\n ACCESS_LOG_TEMPLATE={{.Ctx.RemoteHost}} - {{.Identity}} {{.Start.Format \"[02/Jan/2006:15:04:05 -0700]\" }} \"{{.Ctx.Req.Method}} {{.Ctx.Req.URL.RequestURI}} {{.Ctx.Req.Proto}}\" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} \"{{.Ctx.Req.Referer}}\" \"{{.Ctx.Req.UserAgent}}\"\nmetrics: ENABLED=false\nqueue: |-\n CONN_STR=redis+cluster://:@gitea-redis-cluster-headless.default.svc.cluster.local:6379/0?pool_size=100&idle_timeout=180s&\n TYPE=redis\nrepository: ROOT=/data/git/gitea-repositories\nsecurity: INSTALL_LOCK=true\nserver: |-\n APP_DATA_PATH=/data\n DOMAIN=git.example.com\n ENABLE_PPROF=false\n HTTP_PORT=3000\n PROTOCOL=http\n ROOT_URL=http://git.example.com\n SSH_DOMAIN=git.example.com\n SSH_LISTEN_PORT=2222\n SSH_PORT=22\n START_SSH_SERVER=true\nsession: |-\n PROVIDER=redis\n PROVIDER_CONFIG=redis+cluster://:@gitea-redis-cluster-headless.default.svc.cluster.local:6379/0?pool_size=100&idle_timeout=180s&": template: gotpl:14:28: executing "gotpl" at <.Ctx.RemoteHost>: nil pointer evaluating interface {}.RemoteHost > ``` > > This is the kind of breaking change I wanted to prevent when posting https://gitea.com/gitea/helm-gitea/pulls/759#issuecomment-962987. I think we should make the inline value templating "opt-in". My bad! This one is on me; having providing some input on https://gitea.com/gitea/helm-gitea/pulls/759, I missed resetting my local clone on the matter
Review

Reverting the use if {{- tpl (toYaml $inlines) $ -}} under #846

Reverting the use if `{{- tpl (toYaml $inlines) $ -}}` under https://gitea.com/gitea/helm-gitea/pulls/846
{{- end -}}
{{- define "gitea.inline_configuration.init" -}}

View File

@@ -115,7 +115,7 @@ spec:
{{- toYaml .Values.deployment.env | nindent 12 }}
{{- end }}
{{- if .Values.gitea.additionalConfigFromEnvs }}
{{- toYaml .Values.gitea.additionalConfigFromEnvs | nindent 12 }}
{{- tpl (toYaml .Values.gitea.additionalConfigFromEnvs) $ | nindent 12 }}
{{- end }}
volumeMounts:
- name: config

View File

@@ -0,0 +1,150 @@
suite: deployment template
release:
name: gitea-unittests
namespace: testing
templates:
- templates/gitea/deployment.yaml
- templates/gitea/config.yaml
tests:
- it: Renders a deployment
template: templates/gitea/deployment.yaml
asserts:
- hasDocuments:
count: 1
- containsDocument:
kind: Deployment
apiVersion: apps/v1
name: gitea-unittests
- it: Deployment with empty additionalConfigFromEnvs
template: templates/gitea/deployment.yaml
set:
gitea.additionalConfigFromEnvs: []
asserts:
- hasDocuments:
count: 1
- exists:
path: spec.template.spec.initContainers[1].env
- lengthEqual:
path: spec.template.spec.initContainers[1].env
count: 6
- isSubset:
path: spec.template.spec.initContainers[1]
content:
env:
- name: GITEA_APP_INI
value: /data/gitea/conf/app.ini
- name: GITEA_CUSTOM
value: /data/gitea
- name: GITEA_WORK_DIR
value: /data
- name: GITEA_TEMP
value: /tmp/gitea
- name: TMP_EXISTING_ENVS_FILE
value: /tmp/existing-envs
- name: ENV_TO_INI_MOUNT_POINT
value: /env-to-ini-mounts
- it: Deployment with standard additionalConfigFromEnvs
template: templates/gitea/deployment.yaml
set:
gitea.additionalConfigFromEnvs: [{name: GITEA_database_HOST, value: my-db:123}, {name: GITEA_database_USER, value: my-user}]
asserts:
- hasDocuments:
count: 1
- exists:
path: spec.template.spec.initContainers[1].env
- lengthEqual:
path: spec.template.spec.initContainers[1].env
count: 8
- isSubset:
path: spec.template.spec.initContainers[1]
content:
env:
- name: GITEA_APP_INI
value: /data/gitea/conf/app.ini
- name: GITEA_CUSTOM
value: /data/gitea
- name: GITEA_WORK_DIR
value: /data
- name: GITEA_TEMP
value: /tmp/gitea
- name: TMP_EXISTING_ENVS_FILE
value: /tmp/existing-envs
- name: ENV_TO_INI_MOUNT_POINT
value: /env-to-ini-mounts
- name: GITEA_database_HOST
value: my-db:123
- name: GITEA_database_USER
value: my-user
- it: Deployment with templated additionalConfigFromEnvs
template: templates/gitea/deployment.yaml
set:
gitea.misc.host: my-db-host:321
gitea.misc.user: my-db-user
gitea.additionalConfigFromEnvs: [{name: GITEA_database_HOST, value: "{{ .Values.gitea.misc.host }}"}, {name: GITEA_database_USER, value: "{{ .Values.gitea.misc.user }}"}]
asserts:
- hasDocuments:
count: 1
- exists:
path: spec.template.spec.initContainers[1].env
- lengthEqual:
path: spec.template.spec.initContainers[1].env
count: 8
- isSubset:
path: spec.template.spec.initContainers[1]
content:
env:
- name: GITEA_APP_INI
value: /data/gitea/conf/app.ini
- name: GITEA_CUSTOM
value: /data/gitea
- name: GITEA_WORK_DIR
value: /data
- name: GITEA_TEMP
value: /tmp/gitea
- name: TMP_EXISTING_ENVS_FILE
value: /tmp/existing-envs
- name: ENV_TO_INI_MOUNT_POINT
value: /env-to-ini-mounts
- name: GITEA_database_HOST
value: my-db-host:321
- name: GITEA_database_USER
value: my-db-user
- it: Deployment with additionalConfigFromEnvs templated secret name
template: templates/gitea/deployment.yaml
set:
gitea.misc.existingSecret: my-db-secret
gitea.additionalConfigFromEnvs[0]:
name: GITEA_database_HOST
valueFrom:
secretKeyRef:
name: "{{ .Values.gitea.misc.existingSecret }}"
key: password
asserts:
- hasDocuments:
count: 1
- exists:
path: spec.template.spec.initContainers[1].env
- lengthEqual:
path: spec.template.spec.initContainers[1].env
count: 7
- isSubset:
path: spec.template.spec.initContainers[1]
content:
env:
- name: GITEA_APP_INI
value: /data/gitea/conf/app.ini
- name: GITEA_CUSTOM
value: /data/gitea
- name: GITEA_WORK_DIR
value: /data
- name: GITEA_TEMP
value: /tmp/gitea
- name: TMP_EXISTING_ENVS_FILE
value: /tmp/existing-envs
- name: ENV_TO_INI_MOUNT_POINT
value: /env-to-ini-mounts
- name: GITEA_database_HOST
valueFrom:
secretKeyRef:
name: "my-db-secret"
key: password