Oteemo / charts

Helm chart repository
https://oteemo.github.io/charts
MIT License
181 stars 234 forks source link

SonarQube - Unable to Connect to External Postgres DB #273

Open danieleagle opened 3 years ago

danieleagle commented 3 years ago

I have read through the documentation as well as other issues for using an external Postgres DB with this chart. However, the wait-for-db container never succeeds and shows the following error:

nc: bad address 'sonarqube-postgresql'

Keep in mind I only see this error after deleting the sonarqube-postgresql service (see below for more info). If this service hasn't been deleted then the wait-for-db container emits no logs and just hangs indefinitely. I'm perplexed as to why it's trying to connect to this address. The configuration I'm using for external Postgres is below.

jdbcUrlOverride: "jdbc:postgresql://postgres-ha-postgresql-ha-pgpool.database.svc.cluster.local:5432/sonar”
postgresql:
  enabled: false
  postgresqlServer: postgres-ha-postgresql-ha-pgpool.database.svc.cluster.local
  postgresqlDatabase: sonar
  postgresqlPassword: redacted
  postgresqlUsername: sonar

I have Postgres running in my cluster already and it isn't accessible externally which is why I'm using the internal cluster host. This approach has worked fine with GitLab. Also, I noticed that some services for Postgres are being created - not sure why when I'm supposed to be using an external DB. The services being created are below.

Finally, when I don't specify a value for jdbcUrlOverride the installation succeeds but uses the embedded H2 database which isn't what I'm looking for. Any assistance solving this issue would be greatly appreciated. Thanks in advance.

danieleagle commented 3 years ago

This issue might be related to #218. When looking at the changelog for v9.2.2, it states Added a condition to deployment.yaml so that wait-for-db initContainer is only created if postgresql.enabled=true. Therefore, this init container shouldn't even be running according to that statement. What's interesting is I have set postgresql.enabled to false.

danieleagle commented 3 years ago

I was able to fix my problem. I removed the jdbcUrlOverride field and changed the postgresql config to the values below.

image

I then added a secret named external-sonarqube-opts with the following key/value pairs.

SONARQUBE_JDBC_USERNAME: sonar
SONARQUBE_JDBC_PASSWORD: redacted
SONARQUBE_DB_NAME: sonar
SONARQUBE_DB_HOST: postgres-ha-postgresql-ha-pgpool.database.svc.cluster.local/sonar
SONARQUBE_JDBC_URL: jdbc:postgresql://postgres-ha-postgresql-ha-pgpool.database.svc.cluster.local:5432/sonar
SONARQUBE_JDBC_SCHEMA: sonar

Finally, I added the following.

extraConfig:
  configmaps: []
  secrets:
    - external-sonarqube-opts

After that, it connected to my external Postgres DB without issues. I suspect this isn't the standard way of using an external DB with this Helm chart but perhaps my problems can be translated into a fix or enhancement of some sort.

I'll leave this issue open so it can be reviewed.

fl-max commented 3 years ago

@GetchaDEAGLE I think you were just missing postgresql.service.port.

These Helm properties worked for me:

postgresql:
  postgresqlUsername: my-username
  existingSecret: my-secret
  existingSecretPasswordKey: pgsql-password
  postgresqlServer: pgsql.example.com
  postgresqlDatabase: sonarDB
  service:
    port: 5432
ruckc commented 2 years ago

I had to set postgresql.secretKey to get this to work.