英文:
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")}}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论