<p>I'm developing a Java application that creates some Kubernetes Jobs using the official Kubernetes Java client. Each Job uses its configuration directory, which already exists as a configMap in the cluster. (This configMap was created using <code>kubectl create configmap {name} --from-file=/... </code>)</p>
<p>Using Java client, I successfully created a <code>V1ConfigMap</code> object that refers to a specific configMap, and I also found that <code>V1Volume.setConfigMap()</code> will convert <code>V1ConfigMapVolumeSource</code> to <code>V1Volume</code> that can be mounted by a container.</p>
<p>However, I couldn't find the way to map <code>V1ConfigMap</code> and <code>V1ConfigMapVolumeSource</code>.</p>
<p>Here is my code:</p>
<pre class="lang-java prettyprint-override"><code>public void setConfigMap(V1ConfigMap cm, String mountPath){
       
    V1ConfigMapVolumeSource volSource = new V1ConfigMapVolumeSource();
        
    //Some additional mappings are needed here.
    //volSource = ...(cm)

    //create V1Volume from V1ConfigMapVolumeSource
    String volName = &quot;appSetting&quot;;
    V1Volume settingVol = new V1Volume().name(volName);
    settingVol.setConfigMap(volSource);

    //create V1VolumeMount
    V1VolumeMount volumeMount = new V1VolumeMount();
    volumeMount.setMountPath(mountPath);
    volumeMount.setName(volName);

    //set created objects to the Job
    job.getSpec().getTemplate().getSpec().addVolumesItem(settingVol);
    job.getSpec().getTemplate().getSpec().getContainers().get(0).addVolumeMountsItem(volumeMount);
}
</code></pre>
<p>Does anyone know the way to solve this, or is my way to approach completely wrong?</p>

<p>As stated into the <a href="https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/V1ConfigMapVolumeSource.md" rel="nofollow noreferrer">documentation</a> for <code>V1ConfigMapVolumeSource</code>, there is a <code>name</code> parameter (type <code>String</code>) which is the <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names" rel="nofollow noreferrer">name of the referent</a>.</p>
<p>To link a <code>ConfigMap</code> inside a <code>ConfigMapVolumeSource</code>, just put the name of the <code>ConfigMap</code> in the name parameter, that should be enough.</p>
