kuberneteskubernetes-helmkustomize

How to pass kustomize configmap to helm values


I have kustomize deployment which installs helm chart. This helm chart expects particular config map to exist and be mounted into pod. configMapGenerator component generates config maps with hash suffix.

I.e. following kustomize section:

configMapGenerator:
  - name: my-config-map
    files:
      - my-file.json

Will generate config map with name my-config-map-fdt4f87bkm. I want to pass this config map to helm chart in HelmRelease:

    values:
        configmap: my-config-map

However this does not work, becasue real name of config map is my-config-map-fdt4f87bkm. I want to keep using configMapGenerator to ensure that pods are rolled when there is conifguration change.

How I can pass real name of config map there?


Solution

  • You have two ways. Either turn off suffix hash like:

    configMapGenerator:
    - name: my-config-map
      files:
      - my-file.json
      options:
        disableNameSuffixHash: true
    
    

    or use kustomizeconfig.

    (I'm considering by HelmRelease You mean FluxCD HelmRelease object and You provide values to it by .spec.valuesFrom not .spec.values)

    for kustomize configuration, You have to provide a file with this content:

    ---
    nameReference:
    - kind: ConfigMap
      version: v1
      fieldSpecs:
      - path: spec/valuesFrom/name
        kind: HelmRelease
    

    this file makes kustomize to append configMap suffixes to referenced configMaps for helm release values. now set your kustomization.yaml to use this file:

    ---
    apiVersion: kustomize.config.k8s.io/v1beta1
    
    kind: Kustomization
    
    
    resources:
    - helmrelease.yaml
    
      
    configMapGenerator:
    - name: my-config-map
      files:
      - my-file.json
    
        
    configurations:
    - kustomizeconfig.yaml
    

    Output of kustomize build using kustomizeconfig file:

    apiVersion: v1
    data:
      my-file.json: |
        {
          "this": "that"
        }
    kind: ConfigMap
    metadata:
      name: my-config-map-mb2ck9tb4f
    ---
    apiVersion: helm.toolkit.fluxcd.io/v2beta1
    kind: HelmRelease
    metadata:
      name: my-release
    spec:
      chart:
        spec:
          chart: test
          sourceRef:
            kind: HelmRepository
            name: test
            namespace: test
          version: 1.1.1
      releaseName: my-release
      targetNamespace: kkk
      timeout: 15m
      valuesFrom:
      - kind: ConfigMap
        name: my-config-map-mb2ck9tb4f