Skip to content

Commit a4dc532

Browse files
Jonathan S. Katzjkatz
authored andcommitted
Modify role change check command call
This moves away from making a direct call to the API and instead leverages the command to update the tag on a role change.
1 parent f9eafa9 commit a4dc532

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

internal/operator/cluster/failover.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import (
3232
"k8s.io/client-go/rest"
3333
)
3434

35+
var roleChangeCmd = []string{"patronictl", "edit-config", "--force",
36+
"--set", "tags.primary_on_role_change=null"}
37+
3538
// RemovePrimaryOnRoleChangeTag sets the 'primary_on_role_change' tag to null in the
3639
// Patroni DCS, effectively removing the tag. This is accomplished by exec'ing into
3740
// the primary PG pod, and sending a patch request to update the appropriate data (i.e.
@@ -61,17 +64,11 @@ func RemovePrimaryOnRoleChangeTag(clientset kubernetes.Interface, restconfig *re
6164
}
6265
pod := pods.Items[0]
6366

64-
// generate the curl command that will be run on the pod selected for the failover in order
65-
// to trigger the failover and promote that specific pod to primary
66-
command := make([]string, 3)
67-
command[0] = "/bin/bash"
68-
command[1] = "-c"
69-
command[2] = fmt.Sprintf("curl -s 127.0.0.1:%s/config -XPATCH -d "+
70-
"'{\"tags\":{\"primary_on_role_change\":null}}'", config.DEFAULT_PATRONI_PORT)
71-
67+
// execute the command that will be run on the pod selected for the failover
68+
// in order to trigger the failover and promote that specific pod to primary
7269
log.Debugf("running Exec command '%s' with namespace=[%s] podname=[%s] container name=[%s]",
73-
command, namespace, pod.Name, pod.Spec.Containers[0].Name)
74-
stdout, stderr, err := kubeapi.ExecToPodThroughAPI(restconfig, clientset, command,
70+
roleChangeCmd, namespace, pod.Name, pod.Spec.Containers[0].Name)
71+
stdout, stderr, err := kubeapi.ExecToPodThroughAPI(restconfig, clientset, roleChangeCmd,
7572
pod.Spec.Containers[0].Name, pod.Name, namespace, nil)
7673
log.Debugf("stdout=[%s] stderr=[%s]", stdout, stderr)
7774
if err != nil {

0 commit comments

Comments
 (0)