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

Kubegres complains about missing value for topologyKey when using podAntiAffinity requiredDuringSchedulingIgnoredDuringExecution #56

Closed joes closed 3 years ago

joes commented 3 years ago

Hi!

I attempted to use requiredDuringSchedulingIgnoredDuringExecution as podAntiAffinity:

apiVersion: kubegres.reactive-tech.io/v1
kind: Kubegres
metadata:
  name: example-postgres-db
  namespace: example-db

spec:
  replicas: 3
  # use latest-tag to force imagePullPolicy: always
  image: gitlab.example.se:5050/containers/container-images/postgres/postgres:latest
  imagePullSecrets:
    - name: gitlab-example-se-regcred

  scheduler:
    affinity:
      nodeAffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
          nodeSelectorTerms:
          - matchExpressions:
            - key: example.se/postgres-db-node
              operator: In
              values:
              - example-postgres-db
      podAntiAffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
            - weight: 100
              podAffinityTerm:
                labelSelector:
                    matchExpressions:
                      - key: app
                        operator: In
                        values:
                        - example-postgres-db
                topologyKey: "kubernetes.io/hostname"

  database:
    size: 10Gi

  env:
    - name: POSTGRES_PASSWORD
      valueFrom:
        secretKeyRef:
          name: example-db-admin-secret
          key: superUserPassword

    - name: POSTGRES_REPLICATION_PASSWORD
      valueFrom:
        secretKeyRef:
          name: example-db-admin-secret
          key: replicationUserPassword

However, I receive the following error if I apply the above specification:

The Kubegres "example-postgres-db" is invalid: spec.scheduler.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution.topologyKey: Required value

As far as I can tell this error message is not correct since I have defined topologyKey: "kubernetes.io/hostname".

If I change requiredDuringSchedulingIgnoredDuringExecution to preferredDuringSchedulingIgnoredDuringExecution the configuration can be applied just fine (without errors).

Thank you for making kubegres and I look forward to getting it up and running!

alex-arica commented 3 years ago

Thank you for your message.

Please check Kubernetes official documentation about requiredDuringSchedulingIgnoredDuringExecution: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#podaffinityterm-v1-core

That type does not have the field "weight" since it is not a weighted affinity.

There is an example in Kubernetes official website: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#an-example-of-a-pod-that-uses-pod-affinity

joes commented 3 years ago

Thanks for your assistance!