reactive-tech / kubegres

Kubegres is a Kubernetes operator allowing to deploy one or many clusters of PostgreSql instances and manage databases replication, failover and backup.
https://www.kubegres.io
Apache License 2.0
1.32k stars 74 forks source link

"storageClassName" definition doesn't work. #164

Closed behniafb closed 11 months ago

behniafb commented 1 year ago

As you can see in my Kubegres.yaml config below, I've set the storageClass to be "local-path":

apiVersion: kubegres.reactive-tech.io/v1
kind: Kubegres
metadata:
  name: mypostgres
spec:
  replicas: {{ .Values.database.replicaCount }}
  image: postgres:14.1

  database:
    size: 5Gi
    storageClassName: local-path

  backup:
    # Backup every 12 hours
    schedule: "0 */12 * * *"
    pvcName: my-backup-pvc
    volumeMount: /var/lib/backup

  env:
    - name: POSTGRES_PASSWORD
      valueFrom:
        secretKeyRef:
          name: {{ .Release.Name }}-database-secret
          key: PASSWORD

    - name: POSTGRES_REPLICATION_PASSWORD
      valueFrom:
        secretKeyRef:
          name: {{ .Release.Name }}-database-secret
          key: REPLICATION_USER_PASSWORD

BUT when it deploys, and creates the related PVC, I see that the storageClass is set to "local-storage" instead of "local-path":

postgres-db-mypostgres-1-0 PVC:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  creationTimestamp: '2023-10-23T13:18:17Z'
  finalizers:
    - kubernetes.io/pvc-protection
  labels:
    app: mypostgres
    index: '1'
  name: postgres-db-mypostgres-1-0
  namespace: sdk
  resourceVersion: '846624'
  uid: 553aba82-334a-4a0f-b43b-c713a82713d3
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: local-storage
  volumeMode: Filesystem
status:
  phase: Pending

SO -> it's always requesting for that SC, which doesn't exist, and because I'm on bare-metal and I don't have any cloud storage provisioned, the database can't deploy, and produces error:

My k8s cluster is on bare-metal.

alex-arica commented 1 year ago

Could you please share the list of the available the storage class in your cluster, with the command:

kubectl get sc

behniafb commented 1 year ago

Could you please share the list of the available the storage class in your cluster, with the command:

kubectl get sc

I'm sorry that I can't do it right now, because I deleted the SC that I created (the local-path - the one that Kubegres had problem with), and currently, I only have local-storage, so Kubegres can work with it correctly:

ubuntu@localhost:~$ kubectl get sc
NAME            PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
local-storage   rancher.io/local-path   Delete          WaitForFirstConsumer   false                  3d22h

But I can assure you that, before deleting that SC, it was like this:

ubuntu@localhost:~$ kubectl get sc
NAME                 PROVISIONER                   RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
local-storage        kubernetes.io/no-provisioner  Delete          WaitForFirstConsumer   false                  3d22h
local-path(default)  rancher.io/local-path         Delete          WaitForFirstConsumer   false                  3d22h

What I've done was, deleting all SCs, and deploying local-storage SC again so Kubegres can work with it, but with my specific provisioned(which is rancher.io/local-path).

alex-arica commented 1 year ago

Thank you.

I checked the code and the only time Kubegres attempts to set the default storage class is when the property 'database.storageClassName' is not set. I use the method below to check whether a storage class name was set:

func (r *UndefinedSpecValuesChecker) isStorageClassNameUndefinedInSpec() bool {

 storageClassName := r.kubegresContext.Kubegres.Spec.Database.StorageClassName
 return storageClassName == nil || *storageClassName == ""

}

The method above is used as follows:

if r.isStorageClassNameUndefinedInSpec() {

  wasSpecChanged = true
  defaultStorageClassName, err := r.defaultStorageClass.GetDefaultStorageClassName()
  if err != nil {
    return err
  }

  kubegresSpec.Database.StorageClassName = &defaultStorageClassName
  r.createLog("spec.Database.StorageClassName", defaultStorageClassName)
 }

If you can reproduce it, I am happy to investigate further.

alex-arica commented 11 months ago

Closing this ticket if there is not any more update.