Skip to content

feat: add PostgreSQL support for manager database - #492

Open
bumarcell wants to merge 7 commits into
dragonflyoss:mainfrom
bumarcell:feat/postgres-support
Open

feat: add PostgreSQL support for manager database#492
bumarcell wants to merge 7 commits into
dragonflyoss:mainfrom
bumarcell:feat/postgres-support

Conversation

@bumarcell

@bumarcell bumarcell commented Apr 10, 2026

Copy link
Copy Markdown

Summary

The Dragonfly manager application has supported PostgreSQL since dragonflyoss/dragonfly#1459, but the Helm chart only renders MySQL configuration. This adds PostgreSQL support to the chart.

Changes

values.yaml

  • New externalPostgres section: enable, host, port, database, username, password, sslMode, timezone, migrate
  • New manager.extraInitContainers: [] — generic escape hatch for additional init containers
  • New manager.renderConfig: false — opt-in flag that swaps the /etc/dragonfly mount from the raw ConfigMap to an emptyDir, so a user-supplied init container can render the final manager.yaml (e.g. by substituting credentials pulled from a Kubernetes Secret)
  • Commented-out example in the externalPostgres section showing how to combine renderConfig: true + an init container to inject credentials from a Secret

manager-configmap.yaml

  • Adds database.type field (postgres when enabled, mysql otherwise)
  • Renders database.postgres block when externalPostgres.enable is true
  • mysql block only rendered when postgres is disabled

manager-deployment.yaml

  • Adds manager.extraInitContainers support via common.tplvalues.render
  • When manager.renderConfig is true, mounts a config-rendered emptyDir at /etc/dragonfly instead of the raw ConfigMap, and declares that emptyDir volume. The user's extraInitContainers entry is expected to read the raw ConfigMap (from an extraVolumeMounts path) and write the rendered manager.yaml to /etc/dragonfly/manager.yaml.
  • Default (renderConfig: false): manager mounts the ConfigMap directly, extraInitContainers stays a pure escape hatch with no volume side effects — static credentials in values.yaml work out of the box for both externalPostgres and externalMysql.

Usage

Direct credentials

mysql:
  enable: false
externalPostgres:
  enable: true
  host: my-postgres-host
  username: dragonfly
  password: mypassword
  database: manager

Credentials from Kubernetes Secret

mysql:
  enable: false
externalPostgres:
  enable: true
  host: my-postgres-host
  database: manager
  username: __PG_USER__
  password: __PG_PASSWORD__
manager:
  renderConfig: true
  extraInitContainers:
    - name: inject-pg-credentials
      image: busybox:latest
      command: ["sh", "-c", "sed 's/__PG_USER__/$PG_USER/g; s/__PG_PASSWORD__/$PG_PASSWORD/g' /etc/dragonfly-template/manager.yaml > /etc/dragonfly/manager.yaml"]
      env:
        - name: PG_USER
          valueFrom:
            secretKeyRef:
              name: my-postgres-secret
              key: username
        - name: PG_PASSWORD
          valueFrom:
            secretKeyRef:
              name: my-postgres-secret
              key: password
      volumeMounts:
        - name: config
          mountPath: /etc/dragonfly-template
        - name: config-rendered
          mountPath: /etc/dragonfly

Follow-up

A more ergonomic externalPostgres.existingSecret pattern (chart-shipped init container that does the substitution automatically) is a natural follow-up and will land in a separate PR once this one merges. That avoids bloating this PR further and keeps the review focused on the core externalPostgres + renderConfig plumbing.

@github-actions
github-actions Bot requested review from BraveY, imeoer and yxxhero April 10, 2026 13:56
@bumarcell
bumarcell force-pushed the feat/postgres-support branch 2 times, most recently from 2724a79 to 2b295ff Compare April 13, 2026 09:57
@bumarcell bumarcell changed the title feat: add PostgreSQL support for manager database enhancement: add PostgreSQL support for manager database Apr 13, 2026
@bumarcell
bumarcell force-pushed the feat/postgres-support branch from 2b295ff to 3f749b2 Compare April 13, 2026 11:36
@bumarcell

Copy link
Copy Markdown
Author

Could a maintainer please add the enhancement label? The Classify PR check requires it and I don't have permission to add labels from my fork.

@bumarcell bumarcell changed the title enhancement: add PostgreSQL support for manager database feat: add PostgreSQL support for manager database Apr 13, 2026
@bumarcell
bumarcell force-pushed the feat/postgres-support branch 3 times, most recently from de58eab to e48a722 Compare April 13, 2026 12:38
@yxxhero yxxhero added the enhancement New feature or request label Apr 13, 2026
@yxxhero
yxxhero requested a review from Copilot April 13, 2026 12:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Dragonfly Helm chart to support configuring the manager database as external PostgreSQL (in addition to the existing MySQL configuration), and adds a chart value to allow injecting extra init containers into the manager Deployment.

Changes:

  • Add externalPostgres configuration to values.yaml and document it in README.md.
  • Update manager-configmap.yaml to render database.type and a PostgreSQL config block when enabled.
  • Update manager-deployment.yaml to support manager.extraInitContainers and to introduce a config-rendered volume path for PostgreSQL mode.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
