mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-04 03:14:35 +02:00
Perform manual failover during the scale down
This commit is contained in:
@@ -41,7 +41,7 @@ func New(logger *logrus.Entry) *Patroni {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Patroni) apiURL(masterPod *v1.Pod) string {
|
||||
func apiURL(masterPod *v1.Pod) string {
|
||||
return fmt.Sprintf("http://%s:%d", masterPod.Status.PodIP, apiPort)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func (p *Patroni) Failover(master *v1.Pod, candidate string) error {
|
||||
return fmt.Errorf("could not encode json: %v", err)
|
||||
}
|
||||
|
||||
request, err := http.NewRequest(http.MethodPost, p.apiURL(master)+failoverPath, buf)
|
||||
request, err := http.NewRequest(http.MethodPost, apiURL(master)+failoverPath, buf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create request: %v", err)
|
||||
}
|
||||
@@ -77,4 +77,4 @@ func (p *Patroni) Failover(master *v1.Pod, candidate string) error {
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -103,3 +103,19 @@ func FindNamedStringSubmatch(r *regexp.Regexp, s string) map[string]string {
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// MapContains returns true if and only if haystack contains all the keys from the needle with matching corresponding values
|
||||
func MapContains(haystack, needle map[string]string) bool {
|
||||
if len(haystack) < len(needle) {
|
||||
return false
|
||||
}
|
||||
|
||||
for k, v := range needle {
|
||||
v2, ok := haystack[k]
|
||||
if !ok || v2 != v {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -46,6 +46,18 @@ var substractTest = []struct {
|
||||
{[]string{"a", "b", "c", "d"}, []string{"a", "bb", "c", "d"}, []string{"b"}, false},
|
||||
}
|
||||
|
||||
var mapContaintsTest = []struct {
|
||||
inA map[string]string
|
||||
inB map[string]string
|
||||
out bool
|
||||
}{
|
||||
{map[string]string{"1": "a", "2": "b", "3": "c", "4": "c"}, map[string]string{"1": "a", "2": "b", "3": "c"}, true},
|
||||
{map[string]string{"1": "a", "2": "b", "3": "c", "4": "c"}, map[string]string{"1": "a", "2": "b", "3": "d"}, false},
|
||||
{map[string]string{}, map[string]string{}, true},
|
||||
{map[string]string{"3": "c", "4": "c"}, map[string]string{"1": "a", "2": "b", "3": "c"}, false},
|
||||
{map[string]string{"3": "c", "4": "c"}, map[string]string{}, true},
|
||||
}
|
||||
|
||||
var substringMatch = []struct {
|
||||
inRegex *regexp.Regexp
|
||||
inStr string
|
||||
@@ -122,3 +134,12 @@ func TestFindNamedStringSubmatch(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapContains(t *testing.T) {
|
||||
for _, tt := range mapContaintsTest {
|
||||
res := MapContains(tt.inA, tt.inB)
|
||||
if res != tt.out {
|
||||
t.Errorf("MapContains expected: %#v, got: %#v", tt.out, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user