charts
charts copied to clipboard
Database ping test fails when the username and dbname is different in initdb
Hi everyone,
The database-ping-test fails when i set the value of the database different from the owner in the initdb configuration.
Following is my configuration for cluster chart, I am using kustomize to deploy helm
helmCharts:
- name: cluster
version: 0.0.10
releaseName: psql-gitea
repo: https://cloudnative-pg.github.io/charts
namespace: homelab
valuesInline:
cluster:
instances: 1
initdb:
database: giteadb
owner: gitea
And this results in the following error in the ping-test pod:
psql: error: connection to server at "psql-gitea-cluster-rw.homelab.svc.cluster.local" (10.43.64.140), port 5432 failed: FATAL: database "gitea" does not exist
As you can see it tries to connect to gitea database, even though we specified it as giteadb
The connection string and pod configuration:
# psql-gitea-cluster-ping-test pod
spec:
containers:
- args:
- -c
- apk add postgresql-client && psql "postgresql://$PGUSER:[email protected]:5432"
-c 'SELECT 1'
command:
- sh
env:
- name: PGUSER
valueFrom:
secretKeyRef:
key: username
name: psql-gitea-cluster-app
- name: PGPASS
valueFrom:
secretKeyRef:
key: password
name: psql-gitea-cluster-app
image: alpine:3.17
When I manually try to connect with the giteadb, i can succesfully create a connection:
➜ kubectl exec -it psql-gitea-cluster-1 -c postgres -- psql 'postgresql://gitea:<AUTO_GENERATED_PASSWORD>@psql-gitea-cluster-rw.homelab:5432/giteadb' -c 'SELECT 1'
?column?
----------
1
(1 row)
So the problem is, in the test-pod there is no db specified so it (by default) tries to connect to a db with the same name as the user. As there is no db created as such, it fails.