Skip to content

Commit 3dcd007

Browse files
committed
reflect feedback
1 parent 6149711 commit 3dcd007

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"
@@ -497,14 +506,22 @@ def compare_config():
497506
self.eventuallyEqual(lambda: self.query_database(replica.metadata.name, "postgres", setting_query)[0], lower_max_connections_value,
498507
"Previous max_connections setting not applied on replica", 10, 5)
499508

500-
# delete test_slot_2 from config
509+
# patch new slot via Patroni REST
510+
patroni_slot = "test_patroni_slot"
511+
patch_slot_command = """curl -s -XPATCH -d '{"slots": {"test_patroni_slot": {"type": "physical"}}}' http://localhost:8008/config"""
512+
k8s.exec_with_kubectl(replica.metadata.name, patch_slot_command)
513+
514+
# delete test_slot_2 from config and change the plugin type for test_slot
501515
slot_to_remove = "test_slot_2"
516+
slot_to_change = "test_slot"
502517
pg_patch_slots = {
503518
"spec": {
504519
"patroni": {
505520
"slots": {
506521
"test_slot": {
507-
"type": "physical"
522+
"type": "logical",
523+
"database": "foo",
524+
"plugin": "wal2json"
508525
}
509526
}
510527
}
@@ -523,7 +540,26 @@ def compare_config():
523540
""" % (slot_to_remove)
524541

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

528564
except timeout_decorator.TimeoutError:
529565
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
@@ -373,10 +373,8 @@ func (c *Cluster) Create() error {
373373
}
374374
}
375375

376-
if len(c.Spec.Patroni.Slots) > 0 {
377-
for slotName, desiredSlot := range c.Spec.Patroni.Slots {
378-
c.replicationSlots[slotName] = desiredSlot
379-
}
376+
for slotName, desiredSlot := range c.Spec.Patroni.Slots {
377+
c.replicationSlots[slotName] = desiredSlot
380378
}
381379

382380
return nil

pkg/cluster/sync_test.go

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

147154
ctrl := gomock.NewController(t)
148155
defer ctrl.Finish()
@@ -206,6 +213,7 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) {
206213
tests := []struct {
207214
subtest string
208215
patroni acidv1.Patroni
216+
slots map[string]map[string]string
209217
pgParams map[string]string
210218
restartPrimary bool
211219
}{
@@ -253,9 +261,62 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) {
253261
},
254262
restartPrimary: true,
255263
},
264+
{
265+
subtest: "slot does not exist but is desired",
266+
patroni: acidv1.Patroni{
267+
TTL: 20,
268+
},
269+
slots: testSlots,
270+
pgParams: map[string]string{
271+
"log_min_duration_statement": "200",
272+
"max_connections": "50",
273+
},
274+
restartPrimary: false,
275+
},
276+
{
277+
subtest: "slot exist, nothing specified in manifest",
278+
patroni: acidv1.Patroni{
279+
TTL: 20,
280+
Slots: map[string]map[string]string{
281+
"slot1": {
282+
"type": "logical",
283+
"plugin": "pgoutput",
284+
"database": "foo",
285+
},
286+
},
287+
},
288+
pgParams: map[string]string{
289+
"log_min_duration_statement": "200",
290+
"max_connections": "50",
291+
},
292+
restartPrimary: false,
293+
},
294+
{
295+
subtest: "slot plugin differs",
296+
patroni: acidv1.Patroni{
297+
TTL: 20,
298+
Slots: map[string]map[string]string{
299+
"slot1": {
300+
"type": "logical",
301+
"plugin": "pgoutput",
302+
"database": "foo",
303+
},
304+
},
305+
},
306+
slots: testSlots,
307+
pgParams: map[string]string{
308+
"log_min_duration_statement": "200",
309+
"max_connections": "50",
310+
},
311+
restartPrimary: false,
312+
},
256313
}
257314

258315
for _, tt := range tests {
316+
if tt.slots != nil {
317+
cluster.Spec.Patroni.Slots = tt.slots
318+
}
319+
259320
configPatched, requirePrimaryRestart, err := cluster.checkAndSetGlobalPostgreSQLConfiguration(mockPod, tt.patroni, cluster.Spec.Patroni, tt.pgParams, cluster.Spec.Parameters)
260321
assert.NoError(t, err)
261322
if configPatched != true {

0 commit comments

Comments
 (0)