cloudnative-pg / charts

CloudNativePG Helm Charts
Apache License 2.0
196 stars 98 forks source link

Duplicate Access Mode in Cluster #287

Closed yacinebbt closed 6 months ago

yacinebbt commented 6 months ago

Hello,

When creating a cluster and specifying the access mode type, the type is appended to a hardcoded value which is the ReadWriteOnce:

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: yacine-rwm
  namespace: source
spec:
  instances: 1
  storage:
    pvcTemplate:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 1Gi
      storageClassName: sc-cus
      volumeMode: Filesystem
  walStorage:
    pvcTemplate:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 1Gi
      storageClassName: sc-cus
      volumeMode: Filesystem

The auto created pvcs have the following specs:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: yacine-rwm-1
  namespace: source
spec:
  accessModes:
    - ReadWriteMany
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: sc-cus
  volumeMode: Filesystem
  volumeName: pvc-xx-xxxx-xxxxxx-xxxxxxxxxx-xxxxxxxxx-x

and

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: yacine-rwm-1-wal
  namespace: source
spec:
  accessModes:
    - ReadWriteOnce
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  volumeName: pvc-xx-xxxx-xxxxxx-xxxxxxxxxx-xxxxxxxxx-x
  storageClassName: sc-cus
  volumeMode: Filesystem

The same thing happen if we create a cluster with ReadWriteOnce access mode:

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: yacine-rwo
  namespace: source
spec:
  instances: 1
  storage:
    pvcTemplate:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
      storageClassName: sc-cus
      volumeMode: Filesystem
  walStorage:
    pvcTemplate:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
      storageClassName: sc-cus
      volumeMode: Filesystem

The pvcs created have ReadWriteOnce access mode duplicated:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: yacine-rwo-1
  namespace: source
spec:
  accessModes:
    - ReadWriteOnce
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  volumeName: pvc-xx-xxxx-xxxxxx-xxxxxxxxxx-xxxxxxxxx-x
  storageClassName: sc-cus
  volumeMode: Filesystem

and:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: yacine-rwo-1
  namespace: source
spec:
  accessModes:
    - ReadWriteOnce
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  volumeName: pvc-xx-xxxx-xxxxxx-xxxxxxxxxx-xxxxxxxxx-x
  storageClassName: sc-cus
  volumeMode: Filesystem

The same result if we mix the types, meaning that if we use RWO for storage data and RWX for wals or vice-versa, the pvcs will always have the ReadWriteOnce value + the one we configure in our cluster definition. we can find the definition of the funtion that generate the pvc here: https://github.com/cloudnative-pg/cloudnative-pg/blob/267e7cc1416241453c3e0a1d5ec257e806b184fd/internal/cmd/plugin/fio/fio.go#L92

I think what should be done, is to check if the user don't define a value for AccessMode we keep the ReadWriteOnce as a default value, otherwise, use the defined value by the user. (https://github.com/cloudnative-pg/cloudnative-pg/blob/267e7cc1416241453c3e0a1d5ec257e806b184fd/internal/cmd/plugin/fio/fio.go#L103C4-L103C74)

Thank you for fixing this issue :). Regards,

itay-grudev commented 6 months ago

I'm closing this as it doesn't seem to be related to the Helm charts.