Skip to content

Commit

Permalink
Chart: Fix PgBouncer exporter sidecar (#16099)
Browse files Browse the repository at this point in the history
An extra colon crept in and was breaking the pgbouncer exporter sidecar
  • Loading branch information
jedcunningham committed May 26, 2021
1 parent 2c17257 commit 71ef2f2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chart/templates/secrets/pgbouncer-stats-secret.yaml
Expand Up @@ -34,5 +34,5 @@ metadata:
{{- end }}
type: Opaque
data:
connection: {{ urlJoin (dict "scheme" "postgresql" "userinfo" (printf "%s:%s" (.Values.data.metadataConnection.user | urlquery) (.Values.data.metadataConnection.pass | urlquery) ) "host" (printf "127.0.0.1::%s" (.Values.ports.pgbouncer | toString)) "path" "/pgbouncer" "query" "sslmode=disable") | b64enc | quote }}
connection: {{ urlJoin (dict "scheme" "postgresql" "userinfo" (printf "%s:%s" (.Values.data.metadataConnection.user | urlquery) (.Values.data.metadataConnection.pass | urlquery) ) "host" (printf "127.0.0.1:%s" (.Values.ports.pgbouncer | toString)) "path" "/pgbouncer" "query" "sslmode=disable") | b64enc | quote }}
{{- end }}
41 changes: 41 additions & 0 deletions chart/tests/test_pgbouncer.py
Expand Up @@ -314,3 +314,44 @@ def test_ssl_config(self):
encoded = jmespath.search(f'data."{key}"', docs[0])
value = base64.b64decode(encoded).decode()
assert expected == value


class PgbouncerExporterTest(unittest.TestCase):
def test_secret_not_created_by_default(self):
docs = render_chart(
show_only=["templates/secrets/pgbouncer-stats-secret.yaml"],
)
assert 0 == len(docs)

def _get_connection(self, values: dict) -> str:
docs = render_chart(
values=values,
show_only=["templates/secrets/pgbouncer-stats-secret.yaml"],
)
encoded_connection = jmespath.search("data.connection", docs[0])
return base64.b64decode(encoded_connection).decode()

def test_default_exporter_secret(self):
connection = self._get_connection({"pgbouncer": {"enabled": True}})
assert "postgresql://postgres:postgres@127.0.0.1:6543/pgbouncer?sslmode=disable" == connection

def test_exporter_secret_with_overrides(self):
connection = self._get_connection(
{
"pgbouncer": {"enabled": True},
"data": {
"metadataConnection": {
"user": "username@123123",
"pass": "password@!@#$^&*()",
"host": "somehost",
"port": 7777,
"db": "somedb",
},
},
"ports": {"pgbouncer": 1111},
}
)
assert (
"postgresql://username%40123123:password%40%21%40%23$%5E&%2A%28%29@127.0.0.1:1111"
"/pgbouncer?sslmode=disable" == connection
)

0 comments on commit 71ef2f2

Please sign in to comment.