<p>I am trying to modify the <code>yaml</code> file of a <code>persistent volume</code> in <code>OpenShift</code> through the API in <code>Go(lang)</code>, I have the following</p>

<pre><code>    pv, err := clientset.CoreV1().PersistentVolumes().List(metav1.ListOptions{})


    for _, persV := range pv.Items {
        // Check status persistent volume
        pvStatus, err := clientset.CoreV1().PersistentVolumes().Get(persV.Name, metav1.GetOptions{})
        if err != nil {
            panic(err.Error())
        }

        patch := []byte(`{"spec":{"template":{"spec":{"containers":[{"persistentVolumeReclaimPolicy":"Retain"}]}}}}`)
        a := fmt.Sprintf("%s", patch)
        fmt.Println(a)
        _, err = clientset.CoreV1().PersistentVolumes().Patch(persV.Name, types.StrategicMergePatchType, patch)
}

</code></pre>

<p>my <code>persistent volume</code> <code>yaml</code></p>

<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
...
...
...
persistentVolumeReclaimPolicy: Retain
status:
  phase: Released
</code></pre>

<p>How could I get the <code>yaml</code> file and modify it from my actual <code>pvStatus</code>?
I would like to change <code>persistentVolumeReclaimPolicy: Retain</code> to <code>persistentVolumeReclaimPolicy: Delete</code></p>

Iago Santos
<p>Basically my error was constructing the <code>patch</code> <code>[]byte</code> value, the script should look like</p>

<pre><code> pv, err := clientset.CoreV1().PersistentVolumes().List(metav1.ListOptions{})


    for _, persV := range pv.Items {
        // Check status persistent volume
        pvStatus, err := clientset.CoreV1().PersistentVolumes().Get(persV.Name, metav1.GetOptions{})
        if err != nil {
            panic(err.Error())
        }

        patch := []byte(`{"spec": {"persistentVolumeReclaimPolicy": "Delete"}}`)
        _, err = clientset.CoreV1().PersistentVolumes().Patch(persV.Name, types.StrategicMergePatchType, patch)
</code></pre>
