Skip to content

Commit 86dfc8c

Browse files
committed
reflect feedback
1 parent 5ae08d7 commit 86dfc8c

File tree

3 files changed

+105
-10
lines changed

3 files changed

+105
-10
lines changed

e2e/tests/test_e2e.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,22 @@ def test_config_update(self):
395395
"spec": {
396396
"postgresql": {
397397
"parameters": {
398-
"max_connections": new_max_connections_value
398+
"max_connections": new_max_connections_value,
399+
"wal_level": "logical"
399400
}
400401
},
401-
"patroni": {
402+
"users": {
403+
"test_user": []
404+
},
405+
"databases": {
406+
"foo": "test_user"
407+
},
408+
"patroni": {
402409
"slots": {
403410
"test_slot": {
404-
"type": "physical"
411+
"type": "logical",
412+
"database": "foo",
413+
"plugin": "pgoutput"
405414
},
406415
"test_slot_2": {
407416
"type": "physical"
@@ -500,14 +509,22 @@ def compare_config():
500509
self.eventuallyEqual(lambda: self.query_database(replica.metadata.name, "postgres", setting_query)[0], lower_max_connections_value,
501510
"Previous max_connections setting not applied on replica", 10, 5)
502511

503-
# delete test_slot_2 from config
512+
# patch new slot via Patroni REST
513+
patroni_slot = "test_patroni_slot"
514+
patch_slot_command = """curl -s -XPATCH -d '{"slots": {"test_patroni_slot": {"type": "physical"}}}' http://localhost:8008/config"""
515+
k8s.exec_with_kubectl(replica.metadata.name, patch_slot_command)
516+
517+
# delete test_slot_2 from config and change the plugin type for test_slot
504518
slot_to_remove = "test_slot_2"
519+
slot_to_change = "test_slot"
505520
pg_patch_slots = {
506521
"spec": {
507522
"patroni": {
508523
"slots": {
509524
"test_slot": {
510-
"type": "physical"
525+
"type": "logical",
526+
"database": "foo",
527+
"plugin": "wal2json"
511528
}
512529
}
513530
}
@@ -526,7 +543,26 @@ def compare_config():
526543
""" % (slot_to_remove)
527544

528545
self.eventuallyEqual(lambda: len(self.query_database(replica.metadata.name, "postgres", deleted_slot_query)), 0,
529-
"The replication slot cannot be deleted", 10, 5)
546+
"The replication slot cannot be deleted", 10, 5)
547+
548+
changed_slot_query = """
549+
SELECT plugin
550+
FROM pg_replication_slots
551+
WHERE slot_name = '%s';
552+
""" % (slot_to_change)
553+
554+
self.eventuallyEqual(lambda: self.query_database(replica.metadata.name, "postgres", changed_slot_query)[0], "wal2json",
555+
"The replication slot cannot be updated", 10, 5)
556+
557+
# make sure slot from Patroni didn't get deleted
558+
patroni_slot_query = """
559+
SELECT slot_name
560+
FROM pg_replication_slots
561+
WHERE slot_name = '%s';
562+
""" % (patroni_slot)
563+
564+
self.eventuallyEqual(lambda: len(self.query_database(replica.metadata.name, "postgres", patroni_slot_query)), 1,
565+
"The replication slot from Patroni gets deleted", 10, 5)
530566

531567
except timeout_decorator.TimeoutError:
532568
print('Operator log: {}'.format(k8s.get_operator_log()))

pkg/cluster/cluster.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,8 @@ func (c *Cluster) Create() error {
377377
}
378378
}
379379

380-
if len(c.Spec.Patroni.Slots) > 0 {
381-
for slotName, desiredSlot := range c.Spec.Patroni.Slots {
382-
c.replicationSlots[slotName] = desiredSlot
383-
}
380+
for slotName, desiredSlot := range c.Spec.Patroni.Slots {
381+
c.replicationSlots[slotName] = desiredSlot
384382
}
385383

386384
return nil

pkg/cluster/sync_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) {
144144
client, _ := newFakeK8sSyncClient()
145145
clusterName := "acid-test-cluster"
146146
namespace := "default"
147+
testSlots := map[string]map[string]string{
148+
"slot1": {
149+
"type": "logical",
150+
"plugin": "wal2json",
151+
"database": "foo",
152+
},
153+
}
147154

148155
ctrl := gomock.NewController(t)
149156
defer ctrl.Finish()
@@ -210,6 +217,7 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) {
210217
tests := []struct {
211218
subtest string
212219
patroni acidv1.Patroni
220+
slots map[string]map[string]string
213221
pgParams map[string]string
214222
restartPrimary bool
215223
}{
@@ -251,9 +259,62 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) {
251259
},
252260
restartPrimary: true,
253261
},
262+
{
263+
subtest: "slot does not exist but is desired",
264+
patroni: acidv1.Patroni{
265+
TTL: 20,
266+
},
267+
slots: testSlots,
268+
pgParams: map[string]string{
269+
"log_min_duration_statement": "200",
270+
"max_connections": "50",
271+
},
272+
restartPrimary: false,
273+
},
274+
{
275+
subtest: "slot exist, nothing specified in manifest",
276+
patroni: acidv1.Patroni{
277+
TTL: 20,
278+
Slots: map[string]map[string]string{
279+
"slot1": {
280+
"type": "logical",
281+
"plugin": "pgoutput",
282+
"database": "foo",
283+
},
284+
},
285+
},
286+
pgParams: map[string]string{
287+
"log_min_duration_statement": "200",
288+
"max_connections": "50",
289+
},
290+
restartPrimary: false,
291+
},
292+
{
293+
subtest: "slot plugin differs",
294+
patroni: acidv1.Patroni{
295+
TTL: 20,
296+
Slots: map[string]map[string]string{
297+
"slot1": {
298+
"type": "logical",
299+
"plugin": "pgoutput",
300+
"database": "foo",
301+
},
302+
},
303+
},
304+
slots: testSlots,
305+
pgParams: map[string]string{
306+
"log_min_duration_statement": "200",
307+
"max_connections": "50",
308+
},
309+
restartPrimary: false,
310+
},
254311
}
255312

256313
for _, tt := range tests {
314+
if tt.slots != nil {
315+
cluster.Spec.Patroni.Slots = tt.slots
316+
}
317+
257318
configPatched, requirePrimaryRestart, err := cluster.checkAndSetGlobalPostgreSQLConfiguration(mockPod, tt.patroni, cluster.Spec.Patroni, tt.pgParams, cluster.Spec.Parameters)
258319
assert.NoError(t, err)
259320
if configPatched != true {

0 commit comments

Comments
 (0)