【发布时间】:2021-07-26 18:57:22
【问题描述】:
我是 helm 图表的新手,在从列表中获取密钥时遇到问题。我正在尝试解析以下结构:
operation:map[initiatedBy:map[username:admin] retry:map[] sync:map[resources:[map[group:apps kind:Deployment name:dev-refresh-service namespace:dev-apps]]
我可以使用 {{.operation.initiatedBy.username}} 获取 initiatedBy 键内的 username 的值:{{.operation.initiatedBy.username}}
但是我无法从列表中获取 name 键的值 - resources
我使用以下语法:{{ operation.sync.resources.name }}
以下是我得到的错误:can't evaluate field name in type interface {}
有什么办法吗?我不确定这是 helm 问题还是 golang 问题
提前致谢
【问题讨论】:
-
试试 {{ operation.sync.resources[0].name }}
-
@taleodor 出现新错误:
msg="Failed to parse new settings: template: app-sync-succeeded:1: bad character U+005B '['" -
实际上看看这个 SO - stackoverflow.com/questions/52682621/… - 如果你玩了一下,应该完成它;本质上看起来问题是资源在您的情况下是一个数组,因此您需要其中的第一个元素
-
@taleodor 会试一试。谢谢你:)
-
@taleodor 兄弟。非常感谢这个:)
标签: go syntax syntax-error kubernetes-helm