使用环境变量引用命名空间

Referring to namespace using environment variable

有谁知道使用环境变量 引用 values.yaml 内部的命名空间 的方法吗?

例如,映射秘密时

secret:
    # RabbitMQ password
    V_RABBIT_PASSWORD:
      secretKeyRef:
        name: jx-staging-rabbit //<--- this needs to work for staging and prod
        key: rabbitmq-password

这是deployment.yaml

中的部分
            - name: {{ $name | quote }}
              valueFrom:
                secretKeyRef:
                  name: {{ $value.secretKeyRef.name | quote }} //<-- trying different combinations here
                  key: {{ $value.secretKeyRef.key | quote }}

尝试次数:

${NAMESPACE}-{{ $value.secretKeyRef.name | quote }}

{{ template "namespace" . }}-{{ $value.secretKeyRef.name | quote }}

谢谢

我猜这是在您使用 jenkins-x 部署的应用程序的 helm chart 中。 Helm 有一个您可以访问的 Release.Namespace 值。所以在 deployment.yaml 中你可以使用 {{ .Release.Namespace }} 虽然 jx-staging 也是版本的名称所以 {{ .Release.Name}} 在这里同样适用。我希望它看起来像:

      valueFrom:
        secretKeyRef:
          name: {{ .Release.Name }}-{{ .Values.rabbitmq.name }}
          key: rabbitmq-password

其中 {{ .Values.rabbitmq.name }} 等于 rabbitmq 或您在 requirements.yaml 中对 rabbitmq 的任何称呼。 (Here's 以这种方式为 postgres 做的示例图表,它也使用 rabbit 但访问 rabbit 密码的方式不同。)

如果您正确加载了密码但仍然遇到密码问题,请确保您设置了明确的密码值,否则您可能会遇到 https://github.com/helm/charts/issues/5167

{{ .Release.Name }} 的使用在 values.yaml 中不起作用,但我不确定您是否需要它,如果您可以在 deployment.yaml 中使用它。

(如果您确实需要从 values.yaml 访问函数,那么您需要在 values.yaml 和 pass it through the tpl function within the template 中为字符串值输入一个条目。)