Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pgbouncer exporter sidecar #16099

Merged
merged 1 commit into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion chart/templates/secrets/pgbouncer-stats-secret.yaml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
)