我正在尝试胶板,但遇到了一个错误。
对于上下文,我定义了一个模板文件test.tmplt和一个数据源文件dev.yaml。
test.tmplt有以下内容:
localAPIEndpoint:
advertiseAddress: {{ (datasource "k8s").api-advertise-ip }}而dev.yaml包含以下内容:
api-advertise-ip: 192.168.0.1如果我试图使用gomplate填充test.tmplt的内容,如下所示:
gomplate -d k8s=./dev.yaml -f ./test.tmplt -o test.conf我得到以下错误:
09:42:44 FTL error="template: ./test.tmplt:2: bad character U+002D '-'"在我看来,它不喜欢模板文件中的“-”符号。有什么解决办法吗?这是有意的行为吗?
编辑1:谢谢@icza给出的答案,这个答案对上面的例子是正确的。但是,如果我将yaml文件修改为有嵌套字段,它似乎就会崩溃。
例如
dev.yaml:
kubernetes:
api-advertise-ip: 192.168.0.0test.tmplt:
localAPIEndpoint:
advertiseAddress: {{ index (datasource "k8s") "kubernetes.api-advertise-ip" }}在这种情况下,它的输出:
gomplate -d k8s=./dev.yaml -f ./test.tmplt -o test.conf是:
localAPIEndpoint:
advertiseAddress: <no value>发布于 2022-09-12 18:27:46
对于那些在这里访问Kubernetes机密值(带有kubectl)的密钥中含有连字符-的值的用户,@icza建议的解决方案是:
kubectl -n <namespace> \
get secret <secret-name> \
-ogo-template='{{ index .data "key-with-hyphens" | base64decode }}'https://stackoverflow.com/questions/64908171
复制相似问题