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

Allowing manual changes to the statefulsets #64

Closed wunderlichh closed 3 years ago

wunderlichh commented 3 years ago

Hi, first of all thanks for kubegres. We want to use it for a future project and are quite happy that this operator exists.

I am in the process of working out our backup and restore strategy when I ran into a problem. I have configured the Kubegres cluster according to the instructions for creating backups and now I want to restore those to a new cluster. To do this I would like to manually change the StatefulSet of the primary node and mount the PVC where the backups are.

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgresdb-a-1
  namespace: abosys
spec:
  template:
    spec:
      volumes:
+     - name: postgres-backup-storage
+       persistentVolumeClaim:
+         claimName: postgres-backup
      containers:
        volumeMounts:
+       - mountPath: /backup
+         name: postgres-backup-storage

I can save the changes but the operator immediately detects something has been changed and undoes it. Can I prevent this?

message: 'The Spec is NOT up-to-date for a StatefulSet. ''StatefulSet name'': postgresdb-a-1,
  ''SpecName'': Volume.Volumes, ''Expected'': , ''Current'': &Volume{Name:postgres-backup,VolumeSource:VolumeSource{HostPath:nil,EmptyDir:nil,GCEPersistentDisk:nil,AWSElasticBlockStore:nil,GitRepo:nil,Secret:nil,NFS:nil,ISCSI:nil,Glusterfs:nil,PersistentVolumeClaim:&PersistentVolumeClaimVolumeSource{ClaimName:postgres-backup,ReadOnly:false,},RBD:nil,FlexVolume:nil,Cinder:nil,CephFS:nil,Flocker:nil,DownwardAPI:nil,FC:nil,AzureFile:nil,ConfigMap:nil,VsphereVolume:nil,Quobyte:nil,AzureDisk:nil,PhotonPersistentDisk:nil,PortworxVolume:nil,ScaleIO:nil,Projected:nil,StorageOS:nil,CSI:nil,Ephemeral:nil,},}
  - '

Thanks for your help in advance

alex-arica commented 3 years ago

Thank you for your message.

Kubegres monitors the volumes and volumeMounts fields of each StatefulSet. And it is not possible to disable it.

However, what you can do is to add the volumes and volumeMounts configurations that you mention in the YAML of 'kind: Kubegres' representing your cluster of Postgres. Then those volumes and volumeMounts will apply to all StatefulSets and Pods of a cluster of Postgres.

Please check the field "volume" in this page: https://www.kubegres.io/doc/properties-explained.html

wunderlichh commented 3 years ago

Thank you very much. I wasnt aware of this configuration property. Next time i will spend more time reading the docs before bothering you :)