4

I like configMapGenerator with suffix hashes because it forces redeployment of pod that are consuming particular config. But the diff output after changing config is just delete and create, which is less than ideal. Is there a way to get more intelligent diff config maps produces by configMapGenerator with suffix hashes?

Edit:

For example if I have kustomization.yaml:

generatorOptions:
  disableNameSuffixHash: false

 configMapGenerator:
  - name: nginx-conf
    files:
    - nginx.conf=config/nginx.conf
  1. Lets assume that for first time kubectl apply -k generates nginx-conf-aaaa config map.

  2. Edit config/nginx.conf.

  3. Lets assume that kubectl apply -k will generate nginx-config-bbbb.

Is there a way to diff nginx-config-aaaa and nginx-config-bbbb before applying changes?

aisbaa
  • 9,867
  • 6
  • 33
  • 48
  • Hello @aisbaa, Could you please explain what you mean by: "more intelligent diff config maps"? Using kustomize you can create your own generators. You need to extend kustomize functionality: https://kubectl.docs.kubernetes.io/guides/extending_kustomize/. Here are generating options: https://github.com/kubernetes-sigs/kustomize/blob/master/examples/generatorOptions.md. You can also loot at this similar topic: https://stackoverflow.com/questions/67067083/configmap-that-can-reference-current-namespace/67075274#67075274 – Mikołaj Głodziak Apr 29 '21 at 07:01
  • Thank you @MikołajGłodziak, I was not aware of kustomize plugin system. – aisbaa Apr 29 '21 at 12:42
  • did you find a solution using kustomize plugin system? – Mikołaj Głodziak Apr 29 '21 at 14:16
  • Not yet. I have a hunch that it would require change or plugin in/for kubectl. Kustomization part just produces manifests, kubectl does the diffing. – aisbaa May 03 '21 at 08:03
  • Did you try add parameter: `behavior: [create|replace|merge]`? If not, you will find here more information and an example usage: https://kubectl.docs.kubernetes.io/guides/extending_kustomize/builtins/#field-name-configmapgenerator. "This allows an overlay to modify or replace an existing configMap from the parent." – Mikołaj Głodziak May 04 '21 at 13:23

1 Answers1

1

You can do something like this

  • Get the current version of the ConfigMap and write it to a file current.yaml

    kubectl get configmap nginx-conf-aaaa -o=yaml > ./current.yaml

  • After making the changes get the new version of the ConfigMap in new.yaml

    kubectl kustomize . > ./new.yaml

  • Then perform a git diff

    git diff --no-index ./current.yaml ./new.yaml

If you are happy with the diff, go ahead and apply the changes.

GSSwain
  • 5,787
  • 2
  • 19
  • 24