Home > Software design >  Reference a secret's value when the key contains a (.) dot?
Reference a secret's value when the key contains a (.) dot?

Time:11-16

My secret file looks like:

apiVersion: v1
kind: Secret
metadata:
  name: secret
type: Opaque
stringData:
  "user.name":  "user"
  "user.password":  "password"

And I am trying to get a value with the next code:

{{- $secret := lookup "v1" "Secret" .Release.Namespace "secret" -}}
  {{- if $secret -}}
       {{- print $secret.data.user.password}}

The problem is "user.password" key contains a dot and I haven't found how to fix it. Thanks for any help!

CodePudding user response:

You can use the index function to access map values with dots in them like:

{{- print (index $secret.data "user.password")}}
  • Related