title: Migrating ROM, RWO persistent volume claims from in-tree plugin to csi in GKE
body: <p>I currently have a ROM, RWO persistent volume claim that I regularly use as a read only volume in a deployment that sporadically gets repopulated by some job using it as a read write volume while the deployment is scaled down to 0. However, since in-tree plugins will be deprecated in future versions of kubernetes, I'm planning to migrate this process to volumes using csi drivers.</p>
  <p>In order to clarify my current use of this kind of volumes, I'll put a sample yaml configuration file using the basic idea:</p>
  <pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: test
  spec:
    storageClassName: standard
    accessModes:
    - ReadOnlyMany
    - ReadWriteOnce
    resources:
      requests:
        storage: 1Gi
  ---
  apiVersion: batch/v1
  kind: Job
  metadata:
    name: test
  spec:
    template:
      spec:
        containers:
        - name: test
          image: busybox
          # Populate the volume
          command:
          - touch
          - /foo/bar
          volumeMounts:
          - name: test
            mountPath: /foo/
            subPath: foo
        volumes:
        - name: test
          persistentVolumeClaim:
            claimName: test
        restartPolicy: Never
  ---
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    labels:
      app: test
    name: test
  spec:
    replicas: 0
    selector:
      matchLabels:
        app: test
    template:
      metadata:
        labels:
          app: test
      spec:
        containers:
        - name: test
          image: busybox
          command:
          - sh
          - '-c'
          - |
            # Check the volume has been populated
            ls /foo/
            # Prevent the pod from exiting for a while
            sleep 3600
          volumeMounts:
          - name: test
            mountPath: /foo/
            subPath: foo
        volumes:
        - name: test
          persistentVolumeClaim:
            claimName: test
            readOnly: true
  </code></pre>
  <p>so the job populates the the volume and later the deployment is scaled up. However, replacing the <code>storageClassName</code> field <code>standard</code> in the persistent volume claim by <code>singlewriter-standard</code> does not even allow the job to run.</p>
  <p>Is this some kind of bug? Is there some workaround to this using volumes using the csi driver?</p>
  <p>If this is a bug, I'd plan to migrate to using sci drivers later; however, if this is not a bug, how should I migrate my current workflow since in-tree plugins will eventually be deprecated?</p>
  <p><strong>Edit:</strong></p>
  <p>The version of the kubernetes server is <code>1.17.9-gke.1504</code>. As for the storage classes, they are the <code>standard</code> and <code>singlewriter-standard</code> default storage classes:</p>
  <pre class="lang-yaml prettyprint-override"><code>apiVersion: storage.k8s.io/v1
  kind: StorageClass
  metadata:
    labels:
      addonmanager.kubernetes.io/mode: EnsureExists
      kubernetes.io/cluster-service: &quot;true&quot;
    name: standard
  parameters:
    type: pd-standard
  provisioner: kubernetes.io/gce-pd
  reclaimPolicy: Delete
  volumeBindingMode: Immediate
  ---
  apiVersion: storage.k8s.io/v1
  kind: StorageClass
  metadata:
    annotations:
      components.gke.io/component-name: pdcsi-addon
      components.gke.io/component-version: 0.5.1
      storageclass.kubernetes.io/is-default-class: &quot;true&quot;
    labels:
      addonmanager.kubernetes.io/mode: EnsureExists
    name: singlewriter-standard
  parameters:
    type: pd-standard
  provisioner: pd.csi.storage.gke.io
  reclaimPolicy: Delete
  volumeBindingMode: WaitForFirstConsumer
  </code></pre>
  <p>While the error is not shown in the job but in the pod itself (this is just for the <code>singlewriter-standard</code> storage class):</p>
  <p><code>Warning FailedAttachVolume attachdetach-controller AttachVolume.Attach failed for volume &quot;...&quot; : CSI does not support ReadOnlyMany and ReadWriteOnce on the same PersistentVolume</code></p>