charts/dragonfly/values.yaml Adds manager.extraInitContainers and new externalPostgres values.
charts/dragonfly/templates/manager/manager-deployment.yaml Allows extra init containers; switches manager config mount to config-rendered and adds an emptyDir volume in PostgreSQL mode.
charts/dragonfly/templates/manager/manager-configmap.yaml Adds PostgreSQL database configuration rendering and database.type.
charts/dragonfly/README.md Documents externalPostgres values and manager.extraInitContainers.
charts/dragonfly/Chart.yaml Bumps chart version and updates Artifact Hub changelog annotations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread charts/dragonfly/templates/manager/manager-deployment.yaml Outdated
Comment thread charts/dragonfly/templates/manager/manager-deployment.yaml Outdated
Comment thread charts/dragonfly/values.yaml
Comment thread charts/dragonfly/README.md Outdated
@bumarcell bumarcell changed the title feat: add PostgreSQL support for manager database [WIP] feat: add PostgreSQL support for manager database Apr 13, 2026
@bumarcell bumarcell changed the title [WIP] feat: add PostgreSQL support for manager database feat: add PostgreSQL support for manager database Apr 14, 2026
@bumarcell
bumarcell force-pushed the feat/postgres-support branch from e48a722 to 4261217 Compare April 14, 2026 10:03
@bumarcell

Copy link
Copy Markdown
Author

I have this already deployed and running. Please let me know if you find any problem!

bumarcell and others added 6 commits April 23, 2026 11:36
The Dragonfly manager application has supported PostgreSQL since
dragonflyoss/dragonfly#1459, but the Helm chart only renders MySQL
configuration in the manager configmap.

This adds:
- externalPostgres values section (host, port, database, sslMode, etc.)
- database.type field in the configmap (postgres or mysql)
- database.postgres block when externalPostgres is enabled; mysql block
  only rendered when postgres is disabled
- manager.extraInitContainers support for custom init containers (e.g.
  to inject database credentials from a Kubernetes Secret at pod startup)
- config-rendered emptyDir volume and conditional mount swap when
  externalPostgres is enabled, allowing init containers to write the
  final config without duplicate mountPath conflicts
- Example extraInitContainers in values.yaml showing credential injection

When externalPostgres.enable is true, database.type is set to postgres
and the manager uses the postgres config block.

Signed-off-by: Jamal Allogie <jamal.allogie@gmail.com>
Signed-off-by: Jamal Allogie <jamal.allogie@deepl.com>
Addresses Copilot review feedback: when externalPostgres.enable was
true but no extraInitContainers were provided, the manager mounted an
empty config-rendered emptyDir and started without its config file.

Add a dedicated manager.renderConfig flag (default: false) that
controls the config-rendered mount swap, rather than gating on
externalPostgres.enable or manager.extraInitContainers:

  - Gating on externalPostgres.enable breaks the simple path where a
    user enables external postgres with static credentials in
    values.yaml and expects the ConfigMap to be mounted directly.
  - Gating on extraInitContainers couples the mount swap to an
    unrelated escape hatch — users who add an extraInitContainers
    for non-config-rendering reasons (wait-for-X, custom migrations,
    etc.) would silently get an empty config dir.

With manager.renderConfig:

  - Default (false): the manager always mounts the ConfigMap directly,
    extraInitContainers stays a pure escape hatch with no volume side
    effects. Static credentials in values.yaml work out of the box
    for both externalPostgres and externalMysql.
  - Opt-in (true): the manager mounts a config-rendered emptyDir and
    the user's extraInitContainers is expected to populate
    /etc/dragonfly/manager.yaml (e.g. by substituting credentials
    from a Kubernetes Secret into the raw ConfigMap).

Signed-off-by: Jamal Allogie <jamal.allogie@gmail.com>
Signed-off-by: Jamal Allogie <jamal.allogie@deepl.com>
Signed-off-by: Jamal Allogie <jamal.allogie@deepl.com>
Updated comments for extra init containers and external PostgreSQL configuration.

Signed-off-by: Jamal Allogie <jamal.allogie@deepl.com>
Updated comments for clarity regarding Kubernetes Secret usage.

Signed-off-by: Jamal Allogie <jamal.allogie@deepl.com>
Signed-off-by: Jamal Allogie <jamal.allogie@deepl.com>
@bumarcell
bumarcell force-pushed the feat/postgres-support branch from 748a592 to 92699e2 Compare April 23, 2026 12:54
Signed-off-by: Jamal Allogie <jamal.allogie@deepl.com>
@junjieteo

Copy link
Copy Markdown

Will this be merged soon?

@tz-torchai

tz-torchai commented May 19, 2026

Copy link
Copy Markdown

Thanks for the PR! Could you also add existingSecret field so d7y directly reads from the K8s secret instead of using init container?

cc: @gaius-qi @jim3ma @chlins @yxxhero @Liam-Zhao for review

@gaius-qi

Copy link
Copy Markdown
Member

@bumarcell Please resolve conflicts.

@bumarcell

Copy link
Copy Markdown
Author

@tz-torchai the initContainer is needed to decide where to pull the creds from, based on the config.
Or did I misunderstand your point?

@bumarcell bumarcell left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaius-qi I don't see any merge conflict (un)fortunately

@tz-torchai

Copy link
Copy Markdown

@tz-torchai the initContainer is needed to decide where to pull the creds from, based on the config. Or did I misunderstand your point?

I see, the cleaner fix would be an app-side PR adding AutomaticEnv() so existingSecret could work via plain secretKeyRef env vars with no init container, but that's dragonflyoss/dragonfly, separate from this chart PR. Not blocking this one.

cc: @gaius-qi @BraveY @imeoer @yxxhero

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants