hostPathVolume not mounting when configured in podTemplate for kubernetes-plugin

10/15/2019

I've been trying to mount a hostPathVolume in a Kubernetes-plugin podTemplate and when the pod gets kicked off via Jenkins master the path is never mounted.

I've deployed Openshift v3.10 in a 5 node cluster, which comes with Jenkins (v 2.89.2) templates and the Kubernetes plugin (v 0.10) already available. In my project I am deploying the jenkins-ephemeral template to test out configuration of a pipeline build. When my pipeline gets kicked off, my custom jenkins agent pod gets kicked off as I expect by the Jenkins master container, but my configured hostPathVolume mount is never mounted. I've tried numerous directories and files, but can't get any of them to mount. Wondering if it could be permissions, but jenkins and my pod log don't show any errors or problems relating to mounting the directory or files. I have a ConfigMap configured like so (omitted some of the tags for brevity):

     apiVersion: v1
     metadata:
       name: jenkins-agent-test
     labels:
       role: jenkins-slave
     data:
       dino: |-
         <org.csanchez.jenkins.plugins.kubernetes.PodTemplate>
           <inheritFrom></inheritFrom>
           <name>dino</name>
           <label>dino</label>
           <serviceAccount>jenkins</serviceAccount>
           <nodeSelector></nodeSelector>
           <containers>
             <org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate>
               <name>jnlp</name>
               <image>blah.blah.blah/deploy/jenkins-agent-test</image>
               ...
           </containers>
           <volumes>
             <hostPathVolume>
               <mountPath>/tmp/test</mountPath>
               <hostPath>/home/sysadmin/test</hostPath>
             </hostPathVolume>
           </volumes>
           ...
         </org.csanchez.jenkins.plugins.kubernetes.PodTemplate>

I expect the volume to be mounted in my pod. oc describe pod dino does not show the mounted volume and I logged into my pod and verified the path is not mounted.  Not sure what else to try or where to look.
-- gshepherd7
jenkins-plugins
kubernetes
openshift

1 Answer

10/16/2019

Figured it out. Maybe this will help someone else. You have to specify the full package for hostPathVolumes...

<volumes>
  <org.csanchez.jenkins.plugins.kubernetes.volumes.HostPathVolume>
     <mountPath>/tmp/test</mountPath>
     <hostPath>/home/sysadmin/test</hostPath>
  </org.csanchez.jenkins.plugins.kubernetes.volumes.HostPathVolume>
</volumes>
-- gshepherd7
Source: StackOverflow