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
Contributor

Description of the change

Based on the discussion under #60, it is possible to use gitea.additionalConfigFromEnvs to provide variables in order to override configurations from app.ini.
Especially when using gitea as a dependency of an umbrella, some values may need to be repeated in multiple places (such has database configuration). Hence, introducing the tpl function on gitea.additionalConfigFromEnvs will simplify such repetition by having the value only set in one place...

Benefits

With the same intentions as #759, #664, #529 or #498, this change will allow reusing the value from other value parameters to avoid duplicating the same value in multiple places.

Possible drawbacks

N/A

Applicable issues

N/A

Additional information

N/A

⚠ BREAKING

N/A

Checklist

  • Helm templating unittests are added (required when changing anything in templates folder)
<!-- Before you open the request please review the following guidelines and tips to help it be more easily integrated: - Describe the scope of your change - i.e. what the change does. - Describe any known limitations with your change. - Please run any tests or examples that can exercise your modified code. Thank you for contributing! We will try to review, test and integrate the change as soon as we can. --> ### Description of the change <!-- Describe the scope of your change - i.e. what the change does. --> Based on the discussion under https://gitea.com/gitea/helm-gitea/issues/60, it is possible to use `gitea.additionalConfigFromEnvs` to provide variables in order to override configurations from `app.ini`. Especially when using gitea as a dependency of an umbrella, some values may need to be repeated in multiple places (such has database configuration). Hence, introducing the `tpl` function on `gitea.additionalConfigFromEnvs` will simplify such repetition by having the value only set in one place... ### Benefits <!-- What benefits will be realized by the code change? --> With the same intentions as https://gitea.com/gitea/helm-gitea/pulls/759, https://gitea.com/gitea/helm-gitea/pulls/664, https://gitea.com/gitea/helm-gitea/pulls/529 or https://gitea.com/gitea/helm-gitea/pulls/498, this change will allow reusing the value from other value parameters to avoid duplicating the same value in multiple places. ### Possible drawbacks N/A ### Applicable issues N/A ### Additional information N/A ### ⚠ BREAKING N/A ### Checklist <!-- [Place an '[X]' (no spaces) in all applicable fields. Please remove unrelated fields.] --> - [X] Helm templating unittests are added (required when changing anything in `templates` folder)
Ceddaerrix added 2 commits 2025-03-25 16:40:10 +00:00
Adding unit test: unittests/helm/deployment/deployment-additional-config.yaml
Some checks failed
commitlint / check-and-test (pull_request) Failing after 7s
check-and-test / check-and-test (pull_request) Failing after 51s
3d35c40119
Ceddaerrix requested review from justusbunsi 2025-03-25 16:40:10 +00:00
Ceddaerrix requested review from pat-s 2025-03-25 16:40:10 +00:00
Ceddaerrix added 1 commit 2025-03-25 16:45:38 +00:00
deployment-additional-config.yaml: correcting YAML lint errors
Some checks failed
check-and-test / check-and-test (pull_request) Successful in 45s
commitlint / check-and-test (pull_request) Failing after 14m23s
66581f48c9
Ceddaerrix changed title from additionalConfigFromEnvs-DRY to feat{\(): Adding DRY support to 'gitea.additionalConfigFromEnvs' 2025-03-25 16:48:28 +00:00
Ceddaerrix changed title from feat{\(): Adding DRY support to 'gitea.additionalConfigFromEnvs' to feat(): Adding DRY support to 'gitea.additionalConfigFromEnvs' 2025-03-25 16:48:49 +00:00
Ceddaerrix changed title from feat(): Adding DRY support to 'gitea.additionalConfigFromEnvs' to feat: Adding DRY support to 'gitea.additionalConfigFromEnvs' 2025-03-25 16:54:23 +00:00
Ceddaerrix changed title from feat: Adding DRY support to 'gitea.additionalConfigFromEnvs' to feat: adding dry support to gitea additional config from envs parameter 2025-03-25 16:57:59 +00:00
Ceddaerrix requested review from Maintainers 2025-03-25 17:06:16 +00:00
Member

As I mentioned in #60, instead of the environment variable approach, I would rather use the approach of storing the credentials in the container file system to enable a reconnect in case of changed database credentials and to avoid missuse before accessing the environment variables.

Let's wait and see if gitea has such a hotreload or not. I think we will get an answer from the devs soon.

As I mentioned in #60, instead of the environment variable approach, I would rather use the approach of storing the credentials in the container file system to enable a reconnect in case of changed database credentials and to avoid missuse before accessing the environment variables. Let's wait and see if gitea has such a hotreload or not. I think we will get an answer from the devs soon.
Collaborator

@volker.raschek Gitea doesn't have a hot-reloading unfortunately. This has been discussed in multiple issues in the upstream repo.

@volker.raschek Gitea doesn't have a hot-reloading unfortunately. This has been discussed in multiple issues in the upstream repo.
pat-s added 1 commit 2025-03-27 17:40:25 +00:00
Merge branch 'main' into additionalConfigFromEnvs-DRY
All checks were successful
check-and-test / check-and-test (pull_request) Successful in 50s
c059df672b
pat-s removed review request for Maintainers 2025-03-27 17:40:30 +00:00
pat-s approved these changes 2025-03-27 17:42:44 +00:00
pat-s left a comment
Collaborator

LGTM overall, thanks also for adding tests directly.

LGTM overall, thanks also for adding tests directly.
justusbunsi approved these changes 2025-03-30 14:28:30 +00:00
justusbunsi left a comment
Contributor

LGTM as well. By the way, you can also use yaml anchors to not repeat yourself:

diff --git a/values.yaml b/values.yaml index 2a5c4d2..29205c8 100644 --- a/values.yaml +++ b/values.yaml @@ -1,3 +1,6 @@ +misc: + existingSecret: &miscExistingSecret "hello-existing-secret" +  # Default values for gitea. # This is a YAML-formatted file. # Declare variables to be passed into your templates. @@ -438,7 +441,12 @@ gitea:  # name: gitea-app-ini-plaintext ## @param gitea.additionalConfigFromEnvs Additional configuration sources from environment variables - additionalConfigFromEnvs: [] + additionalConfigFromEnvs: + - name: GITEA_database_HOST + valueFrom: + secretKeyRef: + name: *miscExistingSecret + key: password  ## @param gitea.podAnnotations Annotations for the Gitea pod podAnnotations: {} 
LGTM as well. By the way, you can also use yaml anchors to not repeat yourself: ```diff diff --git a/values.yaml b/values.yaml index 2a5c4d2..29205c8 100644 --- a/values.yaml +++ b/values.yaml @@ -1,3 +1,6 @@ +misc: + existingSecret: &miscExistingSecret "hello-existing-secret" + # Default values for gitea. # This is a YAML-formatted file. # Declare variables to be passed into your templates. @@ -438,7 +441,12 @@ gitea: # name: gitea-app-ini-plaintext ## @param gitea.additionalConfigFromEnvs Additional configuration sources from environment variables - additionalConfigFromEnvs: [] + additionalConfigFromEnvs: + - name: GITEA_database_HOST + valueFrom: + secretKeyRef: + name: *miscExistingSecret + key: password ## @param gitea.podAnnotations Annotations for the Gitea pod podAnnotations: {} ```
justusbunsi merged commit 1f313ac70e into main 2025-03-30 14:30:36 +00:00
justusbunsi reviewed 2025-03-30 14:58:28 +00:00
@@ -257,3 +257,3 @@
{{- $_ := set $inlines "_generals_" (join "\n" $generals) -}}
{{- toYaml $inlines -}}
{{- tpl (toYaml $inlines) $ -}}
Contributor

‼️ 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".
Author
Contributor

‼️ 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
Author
Contributor

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
Collaborator

@Ceddaerrix Can you take a look at the most recent comment and maybe come up with a workaround for helm template?

@Ceddaerrix Can you take a look at the most recent comment and maybe come up with a workaround for `helm template`?
Sign in to join this conversation.
No description provided.