当密钥包含点(.)时,如何引用密钥的值?

huangapple go评论74阅读模式
英文:

Reference a secret's value when the key contains a (.) dot?

问题

我的秘密文件看起来像这样:

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

我正在尝试使用以下代码获取一个值:

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

问题在于"user.password"键包含一个点,我还没有找到如何解决它的方法。
感谢任何帮助!

英文:

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!

答案1

得分: 5

你可以使用index函数来访问具有点的映射值,例如:

{{- print (index $secret.data "user.password")}}
英文:

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

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

huangapple
  • 本文由 发表于 2021年11月16日 02:23:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/69979101.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定