Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

SonarQube - Unable to Connect to External Postgres DB #273

Open
danieleagle opened this issue Apr 9, 2021 · 4 comments
Open

SonarQube - Unable to Connect to External Postgres DB #273

danieleagle opened this issue Apr 9, 2021 · 4 comments

Comments

@danieleagle
Copy link

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.

  • sonarqube-postgresql
  • sonarqube-postgresql-headless

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
Copy link
Author

danieleagle commented Apr 10, 2021

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
Copy link
Author

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
Copy link

fl-max commented May 7, 2021

@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
Copy link

ruckc commented Feb 10, 2022

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants