Skip to content

Replace bitnami postgresql with integrated one#389

Merged
taylorsilva merged 11 commits into
concourse:masterfrom
cycloidio:feat/remove_bitnami
Sep 15, 2025
Merged

Replace bitnami postgresql with integrated one#389
taylorsilva merged 11 commits into
concourse:masterfrom
cycloidio:feat/remove_bitnami

Conversation

@fhacloid

Copy link
Copy Markdown
Contributor

Existing Issue

Fixes #387.

Why do we need this PR?

This PR will remove the dependency to bitnami chart and replace the postgresql with a simple statefulSet with one master database.

Changes proposed in this pull request

  • Removed bitnami chart dependency
  • Added a postgresql statefulSet enabled when postgresql.enabled == true
  • Updated values.

Contributor Checklist

  • Variables are documented in the README.md
  • Which branch are you merging into?
    • master is for changes related to the current release of the concourse/concourse:latest image and should be good to publish immediately

Reviewer Checklist

This section is intended for the core maintainers only, to track review progress. Please do not
fill out this section.

  • Code reviewed
  • Topgun tests run
  • Back-port if needed
  • Is the correct branch targeted? (master or dev)

@taylorsilva taylorsilva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good overall! Only nit-type of comments and things to change. Ran our k8s integration test suite against it, it only failed on one test related to the externalUrl. Once that change, and the other minor things, are reverted/fixed, this will be good to merge.

Comment thread values.yaml Outdated
Comment thread values.yaml Outdated
Comment thread values.yaml Outdated
Comment thread values.yaml Outdated
Comment thread values.yaml Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread templates/postgres-secret.yaml
Comment thread templates/postgres-configmap.yaml
Comment thread templates/postgres-statefulset.yaml Outdated
@taylorsilva taylorsilva moved this from Todo to In Progress in Pull Requests Aug 27, 2025
@fhacloid

Copy link
Copy Markdown
Contributor Author

Updated with all your comments with fixups, if approve I will rebase and let you merge :)

@fhacloid fhacloid requested a review from taylorsilva August 27, 2025 20:10
@fhacloid fhacloid force-pushed the feat/remove_bitnami branch 2 times, most recently from a3fbe19 to a344f25 Compare August 28, 2025 08:34
Comment thread README.md Outdated
| `postgresql.service.clusterIPs` | Hardcode services IPs | `[]` |
| `postgresql.service.extraSpec` | Add extra `spec` attributes to the postgresql service. | `{}` |
| `postgresql.image` | Set the image repository | `postgres` |
| `postgresql.imageTag` | Set the image tag, exclusive with imageDigest. | `17-postgres` |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't match the default in values.yaml. I think the default should be the major tag 17, not a variant tag.

Comment thread values.yaml Outdated
- secretName: concourse-web-tls
hosts:
- concourse.l.bahl.fr

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this the default value of tls here?

Comment thread values.yaml Outdated
Comment on lines 2774 to 2815
## Ref: https://artifacthub.io/packages/helm/bitnami/postgresql/11.9.8
##

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove reference to bitnami chart

Comment thread values.yaml Outdated
extraSpec:

image: "postgres"
imageTag: "17-bookworm"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

doesn't match default in README.

@fhacloid

fhacloid commented Sep 2, 2025

Copy link
Copy Markdown
Contributor Author

@taylorsilva I updated with your last nits I didn't saw.

We did some more tests on our side and added 3 settings:

  • extraArgs add args to the cmd of postgres
  • configOverride override the postgresql.conf
  • pvcNameOverride added a way to override the name of the pvc template. This helps with migrating (you can point to the existing vpc that what created with the bitnami charts).

We updated the pvc name to match the one that was in the bitnami chart, so migrating via the PVC should work, I would advise to dump the database anyway to be sure. ;)

@fhacloid fhacloid left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I get an error on _helpers.tpl at line 81:
helm lint --values values.yaml
==> Linting .
[ERROR] templates/: template: concourse/templates/_helpers.tpl:102:16: executing "concourse.statefulSet.apiVersion" at <include "concourse.kubeVersion" .>: error calling include: template: concourse/templates/_helpers.tpl:81:59: executing "concourse.kubeVersion" at <"">: invalid value; expected string

