<p>I am mounting a ConfigMap volume to a pod using Go k8 cient where <code>template-conf</code> is a file (deployed helm yaml in the namespace)</p>
<pre class="lang-golang prettyprint-override"><code>    pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{
        Name: &quot;conf&quot;,
        VolumeSource: corev1.VolumeSource{
            ConfigMap: &amp;corev1.ConfigMapVolumeSource{
                LocalObjectReference: corev1.LocalObjectReference{
                    Name: &quot;template-conf&quot;,
                },
            },
        },
    })
</code></pre>
<p>I was wondering if the following are possible to do in Go or if there's a workaround:</p>
<ol>
<li>Replacing the entire contents of the configMap file with another file</li>
<li>Appending more lines to the configMap file. So something like this:</li>
</ol>
<pre class="lang-golang prettyprint-override"><code>if (...) {
    ...append(configMap, {
        &quot;hello-world\nhello-world\nhello-world&quot;
    }),
}
</code></pre>

koonig
<p>ConfigMap resource is not designed to be modified directly by replacing the entire contents or appending lines.</p>
<p>Try:</p>
<pre><code>// Retrieve the existing ConfigMap
configMap, err := clientset.CoreV1().ConfigMaps(&quot;namespace&quot;).Get(context.TODO(), &quot;template-conf&quot;, metav1.GetOptions{})
if err != nil {
    // handle error
}

// Modify the data in the ConfigMap
configMap.Data[&quot;key1&quot;] = &quot;value1&quot;
configMap.Data[&quot;key2&quot;] = &quot;value2&quot;

// Update the ConfigMap
updatedConfigMap, err := clientset.CoreV1().ConfigMaps(&quot;namespace&quot;).Update(context.TODO(), configMap, metav1.UpdateOptions{})
if err != nil {
    // handle error
}
</code></pre>
