mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-09-30 13:16:25 +02:00
Extend MaintenanceWindows parameter usage (#2810)
Consider maintenance window when migrating master pods and replacing pods (rolling update)
This commit is contained in:
+13
-13
@@ -20,19 +20,19 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
failoverPath = "/failover"
|
||||
configPath = "/config"
|
||||
clusterPath = "/cluster"
|
||||
statusPath = "/patroni"
|
||||
restartPath = "/restart"
|
||||
ApiPort = 8008
|
||||
timeout = 30 * time.Second
|
||||
switchoverPath = "/switchover"
|
||||
configPath = "/config"
|
||||
clusterPath = "/cluster"
|
||||
statusPath = "/patroni"
|
||||
restartPath = "/restart"
|
||||
ApiPort = 8008
|
||||
timeout = 30 * time.Second
|
||||
)
|
||||
|
||||
// Interface describe patroni methods
|
||||
type Interface interface {
|
||||
GetClusterMembers(master *v1.Pod) ([]ClusterMember, error)
|
||||
Switchover(master *v1.Pod, candidate string) error
|
||||
Switchover(master *v1.Pod, candidate string, scheduled_at string) error
|
||||
SetPostgresParameters(server *v1.Pod, options map[string]string) error
|
||||
SetStandbyClusterParameters(server *v1.Pod, options map[string]interface{}) error
|
||||
GetMemberData(server *v1.Pod) (MemberData, error)
|
||||
@@ -103,7 +103,7 @@ func (p *Patroni) httpPostOrPatch(method string, url string, body *bytes.Buffer)
|
||||
}
|
||||
}()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
if resp.StatusCode < http.StatusOK || resp.StatusCode >= 300 {
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not read response: %v", err)
|
||||
@@ -128,7 +128,7 @@ func (p *Patroni) httpGet(url string) (string, error) {
|
||||
return "", fmt.Errorf("could not read response: %v", err)
|
||||
}
|
||||
|
||||
if response.StatusCode != http.StatusOK {
|
||||
if response.StatusCode < http.StatusOK || response.StatusCode >= 300 {
|
||||
return string(bodyBytes), fmt.Errorf("patroni returned '%d'", response.StatusCode)
|
||||
}
|
||||
|
||||
@@ -136,9 +136,9 @@ func (p *Patroni) httpGet(url string) (string, error) {
|
||||
}
|
||||
|
||||
// Switchover by calling Patroni REST API
|
||||
func (p *Patroni) Switchover(master *v1.Pod, candidate string) error {
|
||||
func (p *Patroni) Switchover(master *v1.Pod, candidate string, scheduled_at string) error {
|
||||
buf := &bytes.Buffer{}
|
||||
err := json.NewEncoder(buf).Encode(map[string]string{"leader": master.Name, "member": candidate})
|
||||
err := json.NewEncoder(buf).Encode(map[string]string{"leader": master.Name, "member": candidate, "scheduled_at": scheduled_at})
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not encode json: %v", err)
|
||||
}
|
||||
@@ -146,7 +146,7 @@ func (p *Patroni) Switchover(master *v1.Pod, candidate string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return p.httpPostOrPatch(http.MethodPost, apiURLString+failoverPath, buf)
|
||||
return p.httpPostOrPatch(http.MethodPost, apiURLString+switchoverPath, buf)
|
||||
}
|
||||
|
||||
//TODO: add an option call /patroni to check if it is necessary to restart the server
|
||||
|
||||
Reference in New Issue
Block a user