1

I have a ConfigMap as following:

kind: ConfigMap
apiVersion: v1
metadata:
  name: health-ip
data:
  ip.json: |-
    [
      1.1.1.1,
      2.2.2.2
    ]

I want to modify/append or patch a small piece of this configuration by adding ip 3.3.3.3 to the ConfigMap so that it becomes:

kind: ConfigMap
apiVersion: v1
metadata:
  name: health-ip
data:
  ip.json: |-
    [
      1.1.1.1,
      2.2.2.2,
      3.3.3.3
    ]

How can it do this using kubectl patch or equivalent?

maopuppets
  • 420
  • 3
  • 9
  • 27
  • 1
    `ConfigMap` is a dictionary from string to string. It has no understanding of data structure. If you want to do that - you need to do it entirely manually using string functions or whatever other programming languages facilities you have. – zerkms Aug 24 '20 at 22:07
  • Possibly duplicate of https://stackoverflow.com/questions/54571185/how-to-patch-a-configmap-in-kubernetes – Jignesh Dhua Aug 24 '20 at 22:47
  • The answer on that link deletes the existing ip's to replace with whatever is mentioned in patch. – maopuppets Aug 24 '20 at 22:54

1 Answers1

1

There is no way to add without replace. As mentioned in comment by zerkms, configmaps does not undestand structure data.

You have a couple of options to achive what you want:

  1. Keep a "template" file of your configmap, update and apply when you need;
  2. Automate the first task with a script that reads the configmap value and append the new value.
  3. Use the kubectl path passing the whole ip list.
Mr.KoopaKiller
  • 3,665
  • 10
  • 21