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

unknown field "spec.volume.volumeClaimTemplates.name" #170

Open ghost opened 11 months ago

ghost commented 11 months ago

Hello,

I'm trying to apply custom settings with volumeClaimTemplates option from this doc: https://www.kubegres.io/doc/properties-explained.html However, it does not work even with the example from that link. The error below:

kubectl apply -f my-postgres.yaml
Error from server (BadRequest): error when creating "my-postgres.yaml": Kubegres in version "v1" cannot be handled as a Kubegres: strict decoding error: unknown field "spec.volume.volumeClaimTemplates.name", unknown field "spec.volume.volumeClaimTemplates.spec"

To test it, just follow steps from "Getting started" and add the volume section from the "All properties explained" article. All settings are default. Is it a bug or the documentation is outdated? Thank you in advance.

alex-arica commented 11 months ago

Hi, Let me help me with this. Could you please share the contents of the YAML that you tried to apply with kubectl ?

ghost commented 11 months ago

Sure! Here you go:

apiVersion: kubegres.reactive-tech.io/v1
kind: Kubegres
metadata:
  name: mypostgres
  namespace: default

spec:

   replicas: 3
   image: postgres:16.1

   database:
      size: 200Mi

   env:
      - name: POSTGRES_PASSWORD
        valueFrom:
           secretKeyRef:
              name: mypostgres-secret
              key: superUserPassword

      - name: POSTGRES_REPLICATION_PASSWORD
        valueFrom:
           secretKeyRef:
              name: mypostgres-secret
              key: replicationUserPassword

   volume:

      volumeClaimTemplates:
         name: anyMount
         spec:
            accessModes: [ "ReadWriteOnce" ]
            storageClassName: local-storage
            resources:
              requests:
                storage: 1Gi

I was trying it woth "volumes" and "volumeMounts" before as well as with different paths and replacing anyMount with any other value. The result was always the same.

alex-arica commented 11 months ago

You find an issue in the documentation. Thank you :)

I updated the doc and released the changes: https://www.kubegres.io/doc/properties-explained.html

Try the following, by adding the field "name" under "metadata":

   volume:

      volumeClaimTemplates:
        - metadata:
            name: anyMount
         spec:
            accessModes: [ "ReadWriteOnce" ]
            storageClassName: local-storage
            resources:
              requests:
                storage: 1Gi
ghost commented 11 months ago

Thank you for your reply! Let's try to apply it:

apiVersion: kubegres.reactive-tech.io/v1
kind: Kubegres
metadata:
  name: mypostgres
  namespace: default

spec:

   replicas: 3
   image: postgres:16.1

   database:
      size: 200Mi

   env:
      - name: POSTGRES_PASSWORD
        valueFrom:
           secretKeyRef:
              name: mypostgres-secret
              key: superUserPassword

      - name: POSTGRES_REPLICATION_PASSWORD
        valueFrom:
           secretKeyRef:
              name: mypostgres-secret
              key: replicationUserPassword

   volume:

      volumeClaimTemplates:
        - metadata:
            name: anyMount
          spec:
            accessModes: [ "ReadWriteOnce" ]
            storageClassName: local-storage
            resources:
              requests:
                storage: 1Gi

(The indentation from the example above may not be accurate due to copying and pasting. I formatted it in a correct way on my lab environment) And the result is the following:

kubectl apply -f my-postgres.yaml
Error from server (BadRequest): error when creating "my-postgres.yaml": Kubegres in version "v1" cannot be handled as a Kubegres: strict decoding error: unknown field "spec.volume.volumeClaimTemplates[0].metadata"
alex-arica commented 11 months ago

Oh you know what, it seems like the initial example in the documentation was correct. I did not notice in your initial YAML example that "-" was missing. Because "volumeClaimTemplates" is an array. Could you please try as below?

For us it works fine.

   volume:

      volumeClaimTemplates:
        - name: anyMount
          spec:
             accessModes: [ "ReadWriteOnce" ]
             storageClassName: local-storage
             resources:
               requests:
                 storage: 1Gi
ghost commented 11 months ago

Oh, indeed! It turns out I missed this point. Thank you Alex. It works fine now.

One more question (if I shouldn't create a new issue): can I use this option to override the default pvc setting? For example, to specify "matchLabels" to bind the kubegres pvc's only to the specific pv's. Or it's intended to add an additional pvc?