MCPcopy Index your code
hub / github.com/zalando/postgres-operator / syncStandbyClusterConfiguration

Method syncStandbyClusterConfiguration

pkg/cluster/sync.go:1021–1057  ·  view source on GitHub ↗

syncStandbyClusterConfiguration checks whether standby cluster parameters have changed and if necessary sets it via the Patroni API

()

Source from the content-addressed store, hash-verified

1019// syncStandbyClusterConfiguration checks whether standby cluster
1020// parameters have changed and if necessary sets it via the Patroni API
1021func (c *Cluster) syncStandbyClusterConfiguration() error {
1022 var (
1023 err error
1024 pods []v1.Pod
1025 )
1026
1027 standbyOptionsToSet := make(map[string]interface{})
1028 if c.Spec.StandbyCluster != nil {
1029 c.logger.Infof("turning %q into a standby cluster", c.Name)
1030 standbyOptionsToSet["create_replica_methods"] = []string{"bootstrap_standby_with_wale", "basebackup_fast_xlog"}
1031 standbyOptionsToSet["restore_command"] = "envdir \"/run/etc/wal-e.d/env-standby\" /scripts/restore_command.sh \"%f\" \"%p\""
1032
1033 } else {
1034 c.logger.Infof("promoting standby cluster and detach from source")
1035 standbyOptionsToSet = nil
1036 }
1037
1038 if pods, err = c.listPods(); err != nil {
1039 return err
1040 }
1041 if len(pods) == 0 {
1042 return fmt.Errorf("could not call Patroni API: cluster has no pods")
1043 }
1044 // try all pods until the first one that is successful, as it doesn't matter which pod
1045 // carries the request to change configuration through
1046 for _, pod := range pods {
1047 podName := util.NameFromMeta(pod.ObjectMeta)
1048 c.logger.Infof("patching Postgres config via Patroni API on pod %s with following options: %s",
1049 podName, standbyOptionsToSet)
1050 if err = c.patroni.SetStandbyClusterParameters(&pod, standbyOptionsToSet); err == nil {
1051 return nil
1052 }
1053 c.logger.Warningf("could not patch postgres parameters within pod %s: %v", podName, err)
1054 }
1055 return fmt.Errorf("could not reach Patroni API to set Postgres options: failed on every pod (%d total)",
1056 len(pods))
1057}
1058
1059func (c *Cluster) syncSecrets() error {
1060 c.logger.Debug("syncing secrets")

Callers 3

SyncMethod · 0.95
UpdateMethod · 0.95

Calls 3

listPodsMethod · 0.95
NameFromMetaFunction · 0.92

Tested by 1