<p>I am using the go k8s kube client . I am trying to create a persistent volume in my cluster . I want to use the hostPath type. However I cannot find any documentation about how to do that in go . I have the following code</p>
<pre class="lang-golang prettyprint-override"><code>
vl := v1.PersistentVolume{

        Spec: v1.PersistentVolumeSpec{
            //VolumeMode: v1.PersistentVolumeMode(),

            StorageClassName: &quot;manual&quot;,
            AccessModes: []v1.PersistentVolumeAccessMode{
                &quot;ReadWriteMany&quot;,
            },
            Capacity: v1.ResourceList{
                v1.ResourceName(v1.ResourceStorage): resource.MustParse(&quot;2Gi&quot;),
            },
        },
    }

    vl.Name = &quot;golang-demo-storage&quot;
</code></pre>
<p>If i try to create the above persistent volume as it is I get an error saying <code>PersistentVolume &quot;golang-demo-storage&quot; is invalid: spec: Required value: must specify a volume type</code> which makes sense since I have to define a type</p>
<p>However I cannot find any documentation about where in the struct to actually define the hostpath.</p>
<p>Do you have any reference that would help me ?</p>

Manos Kounelakis
<p>So i was looking at the wrong fields. The field i hav to look at is the <code>PersistentVolumeSource</code> at the <code>PersistentVolumeSpec</code>. Here is the snippet of the code that worked for me</p>
<pre class="lang-golang prettyprint-override"><code>
    ctx := context.TODO()
    vl := v1.PersistentVolume{

        TypeMeta: metav1.TypeMeta{Kind: &quot;PersistentVolume&quot;},
        ObjectMeta: metav1.ObjectMeta{
            Name: name,
        },

        Spec: v1.PersistentVolumeSpec{
            //VolumeMode: v1.PersistentVolumeMode(),

            StorageClassName: &quot;manual&quot;,
            AccessModes: []v1.PersistentVolumeAccessMode{
                &quot;ReadWriteMany&quot;,
            },
            Capacity: v1.ResourceList{
                v1.ResourceName(v1.ResourceStorage): resource.MustParse(&quot;2Gi&quot;),
            },
            PersistentVolumeSource : v1.PersistentVolumeSource{
                HostPath: &amp;v1.HostPathVolumeSource{
                    Path: &quot;/demo&quot;,
                },
            },
        },
    }

    _ , e := clientset.CoreV1().PersistentVolumes().Create(ctx , &amp;vl , metav1.CreateOptions{})

</code></pre>
<p>I had to define a <code>PersistentVolumeSource</code> field and in its initialization i passed the host path configuration i needed</p>
