当尝试使用helm函数: lookup时,我根本没有得到任何预期的结果。
我试着读的秘密是这样的
apiVersion: v1
data:
adminPassword: VG9wU2VjcmV0UGFzc3dvcmQxIQ==
adminUser: YWRtaW4=
kind: Secret
metadata:
annotations:
sealedsecrets.bitnami.com/cluster-wide: "true"
name: activemq-artemis-broker-secret
namespace: common
type: Opaque加载adminUser和adminPassword数据的模板舵图如下所示
apiVersion: broker.amq.io/v1beta1
kind: ActiveMQArtemis
metadata:
name: {{ .Values.labels.app }}
namespace: common
spec:
{{ $secret := lookup "v1" "Secret" .Release.Namespace "activemq-artemis-broker-secret" }}
adminUser: {{ $secret.data.adminUser }}
adminPassword: {{ $secret.data.adminPassword }}在使用ArgoCD部署此文件时,我会得到以下错误:
failed exit status 1: Error: template: broker/templates/deployment.yaml:7:23:
executing "broker/templates/deployment.yaml" at <$secret.data.adminUser>:
nil pointer evaluating interface {}.adminUser Use --debug flag to render out invalid YAML秘密和部署都在同一个名称空间(公共)中。
如果我试图从kubectl那里得到这个秘密,它的作用如下
kubectl get secret activemq-artemis-broker-secret -n common -o json
{
"apiVersion": "v1",
"data": {
"adminPassword": "VG9wU2VjcmV0UGFzc3dvcmQxIQ==",
"adminUser": "YWRtaW4="
},
"kind": "Secret",
"metadata": {
"annotations": {
"sealedsecrets.bitnami.com/cluster-wide": "true"
},
"creationTimestamp": "2022-10-10T14:40:49Z",
"name": "activemq-artemis-broker-secret",
"namespace": "common",
"ownerReferences": [
{
"apiVersion": "bitnami.com/v1alpha1",
"controller": true,
"kind": "SealedSecret",
"name": "activemq-artemis-broker-secret",
"uid": "edff38fb-a966-47a6-a706-cb197ac1797d"
}
],
"resourceVersion": "127303988",
"uid": "0679fc5c-7465-4fe1-9197-b483073e93c2"
},
"type": "Opaque"
}这里出了什么问题。我使用helm版本: 3.8.1和Go版本: 1.75
发布于 2022-10-12 14:12:10
此错误是两个部分协同工作的结果:
首先,helm的lookup只在运行的集群中工作,而在运行helm template (没有--validate)时不起作用。如果以这种方式运行,则返回零。(它通常用作lookup ... | default dict {},以避免出现严重的错误消息)。
其次,在部署舵图时,您使用的是实际上在内部运行ArgoCD的helm template。见未决问题:https://github.com/argoproj/argo-cd/issues/5202。这个问题提到了一个可以用来改变这种行为的插件。然而,这样做需要对argocd本身进行一些重新配置,这不是微不足道的,也不是没有副作用的。
https://stackoverflow.com/questions/74043061
复制相似问题