<p>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.</p>
<p>The connection string inside the <code>secrets.yaml</code> is declared in the following way:</p>
<p><code>DatabaseConnectionString: &quot;{{ (printf &quot;Server=%s;Port=%s;Database=%s;User Id=%s;Password=%s&quot; .Values.database.host .Values.database.port .Values.database.name .Values.database.user .Values.database.password) | b64enc }}&quot;</code></p>
<p>Looking at the value in the Azure portal, I have the following result:</p>
<p><code>Server=****;Port=%!s(int64=5432);Database=postgres;User Id=***;Password=***</code></p>
<p>the value for <code>Port</code> has a strange value, while the others are correct.</p>
<p>What I'm doing wrong?</p>

Salvatore Calla'
<p>In the format string, use <code>%d</code> for the (integer) port number.</p>
<pre class="lang-yaml prettyprint-override"><code>{{ with .Values.database }}
DatabaseConnectionString: &quot;{{ printf &quot;Server=%s;Port=%d;...&quot; .host .port | b64enc }}&quot;
{{ end }}
</code></pre>
<p>This comes from the <a href="https://pkg.go.dev/fmt" rel="nofollow noreferrer">Go <code>fmt</code> package</a>.  The <code>!%s(int64=...)</code> is its way of reporting an error: <code>%s</code> specifically expects a string but it got an integer value instead.</p>
<p>You may also be able to use <code>%v</code> 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.)</p>
