postgres-operator icon indicating copy to clipboard operation
postgres-operator copied to clipboard

Manual switchover via operator

Open FactorT opened this issue 1 year ago • 5 comments

Please, answer some short questions which should help us to understand your problem / question better?

  • Which image of the operator are you using? registry.opensource.zalan.do/acid/postgres-operator:v1.8.2
  • Where do you run it - cloud or metal? Kubernetes or OpenShift? Bare Metal K8s
  • Are you running Postgres Operator in production? no
  • Type of issue? question

Does the operator support manual swithover? I know that I can enter in pod and run switchover via patronictl. But it may be convenient and useful to be able to do a switchover using an operator, for example, through an endpoint annotation.

FactorT avatar Jul 15 '22 10:07 FactorT

You can indeed add the annotation zalando-postgres-operator-rolling-update-required: true to the pods and the operator will discover it on next sync and think it has to do a rolling update.

FxKu avatar Jul 15 '22 16:07 FxKu

Thank you very much @FxKu! This workaround sounds good. But is there a way to force operator run sync operation early? For example via send a request to service postgres-operator.

FactorT avatar Jul 18 '22 07:07 FactorT

Only by deleting the operator pod you can force a sync of all clusters.

FxKu avatar Jul 18 '22 16:07 FxKu

Thank you very much @FxKu for your answers! Could you give me advise please.

I want to try make a PR with switchover functionality via operator. How do you think is it possible to realise it with the next approach?

  1. Add optional section in spec section of kind: postgresql manifest spec: patroni: switchover: enabled: true targetInstance: acid-test-cluster-1 This enable swithcover functionality via operator for our postgresql cluster and set target instance for promoting. Operator will be looking for the trigger in cluster's annotation to perform a switchover.
  2. When we need make swithover we need to add annotation for our postgresql cluster: kubectl annotate postgresql acid-test-cluster acid.zalan.do/swithcover="$(date)"
  3. After that we need to delete operator's pod for trigger sync operation.
  4. Pod make sync. Detect switchover annotation and make switchover via patroni api.
  5. After that we disable switchover section in cluster's spec.

FactorT avatar Jul 19 '22 07:07 FactorT

You can indeed add the annotation zalando-postgres-operator-rolling-update-required: true to the pods and the operator will discover it on next sync and think it has to do a rolling update.

Is it recommended to remove annotation after rollout? I noticed that when the annotation is removed, another rollout happens. I also saw that regardless of the true or false value, the rollout happens, is this expected?

ms3rgio avatar Aug 12 '22 19:08 ms3rgio