在 configmap 上注入 helm 值

Issue injecting helm value on configmap

有人可以帮忙吗? 我试图在配置映射上注入一个 helm 值,但它破坏了格式。如果我直接使用值而不是 .Values,它工作正常。

我有:

data:
  application.instanceLabelKey: argocd.argoproj.io/instance
  oidc.config: |
    name: Okta
    issuer: https://mycompany.okta.com
    clientID: {{ .Values.okta.clientID }}
    clientSecret: {{ .Values.okta.clientSecret }}
    requestedScopes: ["openid", "profile", "email", "groups"]
    requestedIDTokenClaims: {"groups": {"essential": true}}

结果

data:
  application.instanceLabelKey: argocd.argoproj.io/instance
  oidc.config: "name: Okta\nissuer: https://mycompany.okta.com\nclientID: myClientId \nclientSecret:
    mySecret\nrequestedScopes: [\"openid\", \"profile\",
    \"email\", \"groups\"]\nrequestedIDTokenClaims: {\"groups\": {\"essential\": true}}\n"

最简单的方法是将所有内容存储到 文件中 并先直接使用它

文件oidc.config

name: Okta
issuer: https://mycompany.okta.com
clientID: clientID 
clientSecret: clientSecret
requestedScopes: ["openid", "profile", "email", "groups"]
requestedIDTokenClaims: {"groups": {"essential": true}}

头盔

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  {{- $files := .Files }}
  {{- range tuple "oidc.config" }}
  {{ . }}: |-
        {{ $files.Get . }}
  {{- end }}

参考文档:https://helm.sh/docs/chart_template_guide/accessing_files/

另请查看类似的答案:

它应该与 values.yaml 一起。它在两个方面都对我有用:

  1. 使用 values.yaml
  2. 中的值

Values.yaml:

okta:
  clientSecret: test1233
  clientID: testnew

配置图

apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
  namespace: default
  labels:
    app: test
data:
  application.instanceLabelKey: argocd.argoproj.io/instance
  oidc.config: |
    name: Okta
    issuer: https://mycompany.okta.com
    clientID: {{ .Values.okta.clientID }}
    clientSecret: {{ .Values.okta.clientSecret }}
    requestedScopes: ["openid", "profile", "email", "groups"]
    requestedIDTokenClaims: {"groups": {"essential": true}}

使用的命令:

 helm install testchart .\mycharttest --dry-run

-----输出--------------------

# Source: mycharttest/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
  namespace: default
  labels:
    app: test
    product: test
    db: test
data:
  application.instanceLabelKey: argocd.argoproj.io/instance
  oidc.config: |
    name: Okta
    issuer: https://mycompany.okta.com
    clientID: testnew
    clientSecret: test1233
    requestedScopes: ["openid", "profile", "email", "groups"]
    requestedIDTokenClaims: {"groups": {"essential": true}}
  1. 在运行时使用值

---命令--

 helm install test .\mycharttest --dry-run --set okta.clientID=newclientid --set okta.clientSecret=newsecret

----输出---

# Source: mycharttest/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
  namespace: default
  labels:
    app: test
    product: test
    db: test
data:
  application.instanceLabelKey: argocd.argoproj.io/instance
  oidc.config: |
    name: Okta
    issuer: https://mycompany.okta.com
    clientID: newclientid
    clientSecret: newsecret
    requestedScopes: ["openid", "profile", "email", "groups"]
    requestedIDTokenClaims: {"groups": {"essential": true}

kubernetes 版本:1.22 头盔版本: version.BuildInfo{版本:“v3.7.1”,GitCommit:“1d11fcb5d3f3bf00dbe6fe31b8412839a96b3dc4”,GitTreeState:“clean”,GoVersion:“go1.16.9”}

经过多次尝试,当我在开头跳过一个空格时它起作用了

data:
  application.instanceLabelKey: argocd.argoproj.io/instance
  oidc.config: |
    name: Okta
    issuer: "https://mycompany.okta.com"
    clientID: {{- .Values.okta.clientId }}
    clientSecret: {{- .Values.okta.clientSecret }}
    requestedScopes: ["openid", "profile", "email", "groups"]
    requestedIDTokenClaims: {"groups": {"essential": true}}