Skip to content

Commit c5cc90a

Browse files
committed
Update terms for Patroni v4 support
This update changes references from "master" to "primary" in support of Patroni v4. This includes updates to tests and various other methods. For the time being, the leader_label_value is manually set to "master" to facilitate the existing label usage. Issue: PGO-1646
1 parent b2596ac commit c5cc90a

File tree

14 files changed

+43
-36
lines changed

14 files changed

+43
-36
lines changed

internal/controller/postgrescluster/instance.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ func (i Instance) IsWritable() (writable, known bool) {
132132

133133
// TODO(cbandy): Update this to consider when Patroni is paused.
134134

135-
return strings.HasPrefix(member[role:], `"role":"master"`), true
135+
return strings.HasPrefix(member[role:], `"role":"master"`) ||
136+
strings.HasPrefix(member[role:], `"role":"primary"`), true
136137
}
137138

138139
// PodMatchesPodTemplate returns whether or not the Pod for this instance

internal/controller/postgrescluster/instance_rollout_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func TestReconcilerRolloutInstance(t *testing.T) {
132132

133133
// A switchover to any viable candidate.
134134
assert.DeepEqual(t, command[:2], []string{"patronictl", "switchover"})
135-
assert.Assert(t, sets.NewString(command...).Has("--master=the-pod"))
135+
assert.Assert(t, sets.NewString(command...).Has("--primary=the-pod"))
136136
assert.Assert(t, sets.NewString(command...).Has("--candidate="))
137137

138138
// Indicate success through stdout.

internal/controller/postgrescluster/instance_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func TestInstanceIsWritable(t *testing.T) {
117117
assert.Assert(t, !writable)
118118

119119
// Patroni leader
120-
instance.Pods[0].Annotations["status"] = `{"role":"master"}`
120+
instance.Pods[0].Annotations["status"] = `{"role":"primary"}`
121121
writable, known = instance.IsWritable()
122122
assert.Assert(t, known)
123123
assert.Assert(t, writable)
@@ -392,7 +392,7 @@ func TestWritablePod(t *testing.T) {
392392
Namespace: "namespace",
393393
Name: "pod",
394394
Annotations: map[string]string{
395-
"status": `{"role":"master"}`,
395+
"status": `{"role":"primary"}`,
396396
},
397397
DeletionTimestamp: &metav1.Time{},
398398
},
@@ -426,7 +426,7 @@ func TestWritablePod(t *testing.T) {
426426
Namespace: "namespace",
427427
Name: "pod",
428428
Annotations: map[string]string{
429-
"status": `{"role":"master"}`,
429+
"status": `{"role":"primary"}`,
430430
},
431431
},
432432
Status: corev1.PodStatus{
@@ -491,7 +491,7 @@ func TestWritablePod(t *testing.T) {
491491
Namespace: "namespace",
492492
Name: "pod",
493493
Annotations: map[string]string{
494-
"status": `{"role":"master"}`,
494+
"status": `{"role":"primary"}`,
495495
},
496496
},
497497
Status: corev1.PodStatus{
@@ -964,7 +964,7 @@ func TestPodsToKeep(t *testing.T) {
964964
checks func(*testing.T, []corev1.Pod)
965965
}{
966966
{
967-
name: "RemoveSetWithMasterOnly",
967+
name: "RemoveSetWithPrimaryOnly",
968968
instances: []corev1.Pod{
969969
{
970970
ObjectMeta: metav1.ObjectMeta{
@@ -998,7 +998,7 @@ func TestPodsToKeep(t *testing.T) {
998998
assert.Equal(t, len(p), 0)
999999
},
10001000
}, {
1001-
name: "KeepMasterOnly",
1001+
name: "KeepPrimaryOnly",
10021002
instances: []corev1.Pod{
10031003
{
10041004
ObjectMeta: metav1.ObjectMeta{
@@ -1087,7 +1087,7 @@ func TestPodsToKeep(t *testing.T) {
10871087
assert.Equal(t, len(p), 0)
10881088
},
10891089
}, {
1090-
name: "MasterLastInSet",
1090+
name: "PrimaryLastInSet",
10911091
instances: []corev1.Pod{
10921092
{
10931093
ObjectMeta: metav1.ObjectMeta{
@@ -1116,7 +1116,7 @@ func TestPodsToKeep(t *testing.T) {
11161116
assert.Equal(t, p[0].Labels[naming.LabelRole], "master")
11171117
},
11181118
}, {
1119-
name: "ScaleDownSetWithMaster",
1119+
name: "ScaleDownSetWithPrimary",
11201120
instances: []corev1.Pod{
11211121
{
11221122
ObjectMeta: metav1.ObjectMeta{
@@ -1167,7 +1167,7 @@ func TestPodsToKeep(t *testing.T) {
11671167
assert.Equal(t, p[1].Labels[naming.LabelInstanceSet], "max")
11681168
},
11691169
}, {
1170-
name: "ScaleDownSetWithoutMaster",
1170+
name: "ScaleDownSetWithoutPrimary",
11711171
instances: []corev1.Pod{
11721172
{
11731173
ObjectMeta: metav1.ObjectMeta{
@@ -1220,7 +1220,7 @@ func TestPodsToKeep(t *testing.T) {
12201220
assert.Equal(t, p[2].Labels[naming.LabelRole], "replica")
12211221
},
12221222
}, {
1223-
name: "ScaleMasterSetToZero",
1223+
name: "ScalePrimarySetToZero",
12241224
instances: []corev1.Pod{
12251225
{
12261226
ObjectMeta: metav1.ObjectMeta{
@@ -1262,7 +1262,7 @@ func TestPodsToKeep(t *testing.T) {
12621262
assert.Equal(t, p[1].Labels[naming.LabelInstanceSet], "daisy")
12631263
},
12641264
}, {
1265-
name: "RemoveMasterInstanceSet",
1265+
name: "RemovePrimaryInstanceSet",
12661266
instances: []corev1.Pod{
12671267
{
12681268
ObjectMeta: metav1.ObjectMeta{

internal/controller/postgrescluster/patroni.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (r *Reconciler) handlePatroniRestarts(
9494
return r.PodExec(ctx, pod.Namespace, pod.Name, container, stdin, stdout, stderr, command...)
9595
})
9696

97-
return errors.WithStack(exec.RestartPendingMembers(ctx, "master", naming.PatroniScope(cluster)))
97+
return errors.WithStack(exec.RestartPendingMembers(ctx, "primary", naming.PatroniScope(cluster)))
9898
}
9999

100100
// When the primary does not need to restart but a replica does, restart all

internal/controller/postgrescluster/pgbackrest_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ func TestReconcileStanzaCreate(t *testing.T) {
751751

752752
instances := newObservedInstances(postgresCluster, nil, []corev1.Pod{{
753753
ObjectMeta: metav1.ObjectMeta{
754-
Annotations: map[string]string{"status": `"role":"master"`},
754+
Annotations: map[string]string{"status": `"role":"primary"`},
755755
Labels: map[string]string{
756756
naming.LabelCluster: postgresCluster.GetName(),
757757
naming.LabelInstance: "",
@@ -867,7 +867,7 @@ func TestReconcileReplicaCreateBackup(t *testing.T) {
867867
}
868868
instances := newObservedInstances(postgresCluster, nil, []corev1.Pod{{
869869
ObjectMeta: metav1.ObjectMeta{
870-
Annotations: map[string]string{"status": `"role":"master"`},
870+
Annotations: map[string]string{"status": `"role":"primary"`},
871871
Labels: map[string]string{
872872
naming.LabelCluster: postgresCluster.GetName(),
873873
naming.LabelInstance: "",
@@ -1348,7 +1348,7 @@ func TestReconcileManualBackup(t *testing.T) {
13481348
instances.forCluster[0].Pods[0].Annotations = map[string]string{}
13491349
} else {
13501350
instances.forCluster[0].Pods[0].Annotations = map[string]string{
1351-
"status": `"role":"master"`,
1351+
"status": `"role":"primary"`,
13521352
}
13531353
}
13541354

internal/controller/postgrescluster/pgmonitor_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ func TestReconcilePGMonitorExporterSetupErrors(t *testing.T) {
358358
Pods: []*corev1.Pod{{
359359
ObjectMeta: metav1.ObjectMeta{
360360
Name: "daisy-pod",
361-
Annotations: map[string]string{"status": `{"role":"master"}`},
361+
Annotations: map[string]string{"status": `{"role":"primary"}`},
362362
DeletionTimestamp: &metav1.Time{},
363363
},
364364
}},
@@ -388,7 +388,7 @@ func TestReconcilePGMonitorExporterSetupErrors(t *testing.T) {
388388
Pods: []*corev1.Pod{{
389389
ObjectMeta: metav1.ObjectMeta{
390390
Name: "daisy-pod",
391-
Annotations: map[string]string{"status": `{"role":"master"}`},
391+
Annotations: map[string]string{"status": `{"role":"primary"}`},
392392
},
393393
}},
394394
Runner: &appsv1.StatefulSet{},
@@ -410,7 +410,7 @@ func TestReconcilePGMonitorExporterSetupErrors(t *testing.T) {
410410
Pods: []*corev1.Pod{{
411411
ObjectMeta: metav1.ObjectMeta{
412412
Name: "daisy-pod",
413-
Annotations: map[string]string{"status": `{"role":"master"}`},
413+
Annotations: map[string]string{"status": `{"role":"primary"}`},
414414
},
415415
Status: corev1.PodStatus{
416416
ContainerStatuses: []corev1.ContainerStatus{{
@@ -438,7 +438,7 @@ func TestReconcilePGMonitorExporterSetupErrors(t *testing.T) {
438438
Pods: []*corev1.Pod{{
439439
ObjectMeta: metav1.ObjectMeta{
440440
Name: "daisy-pod",
441-
Annotations: map[string]string{"status": `{"role":"master"}`},
441+
Annotations: map[string]string{"status": `{"role":"primary"}`},
442442
},
443443
Status: corev1.PodStatus{
444444
ContainerStatuses: []corev1.ContainerStatus{{
@@ -469,7 +469,7 @@ func TestReconcilePGMonitorExporterSetupErrors(t *testing.T) {
469469
Pods: []*corev1.Pod{{
470470
ObjectMeta: metav1.ObjectMeta{
471471
Name: "daisy-pod",
472-
Annotations: map[string]string{"status": `{"role":"master"}`},
472+
Annotations: map[string]string{"status": `{"role":"primary"}`},
473473
},
474474
Status: corev1.PodStatus{
475475
ContainerStatuses: []corev1.ContainerStatus{{
@@ -536,7 +536,7 @@ func TestReconcilePGMonitorExporter(t *testing.T) {
536536
Pods: []*corev1.Pod{{
537537
ObjectMeta: metav1.ObjectMeta{
538538
Name: "one-daisy-pod",
539-
Annotations: map[string]string{"status": `{"role":"master"}`},
539+
Annotations: map[string]string{"status": `{"role":"primary"}`},
540540
},
541541
Status: corev1.PodStatus{
542542
Phase: corev1.PodRunning,
@@ -634,7 +634,7 @@ func TestReconcilePGMonitorExporterStatus(t *testing.T) {
634634
Pods: []*corev1.Pod{{
635635
ObjectMeta: metav1.ObjectMeta{
636636
Name: "daisy-pod",
637-
Annotations: map[string]string{"status": `{"role":"master"}`},
637+
Annotations: map[string]string{"status": `{"role":"primary"}`},
638638
},
639639
Status: corev1.PodStatus{
640640
ContainerStatuses: []corev1.ContainerStatus{{

internal/controller/postgrescluster/postgres_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ func TestReconcileDatabaseInitSQL(t *testing.T) {
951951
Namespace: ns.Name,
952952
Name: "pod",
953953
Annotations: map[string]string{
954-
"status": `{"role":"master"}`,
954+
"status": `{"role":"primary"}`,
955955
},
956956
},
957957
Status: corev1.PodStatus{
@@ -1072,7 +1072,7 @@ func TestReconcileDatabaseInitSQLConfigMap(t *testing.T) {
10721072
Namespace: ns.Name,
10731073
Name: "pod",
10741074
Annotations: map[string]string{
1075-
"status": `{"role":"master"}`,
1075+
"status": `{"role":"primary"}`,
10761076
},
10771077
},
10781078
Status: corev1.PodStatus{

internal/controller/postgrescluster/watches.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (*Reconciler) watchPods() handler.Funcs {
5050
}
5151

5252
// Queue an event to start applying changes if the PostgreSQL instance
53-
// now has the "master" role.
53+
// now has the "primary" role.
5454
if len(cluster) != 0 &&
5555
!patroni.PodIsPrimary(e.ObjectOld) &&
5656
patroni.PodIsPrimary(e.ObjectNew) {

internal/patroni/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (exec Executor) ChangePrimaryAndWait(
4545

4646
err := exec(ctx, nil, &stdout, &stderr,
4747
"patronictl", "switchover", "--scheduled=now", "--force",
48-
"--master="+current, "--candidate="+next)
48+
"--primary="+current, "--candidate="+next)
4949

5050
log := logging.FromContext(ctx)
5151
log.V(1).Info("changed primary",
@@ -65,7 +65,7 @@ func (exec Executor) ChangePrimaryAndWait(
6565
// "patronictl". It returns true when an election completes successfully. It
6666
// waits up to two "loop_wait" or until an error occurs. When Patroni is paused,
6767
// next cannot be blank. Similar to the "POST /switchover" REST endpoint.
68-
// The "patronictl switchover" variant does not require the current master to be passed
68+
// The "patronictl switchover" variant does not require the current primary to be passed
6969
// as a flag.
7070
func (exec Executor) SwitchoverAndWait(
7171
ctx context.Context, target string,
@@ -96,7 +96,7 @@ func (exec Executor) SwitchoverAndWait(
9696
// "patronictl". It returns true when an election completes successfully. It
9797
// waits up to two "loop_wait" or until an error occurs. When Patroni is paused,
9898
// next cannot be blank. Similar to the "POST /switchover" REST endpoint.
99-
// The "patronictl failover" variant does not require the current master to be passed
99+
// The "patronictl failover" variant does not require the current primary to be passed
100100
// as a flag.
101101
func (exec Executor) FailoverAndWait(
102102
ctx context.Context, target string,

internal/patroni/api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestExecutorChangePrimaryAndWait(t *testing.T) {
3636
) error {
3737
called = true
3838
assert.DeepEqual(t, command, strings.Fields(
39-
`patronictl switchover --scheduled=now --force --master=old --candidate=new`,
39+
`patronictl switchover --scheduled=now --force --primary=old --candidate=new`,
4040
))
4141
assert.Assert(t, stdin == nil, "expected no stdin, got %T", stdin)
4242
assert.Assert(t, stderr != nil, "should capture stderr")

0 commit comments

Comments
 (0)