Error: 1 chart(s) linted, 1 chart(s) failed
error: Recipe lint failed on line 4 with exit code 1

Does that ring a bell on your side ?

@fhacloid

fhacloid commented Sep 2, 2025

Copy link
Copy Markdown
Contributor Author

Oh, dumb issue, pushing a fix

@fhacloid fhacloid force-pushed the feat/remove_bitnami branch 4 times, most recently from ae9862a to 2b4d061 Compare September 4, 2025 08:45
@fhacloid

fhacloid commented Sep 4, 2025

Copy link
Copy Markdown
Contributor Author

We did some thorough testing for the migration, and it works.

Here are the migration steps if you want to re-use the same pvc:

  1. Backup your database in case something bad happends
  2. Switch to the new chart version, adapt values as you see fit
  3. On postgres 17, the data and pvc must be mounted at /var/lib/postgresql/data, but on the bitnami image, the volume was at /opt/bitnami and the data was at /opt/bitnami/data.

If you remount the same pvc, the data dir will not be detected by the entrypoint. So you must move the content of the data folder in the correct place.

Also, the config for both postgresql.conf and pg_hba.conf was managed using a configmap, the postgres container uses a default one on the data folder, for this migration we can recreate the default config.

For that override the command:

postgresql:
  commandOverride:
      - /bin/bash
      - -ec
      - |
          if [ -d "/var/lib/postgresql/data/data" ]; then
            echo "Migrating existing data directory..."
            mv /var/lib/postgresql/data/data/* /var/lib/postgresql/data/ || true
            rmdir /var/lib/postgresql/data/data || true

            # We recreate the default config file, but you can also override
            # the postgres config using the values provided in the new chart.
            echo "listen_addresses = '*'" > /var/lib/postgresql/data/postgresql.conf
            echo "max_connections = 100" >> /var/lib/postgresql/data/postgresql.conf
            echo "shared_buffers = 128MB" >> /var/lib/postgresql/data/postgresql.conf
            echo "dynamic_shared_memory_type = posix" >> /var/lib/postgresql/data/postgresql.conf
            echo "max_wal_size = 1GB" >> /var/lib/postgresql/data/postgresql.conf
            echo "min_wal_size = 80MB" >> /var/lib/postgresql/data/postgresql.conf
            echo "log_timezone = 'Etc/UTC'" >> /var/lib/postgresql/data/postgresql.conf
            echo "datestyle = 'iso, mdy'" >> /var/lib/postgresql/data/postgresql.conf
            echo "timezone = 'Etc/UTC'" >> /var/lib/postgresql/data/postgresql.conf
            echo "lc_messages = 'en_US.utf8'" >> /var/lib/postgresql/data/postgresql.conf
            echo "lc_monetary = 'en_US.utf8'" >> /var/lib/postgresql/data/postgresql.conf
            echo "lc_numeric = 'en_US.utf8'" >> /var/lib/postgresql/data/postgresql.conf
            echo "lc_time = 'en_US.utf8'" >> /var/lib/postgresql/data/postgresql.conf
            echo "default_text_search_config = 'pg_catalog.english'" >> /var/lib/postgresql/data/postgresql.conf
            echo "local   all             all                                     trust" > /var/lib/postgresql/data/pg_hba.conf
            echo "host    all             all             127.0.0.1/32            trust" >> /var/lib/postgresql/data/pg_hba.conf
            echo "host    all             all             ::1/128                 trust" >> /var/lib/postgresql/data/pg_hba.conf
            echo "local   replication     all                                     trust" >> /var/lib/postgresql/data/pg_hba.conf
            echo "host    replication     all             127.0.0.1/32            trust" >> /var/lib/postgresql/data/pg_hba.conf
            echo "host    replication     all             ::1/128                 trust" >> /var/lib/postgresql/data/pg_hba.conf
            echo "host all all all scram-sha-256" >> /var/lib/postgresql/data/pg_hba.conf
          fi
          exec docker-entrypoint.sh postgres
  1. Delete the postgresql statefulset
  2. Apply the helm chart
  3. There may be a collation issue based on the previous postgresql version you have, if you get this message:
2025-09-04 12:33:45.704 UTC [609] WARNING: database "atc" has a collation version mismatch
2025-09-04 12:33:45.704 UTC [609] DETAIL: The database was created using collation version 2.36, but the operating system provides version 2.41.
2025-09-04 12:33:45.704 UTC [609] HINT: Rebuild all objects in this database that use the default collation and run ALTER DATABASE atc REFRESH COLLATION VERSION, or build PostgreSQL with the right library version.

You will need to alter the DB, you can do it by adding a lifecycle script like so:

postgresql:
  lifecycle:
    postStart:
      exec:
        command:
          - /bin/sh
          - -ec
          - |
            for i in $(seq 1 30); do
              pg_isready -U ${POSTGRES_USER:-{{ .Values.postgresql.auth.user }}} \
                         -d "dbname=${POSTGRES_DB:-{{ .Values.postgresql.auth.database }}}" \
                         -h 127.0.0.1 -p 5432 && \
              psql -U ${POSTGRES_USER:-{{ .Values.postgresql.auth.user }}} \
                   -d ${POSTGRES_DB:-{{ .Values.postgresql.auth.database }}} \
                   -c "ALTER DATABASE atc REFRESH COLLATION VERSION;" && break
              echo "Database not ready yet, retrying in 2s..."
              sleep 2
            done
  1. kubectl rollout restart the postgresql statefulset

Warning

In our tests, we weren't able to find the logs of the postStart script

also:

This is the migration setup we tried on our side, please be very careful, back up your db and test the migration steps on a staging env before making it in production.

@fhacloid

fhacloid commented Sep 4, 2025

Copy link
Copy Markdown
Contributor Author

@taylorsilva Waiting for review :)

Signed-off-by: Frédéric BARRAS HAMPEL <frederic.hampel@cycloid.io>
@fhacloid fhacloid force-pushed the feat/remove_bitnami branch from ec6330d to 45f472a Compare September 9, 2025 18:53
Signed-off-by: Frédéric BARRAS HAMPEL <frederic.hampel@cycloid.io>
Signed-off-by: Frédéric BARRAS HAMPEL <frederic.hampel@cycloid.io>
Signed-off-by: Frédéric BARRAS HAMPEL <frederic.hampel@cycloid.io>
Signed-off-by: Frédéric BARRAS HAMPEL <frederic.hampel@cycloid.io>
Signed-off-by: Frédéric BARRAS HAMPEL <frederic.hampel@cycloid.io>
Signed-off-by: Frédéric BARRAS HAMPEL <frederic.hampel@cycloid.io>
Signed-off-by: Frédéric BARRAS HAMPEL <frederic.hampel@cycloid.io>
Signed-off-by: Frédéric BARRAS HAMPEL <frederic.hampel@cycloid.io>
Signed-off-by: Frédéric BARRAS HAMPEL <frederic.hampel@cycloid.io>
Signed-off-by: Frédéric BARRAS HAMPEL <frederic.hampel@cycloid.io>
@fhacloid fhacloid force-pushed the feat/remove_bitnami branch from 45f472a to 8cb04e3 Compare September 9, 2025 18:56
@fhacloid

Copy link
Copy Markdown
Contributor Author

@taylorsilva still up to review, whenever you get the time ;)

@taylorsilva taylorsilva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM - Running this PR against our E2E test suite and then will merge.

@taylorsilva taylorsilva merged commit 004a628 into concourse:master Sep 15, 2025
4 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Pull Requests Sep 15, 2025
@taylorsilva

Copy link
Copy Markdown
Member

I've published v19 of the chart. Thanks for all your work here!

@fhacloid

Copy link
Copy Markdown
Contributor Author

You're welcome, feel free to ping if you need help on a related subject !

It was a pleasure to contribute ;)

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

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Migrate from bitnami charts

2 participants