Cannot use existing secret for DB - Crunchy Data pg operator #297

Closed
opened 2022-02-24 08:30:24 +00:00 by mmalyska · 9 comments
mmalyska commented 2022-02-24 08:30:24 +00:00 (Migrated from gitea.com)

Hi, I'm using postgres operator that creates DB connect info as a secret. To use them I have used

gitea:
  config:
    database:
      DB_TYPE: postgres
      HOST: 127.0.0.1:3306
      NAME: whatever-use-env
      USER: whatever-use-env
      PASSWD: whatever-use-env
statefulset:
    env:
      - name: GITEA_database_HOST
        valueFrom:
          secretKeyRef:
            name: giteadb-pguser-giteadb
            key: host
      - name: GITEA_database_NAME
        valueFrom:
          secretKeyRef:
            name: giteadb-pguser-giteadb
            key: dbname
      - name: GITEA_database_USER
        valueFrom:
          secretKeyRef:
            name: giteadb-pguser-giteadb
            key: user
      - name: GITEA_database_PASSWD
        valueFrom:
          secretKeyRef:
            name: giteadb-pguser-giteadb
            key: password

But still everything is in crashloop because scipts and other things don't get this envs into consideration. Do you have workaround or anything that would help?

Hi, I'm using postgres operator that creates DB connect info as a secret. To use them I have used ``` gitea: config: database: DB_TYPE: postgres HOST: 127.0.0.1:3306 NAME: whatever-use-env USER: whatever-use-env PASSWD: whatever-use-env statefulset: env: - name: GITEA_database_HOST valueFrom: secretKeyRef: name: giteadb-pguser-giteadb key: host - name: GITEA_database_NAME valueFrom: secretKeyRef: name: giteadb-pguser-giteadb key: dbname - name: GITEA_database_USER valueFrom: secretKeyRef: name: giteadb-pguser-giteadb key: user - name: GITEA_database_PASSWD valueFrom: secretKeyRef: name: giteadb-pguser-giteadb key: password ``` But still everything is in crashloop because scipts and other things don't get this envs into consideration. Do you have workaround or anything that would help?
luhahn commented 2022-02-24 09:59:07 +00:00 (Migrated from gitea.com)

I think you misunderstood the use of environment variables for gitea.
You can configure gitea using env variables but they need to be in a specific format.
You also need to run env-to-ini script to write those environment variables into the app.ini. Otherwise those env variables will simply be ignored.

You've got two options to configure gitea via existing secrets:

  1. Use the functionality provided and described here: https://gitea.com/gitea/helm-chart#additional-app-ini-settings
  2. I'm not sure, if this approach will work, but it could be worth a try. Bring your env variables into a format recognized by env-to-ini such as:
    ENV_TO_INI__DATABASE__HOST
    
    Make sure, that you have disabled the database dependencies.
    Delete NAME, USER, PASSWD from gitea.database.config otherwise these settings will override your env variables.
I think you misunderstood the use of environment variables for gitea. You can configure gitea using env variables but they need to be in a specific format. You also need to run env-to-ini script to write those environment variables into the app.ini. Otherwise those env variables will simply be ignored. You've got two options to configure gitea via existing secrets: 1. Use the functionality provided and described here: https://gitea.com/gitea/helm-chart#additional-_app-ini_-settings 2. I'm not sure, if this approach will work, but it could be worth a try. Bring your env variables into a format recognized by env-to-ini such as: ```yaml ENV_TO_INI__DATABASE__HOST ``` Make sure, that you have disabled the database dependencies. Delete NAME, USER, PASSWD from gitea.database.config otherwise these settings will override your env variables.
mmalyska commented 2022-02-24 10:15:10 +00:00 (Migrated from gitea.com)

The problem is that chart is built by gitops and DB secret does not exist and is auto created by postgres operator in the same chart as dependency. I cannot change how it is generated or its structure. So I don't know what secret values it will be after chart creation.
And the main cultprit is configure_gitea.sh because it is generated from

gitea:
  config:
    database:

and not from env variables so it contains wrong db string.

The problem is that chart is built by gitops and DB secret does not exist and is auto created by postgres operator in the same chart as dependency. I cannot change how it is generated or its structure. So I don't know what secret values it will be after chart creation. And the main cultprit is `configure_gitea.sh` because it is generated from ``` gitea: config: database: ``` and not from env variables so it contains wrong db string.
luhahn commented 2022-02-24 10:44:48 +00:00 (Migrated from gitea.com)

That's why i proposed the second option

That's why i proposed the second option
luhahn commented 2022-02-24 11:59:03 +00:00 (Migrated from gitea.com)

Anyways, we will try to make this easier in the next days :)

Anyways, we will try to make this easier in the next days :)
mmalyska commented 2022-02-24 12:34:35 +00:00 (Migrated from gitea.com)

I have tried second option but script configure_gitea.sh is generated from database values and does not use env variables.

I have tried second option but script `configure_gitea.sh` is generated from database values and does not use env variables.
luhahn commented 2022-02-24 12:41:54 +00:00 (Migrated from gitea.com)

have you removed the gitea.config.database settings? If they dont exist, they shouldn't be used

have you removed the gitea.config.database settings? If they dont exist, they shouldn't be used
mmalyska commented 2022-02-24 12:54:29 +00:00 (Migrated from gitea.com)

I have removed NAME, USER, PASSWD because if I remove whole gitea.config.database I got error

 error calling include: template: gitea-subchart/charts/gitea/templates/_helpers.tpl:73:12: executing "db.servicename" at <ne .Values.gitea.config.database.DB_TYPE "sqlite3">
I have removed `NAME, USER, PASSWD` because if I remove whole `gitea.config.database` I got error ``` error calling include: template: gitea-subchart/charts/gitea/templates/_helpers.tpl:73:12: executing "db.servicename" at <ne .Values.gitea.config.database.DB_TYPE "sqlite3"> ```
luhahn commented 2022-02-24 14:05:56 +00:00 (Migrated from gitea.com)

Ich will try to prepare a patch for that issue tomorrow

Ich will try to prepare a patch for that issue tomorrow
erhan commented 2022-02-28 20:16:45 +00:00 (Migrated from gitea.com)

Danke very much for working on this. This is also relevant for my setup with ArgoCD and other applications.

Danke very much for working on this. This is also relevant for my setup with ArgoCD and other applications.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: lunny/helm-chart#297
No description provided.