Description of problem: Create several persistent volume(pv) with multiple access mode, some of the access mode are same, some of them are not. Check the pv in detail. The same access mode show multiple times. Version-Release number of selected component (if applicable): oc v4.0.0-0.81.0 kubernetes v1.11.0+ba8f89f8f9 features: Basic-Auth GSSAPI Kerberos SPNEGO Server https://preserve-qe-lxia-master-etcd-1:8443 openshift v4.0.0-0.81.0 kubernetes v1.11.0+ba8f89f8f9 How reproducible: Always Steps to Reproduce: 1. Create persistent volume with content. --- apiVersion: v1 kind: PersistentVolume metadata: name: pv-45tb1 spec: capacity: storage: 1Gi accessModes: - ReadWriteOnce - ReadWriteOnce - ReadWriteOnce hostPath: path: "/tmp/data" persistentVolumeReclaimPolicy: Delete 2. Check the detail. # oc get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pv-45tb1 1Gi RWO Delete Available 11m pv-45tb2 1Gi RWO,ROX,RWX Delete Available 5m # oc get pv -o yaml apiVersion: v1 items: - apiVersion: v1 kind: PersistentVolume metadata: creationTimestamp: 2018-12-04T08:09:57Z finalizers: - kubernetes.io/pv-protection name: pv-45tb1 namespace: "" resourceVersion: "38967" selfLink: /api/v1/persistentvolumes/pv-45tb1 uid: fd00be21-f79b-11e8-857b-fa163e58f808 spec: accessModes: - ReadWriteOnce - ReadWriteOnce - ReadWriteOnce capacity: storage: 1Gi hostPath: path: /tmp/data type: "" persistentVolumeReclaimPolicy: Delete status: phase: Available - apiVersion: v1 kind: PersistentVolume metadata: creationTimestamp: 2018-12-04T08:16:05Z finalizers: - kubernetes.io/pv-protection name: pv-45tb2 namespace: "" resourceVersion: "39561" selfLink: /api/v1/persistentvolumes/pv-45tb2 uid: d89c5f00-f79c-11e8-857b-fa163e58f808 spec: accessModes: - ReadWriteOnce - ReadWriteMany - ReadOnlyMany capacity: storage: 1Gi hostPath: path: /tmp/data type: "" persistentVolumeReclaimPolicy: Delete status: phase: Available kind: List metadata: resourceVersion: "" selfLink: "" Actual results: spec: accessModes: - ReadWriteOnce - ReadWriteOnce - ReadWriteOnce Expected results: spec: accessModes: - ReadWriteOnce
That's unfortunate result of insufficient validation of PVs / PVCs. We cannot harden the validation now because it could refuse objects that are working today and existing applications could fail.
We already have that check in k8s, https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/util/storage/storage.go#L65 Fixing in the describe command will not break anything that is working today.
(In reply to Liang Xia from comment #2) > We already have that check in k8s, > https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/util/ > storage/storage.go#L65 removeDuplicateAccessModes() linked above affects only `kubectl get pv` (without -o yaml) and `kubectl describe pv`. We already have that code in `oc get/describe pv`. Upstream `kubectl get pv -o yaml` prints full object as it is in API server, with three access modes: accessModes: - ReadWriteOnce - ReadWriteOnce - ReadWriteOnce