Home > Software design >  My requirement is, if the configmap in values.yaml contains the value DOMAIN_NAME then i want replac
My requirement is, if the configmap in values.yaml contains the value DOMAIN_NAME then i want replac

Time:09-27

My requirement is if the configmap in values.yaml contains the value DOMAIN_NAME then i want replace it with {.Values.global.domainName} please help me

Values.yaml

global:
  infraName: abc-qa-bcd
  infraSecretRegion: us-east-1
  domainName: xyz.abcde.com

configmap:
  ALLOWED_ORIGINS: "https://app.DOMAIN_NAME,https://abc-cd.DOMAIN_NAME"
  CREATE_ADMIN_USER: "true"
  CREATE_ADMIN_CDP_API: "true"
  PORT: "8000"

config-map.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name:  {{ .Values.metadata.name }}
  namespace: {{ .Release.Namespace }}
data:
 {{- if .Values.configmap }}
{{- range $key,$value := .Values.configmap }}
  {{$key}}: {{$value | quote}}
{{- end }}
{{- end }}

Thanks in advance.

CodePudding user response:

values.yaml

global:
  infraName: abc-qa-bcd
  infraSecretRegion: us-east-1
  domainName: xyz.abcde.com

configmap:
  ALLOWED_ORIGINS: "https://app.DOMAIN_NAME,https://abc-cd.DOMAIN_NAME"
  CREATE_ADMIN_USER: "true"
  CREATE_ADMIN_CDP_API: "true"
  PORT: "8000"

config-map.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name:  {{ .Values.metadata.name }}
  namespace: {{ .Release.Namespace }}
data: 
  data: |-
  {{- if .Values.configmap }}
  {{- range $key,$value := .Values.configmap }}
  {{- if contains "DOMAIN_NAME" $value }}
  {{- $value = ($value | replace "DOMAIN_NAME" $.Values.global.domainName) }}
  {{- end }}
    {{ $key }}: {{ $value | quote }}
  {{- end }}
  {{- end }}

output

apiVersion: v1
kind: ConfigMap
metadata:
  name: test
  namespace: test
data: 
  data: |-
    ALLOWED_ORIGINS: "https://app.xyz.abcde.com,https://abc-cd.xyz.abcde.com"
    CREATE_ADMIN_CDP_API: "true"
    CREATE_ADMIN_USER: "true"
    PORT: "8000"
  • Related