Skip to content

Commit c8eda9f

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. Issue: PGO-1646
1 parent 5fae3e9 commit c8eda9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+96
-97
lines changed

internal/controller/postgrescluster/instance.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (i Instance) IsWritable() (writable, known bool) {
133133

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

136-
return strings.HasPrefix(member[role:], `"role":"master"`), true
136+
return strings.HasPrefix(member[role:], `"role":"primary"`), true
137137
}
138138

139139
// PodMatchesPodTemplate returns whether or not the Pod for this instance
@@ -1018,14 +1018,14 @@ func podsToKeep(instances []corev1.Pod, want map[string]int) []corev1.Pod {
10181018

10191019
if want > 0 {
10201020
for _, instance := range instances {
1021-
if instance.Labels[naming.LabelRole] == "master" {
1021+
if instance.Labels[naming.LabelRole] == "primary" {
10221022
keep = append(keep, instance)
10231023
}
10241024
}
10251025
}
10261026

10271027
for _, instance := range instances {
1028-
if instance.Labels[naming.LabelRole] != "master" && len(keep) < want {
1028+
if instance.Labels[naming.LabelRole] != "primary" && len(keep) < want {
10291029
keep = append(keep, instance)
10301030
}
10311031
}

internal/controller/postgrescluster/instance_rollout_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestReconcilerRolloutInstance(t *testing.T) {
4242
Name: "one-pod-bruh",
4343
Labels: map[string]string{
4444
"controller-revision-hash": "gamma",
45-
"postgres-operator.crunchydata.com/role": "master",
45+
"postgres-operator.crunchydata.com/role": "primary",
4646
},
4747
},
4848
Status: corev1.PodStatus{
@@ -104,7 +104,7 @@ func TestReconcilerRolloutInstance(t *testing.T) {
104104
Name: "the-pod",
105105
Labels: map[string]string{
106106
"controller-revision-hash": "gamma",
107-
"postgres-operator.crunchydata.com/role": "master",
107+
"postgres-operator.crunchydata.com/role": "primary",
108108
},
109109
},
110110
}},
@@ -134,7 +134,7 @@ func TestReconcilerRolloutInstance(t *testing.T) {
134134

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

140140
// Indicate success through stdout.
@@ -214,7 +214,7 @@ func TestReconcilerRolloutInstances(t *testing.T) {
214214
ObjectMeta: metav1.ObjectMeta{
215215
Labels: map[string]string{
216216
"controller-revision-hash": "gamma",
217-
"postgres-operator.crunchydata.com/role": "master",
217+
"postgres-operator.crunchydata.com/role": "primary",
218218
},
219219
},
220220
Status: corev1.PodStatus{
@@ -259,7 +259,7 @@ func TestReconcilerRolloutInstances(t *testing.T) {
259259
ObjectMeta: metav1.ObjectMeta{
260260
Labels: map[string]string{
261261
"controller-revision-hash": "beta",
262-
"postgres-operator.crunchydata.com/role": "master",
262+
"postgres-operator.crunchydata.com/role": "primary",
263263
},
264264
},
265265
Status: corev1.PodStatus{
@@ -374,7 +374,7 @@ func TestReconcilerRolloutInstances(t *testing.T) {
374374
ObjectMeta: metav1.ObjectMeta{
375375
Labels: map[string]string{
376376
"controller-revision-hash": "beta",
377-
"postgres-operator.crunchydata.com/role": "master",
377+
"postgres-operator.crunchydata.com/role": "primary",
378378
},
379379
},
380380
Status: corev1.PodStatus{

internal/controller/postgrescluster/instance_test.go

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

120120
// Patroni leader
121-
instance.Pods[0].Annotations["status"] = `{"role":"master"}`
121+
instance.Pods[0].Annotations["status"] = `{"role":"primary"}`
122122
writable, known = instance.IsWritable()
123123
assert.Assert(t, known)
124124
assert.Assert(t, writable)
@@ -393,7 +393,7 @@ func TestWritablePod(t *testing.T) {
393393
Namespace: "namespace",
394394
Name: "pod",
395395
Annotations: map[string]string{
396-
"status": `{"role":"master"}`,
396+
"status": `{"role":"primary"}`,
397397
},
398398
DeletionTimestamp: &metav1.Time{},
399399
},
@@ -427,7 +427,7 @@ func TestWritablePod(t *testing.T) {
427427
Namespace: "namespace",
428428
Name: "pod",
429429
Annotations: map[string]string{
430-
"status": `{"role":"master"}`,
430+
"status": `{"role":"primary"}`,
431431
},
432432
},
433433
Status: corev1.PodStatus{
@@ -492,7 +492,7 @@ func TestWritablePod(t *testing.T) {
492492
Namespace: "namespace",
493493
Name: "pod",
494494
Annotations: map[string]string{
495-
"status": `{"role":"master"}`,
495+
"status": `{"role":"primary"}`,
496496
},
497497
},
498498
Status: corev1.PodStatus{
@@ -965,13 +965,13 @@ func TestPodsToKeep(t *testing.T) {
965965
checks func(*testing.T, []corev1.Pod)
966966
}{
967967
{
968-
name: "RemoveSetWithMasterOnly",
968+
name: "RemoveSetWithPrimaryOnly",
969969
instances: []corev1.Pod{
970970
{
971971
ObjectMeta: metav1.ObjectMeta{
972972
Name: "daisy-asdf",
973973
Labels: map[string]string{
974-
naming.LabelRole: "master",
974+
naming.LabelRole: "primary",
975975
naming.LabelInstanceSet: "daisy",
976976
},
977977
},
@@ -999,13 +999,13 @@ func TestPodsToKeep(t *testing.T) {
999999
assert.Equal(t, len(p), 0)
10001000
},
10011001
}, {
1002-
name: "KeepMasterOnly",
1002+
name: "KeepPrimaryOnly",
10031003
instances: []corev1.Pod{
10041004
{
10051005
ObjectMeta: metav1.ObjectMeta{
10061006
Name: "daisy-asdf",
10071007
Labels: map[string]string{
1008-
naming.LabelRole: "master",
1008+
naming.LabelRole: "primary",
10091009
naming.LabelInstanceSet: "daisy",
10101010
},
10111011
},
@@ -1088,7 +1088,7 @@ func TestPodsToKeep(t *testing.T) {
10881088
assert.Equal(t, len(p), 0)
10891089
},
10901090
}, {
1091-
name: "MasterLastInSet",
1091+
name: "PrimaryLastInSet",
10921092
instances: []corev1.Pod{
10931093
{
10941094
ObjectMeta: metav1.ObjectMeta{
@@ -1103,7 +1103,7 @@ func TestPodsToKeep(t *testing.T) {
11031103
ObjectMeta: metav1.ObjectMeta{
11041104
Name: "daisy-poih",
11051105
Labels: map[string]string{
1106-
naming.LabelRole: "master",
1106+
naming.LabelRole: "primary",
11071107
naming.LabelInstanceSet: "daisy",
11081108
},
11091109
},
@@ -1114,10 +1114,10 @@ func TestPodsToKeep(t *testing.T) {
11141114
},
11151115
checks: func(t *testing.T, p []corev1.Pod) {
11161116
assert.Equal(t, len(p), 1)
1117-
assert.Equal(t, p[0].Labels[naming.LabelRole], "master")
1117+
assert.Equal(t, p[0].Labels[naming.LabelRole], "primary")
11181118
},
11191119
}, {
1120-
name: "ScaleDownSetWithMaster",
1120+
name: "ScaleDownSetWithPrimary",
11211121
instances: []corev1.Pod{
11221122
{
11231123
ObjectMeta: metav1.ObjectMeta{
@@ -1132,7 +1132,7 @@ func TestPodsToKeep(t *testing.T) {
11321132
ObjectMeta: metav1.ObjectMeta{
11331133
Name: "daisy-poih",
11341134
Labels: map[string]string{
1135-
naming.LabelRole: "master",
1135+
naming.LabelRole: "primary",
11361136
naming.LabelInstanceSet: "daisy",
11371137
},
11381138
},
@@ -1162,19 +1162,19 @@ func TestPodsToKeep(t *testing.T) {
11621162
},
11631163
checks: func(t *testing.T, p []corev1.Pod) {
11641164
assert.Equal(t, len(p), 2)
1165-
assert.Equal(t, p[0].Labels[naming.LabelRole], "master")
1165+
assert.Equal(t, p[0].Labels[naming.LabelRole], "primary")
11661166
assert.Equal(t, p[0].Labels[naming.LabelInstanceSet], "daisy")
11671167
assert.Equal(t, p[1].Labels[naming.LabelRole], "replica")
11681168
assert.Equal(t, p[1].Labels[naming.LabelInstanceSet], "max")
11691169
},
11701170
}, {
1171-
name: "ScaleDownSetWithoutMaster",
1171+
name: "ScaleDownSetWithoutPrimary",
11721172
instances: []corev1.Pod{
11731173
{
11741174
ObjectMeta: metav1.ObjectMeta{
11751175
Name: "max-asdf",
11761176
Labels: map[string]string{
1177-
naming.LabelRole: "master",
1177+
naming.LabelRole: "primary",
11781178
naming.LabelInstanceSet: "max",
11791179
},
11801180
},
@@ -1213,21 +1213,21 @@ func TestPodsToKeep(t *testing.T) {
12131213
},
12141214
checks: func(t *testing.T, p []corev1.Pod) {
12151215
assert.Equal(t, len(p), 3)
1216-
assert.Equal(t, p[0].Labels[naming.LabelRole], "master")
1216+
assert.Equal(t, p[0].Labels[naming.LabelRole], "primary")
12171217
assert.Equal(t, p[0].Labels[naming.LabelInstanceSet], "max")
12181218
assert.Equal(t, p[1].Labels[naming.LabelInstanceSet], "daisy")
12191219
assert.Equal(t, p[1].Labels[naming.LabelRole], "replica")
12201220
assert.Equal(t, p[2].Labels[naming.LabelInstanceSet], "daisy")
12211221
assert.Equal(t, p[2].Labels[naming.LabelRole], "replica")
12221222
},
12231223
}, {
1224-
name: "ScaleMasterSetToZero",
1224+
name: "ScalePrimarySetToZero",
12251225
instances: []corev1.Pod{
12261226
{
12271227
ObjectMeta: metav1.ObjectMeta{
12281228
Name: "max-asdf",
12291229
Labels: map[string]string{
1230-
naming.LabelRole: "master",
1230+
naming.LabelRole: "primary",
12311231
naming.LabelInstanceSet: "max",
12321232
},
12331233
},
@@ -1263,13 +1263,13 @@ func TestPodsToKeep(t *testing.T) {
12631263
assert.Equal(t, p[1].Labels[naming.LabelInstanceSet], "daisy")
12641264
},
12651265
}, {
1266-
name: "RemoveMasterInstanceSet",
1266+
name: "RemovePrimaryInstanceSet",
12671267
instances: []corev1.Pod{
12681268
{
12691269
ObjectMeta: metav1.ObjectMeta{
12701270
Name: "max-asdf",
12711271
Labels: map[string]string{
1272-
naming.LabelRole: "master",
1272+
naming.LabelRole: "primary",
12731273
naming.LabelInstanceSet: "max",
12741274
},
12751275
},
@@ -1319,7 +1319,7 @@ func TestPodsToKeep(t *testing.T) {
13191319
t.Run(test.name, func(t *testing.T) {
13201320
keep := podsToKeep(test.instances, test.want)
13211321
sort.Slice(keep, func(i, j int) bool {
1322-
return keep[i].Labels[naming.LabelRole] == "master"
1322+
return keep[i].Labels[naming.LabelRole] == "primary"
13231323
})
13241324
test.checks(t, keep)
13251325
})

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
@@ -754,7 +754,7 @@ func TestReconcileStanzaCreate(t *testing.T) {
754754

755755
instances := newObservedInstances(postgresCluster, nil, []corev1.Pod{{
756756
ObjectMeta: metav1.ObjectMeta{
757-
Annotations: map[string]string{"status": `"role":"master"`},
757+
Annotations: map[string]string{"status": `"role":"primary"`},
758758
Labels: map[string]string{
759759
naming.LabelCluster: postgresCluster.GetName(),
760760
naming.LabelInstance: "",
@@ -870,7 +870,7 @@ func TestReconcileReplicaCreateBackup(t *testing.T) {
870870
}
871871
instances := newObservedInstances(postgresCluster, nil, []corev1.Pod{{
872872
ObjectMeta: metav1.ObjectMeta{
873-
Annotations: map[string]string{"status": `"role":"master"`},
873+
Annotations: map[string]string{"status": `"role":"primary"`},
874874
Labels: map[string]string{
875875
naming.LabelCluster: postgresCluster.GetName(),
876876
naming.LabelInstance: "",
@@ -1352,7 +1352,7 @@ func TestReconcileManualBackup(t *testing.T) {
13521352
instances.forCluster[0].Pods[0].Annotations = map[string]string{}
13531353
} else {
13541354
instances.forCluster[0].Pods[0].Annotations = map[string]string{
1355-
"status": `"role":"master"`,
1355+
"status": `"role":"primary"`,
13561356
}
13571357
}
13581358

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/controller/postgrescluster/watches_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestWatchPodsUpdate(t *testing.T) {
6868
Namespace: "some-ns",
6969
Labels: map[string]string{
7070
"postgres-operator.crunchydata.com/cluster": "starfish",
71-
"postgres-operator.crunchydata.com/role": "master",
71+
"postgres-operator.crunchydata.com/role": "primary",
7272
},
7373
},
7474
},

0 commit comments

Comments
 (0)