Home > other >  Issue with database connection string using Helm and kubernetes secrets
Issue with database connection string using Helm and kubernetes secrets

Time:07-13

I'm trying to put a formatted Postgres connection string inside a Kubernetes secret. I'm using Helm to deploy the apps to the AKS cluster and after the deployment, looking at the values of the secrets in the Azure portal, I see something strange.

The connection string inside the secrets.yaml is declared in the following way:

DatabaseConnectionString: "{{ (printf "Server=%s;Port=%s;Database=%s;User Id=%s;Password=%s" .Values.database.host .Values.database.port .Values.database.name .Values.database.user .Values.database.password) | b64enc }}"

Looking at the value in the Azure portal, I have the following result:

Server=****;Port=%!s(int64=5432);Database=postgres;User Id=***;Password=***

the value for Port has a strange value, while the others are correct.

What I'm doing wrong?

CodePudding user response:

In the format string, use %d for the (integer) port number.

{{ with .Values.database }}
DatabaseConnectionString: "{{ printf "Server=%s;Port=%d;..." .host .port | b64enc }}"
{{ end }}

This comes from the Go fmt package. The !%s(int64=...) is its way of reporting an error: %s specifically expects a string but it got an integer value instead.

You may also be able to use %v everywhere in the string to get a default format for both strings and numbers. (Note that the format won't be usable as YAML for lists and maps, though.)

  • Related