@@ -545,45 +545,6 @@ func (c *Cluster) checkAndSetGlobalPostgreSQLConfiguration(pod *v1.Pod, effectiv
545545 configPatched := false
546546 requiresMasterRestart := false
547547
548- for slotName , _ := range effectivePatroniConfig .Slots {
549- if _ , exists := desiredPatroniConfig .Slots [slotName ]; exists {
550- continue
551- }
552-
553- configToRewrite := make (map [string ]interface {})
554- configToRewrite ["loop_wait" ] = effectivePatroniConfig .LoopWait
555- configToRewrite ["maximum_lag_on_failover" ] = effectivePatroniConfig .MaximumLagOnFailover
556- configToRewrite ["pg_hba" ] = effectivePatroniConfig .PgHba
557- configToRewrite ["retry_timeout" ] = effectivePatroniConfig .RetryTimeout
558- configToRewrite ["synchronous_mode" ] = effectivePatroniConfig .SynchronousMode
559- configToRewrite ["synchronous_mode_strict" ] = effectivePatroniConfig .SynchronousModeStrict
560- configToRewrite ["ttl" ] = effectivePatroniConfig .TTL
561- configToRewrite ["postgresql" ] = map [string ]interface {}{constants .PatroniPGParametersParameterName : effectivePgParameters }
562-
563- slotsToRewrite := make (map [string ]map [string ]string )
564- for slotName , desiredSlot := range desiredPatroniConfig .Slots {
565- slotsToRewrite [slotName ] = desiredSlot
566- }
567-
568- if len (slotsToRewrite ) > 0 {
569- configToRewrite ["slots" ] = slotsToRewrite
570- }
571-
572- configToRewriteJson , err := json .Marshal (configToRewrite )
573- if err != nil {
574- c .logger .Debugf ("could not convert config rewrite to JSON: %v" , err )
575- }
576-
577- podName := util .NameFromMeta (pod .ObjectMeta )
578- c .logger .Debugf ("rewrite Postgres config via Patroni API on pod %s with following options: %s" ,
579- podName , configToRewriteJson )
580- if err = c .patroni .RewriteConfig (pod , configToRewrite ); err != nil {
581- return configPatched , requiresMasterRestart , fmt .Errorf ("could not rewrite postgres parameters within pod %s: %v" , podName , err )
582- }
583-
584- break
585- }
586-
587548 // compare effective and desired Patroni config options
588549 if desiredPatroniConfig .LoopWait > 0 && desiredPatroniConfig .LoopWait != effectivePatroniConfig .LoopWait {
589550 configToSet ["loop_wait" ] = desiredPatroniConfig .LoopWait
@@ -607,8 +568,8 @@ func (c *Cluster) checkAndSetGlobalPostgreSQLConfiguration(pod *v1.Pod, effectiv
607568 configToSet ["ttl" ] = desiredPatroniConfig .TTL
608569 }
609570
571+ slotsToSet := make (map [string ]interface {})
610572 // check if specified slots exist in config and if they differ
611- slotsToSet := make (map [string ]map [string ]string )
612573 for slotName , desiredSlot := range desiredPatroniConfig .Slots {
613574 if effectiveSlot , exists := effectivePatroniConfig .Slots [slotName ]; exists {
614575 if reflect .DeepEqual (desiredSlot , effectiveSlot ) {
@@ -617,6 +578,15 @@ func (c *Cluster) checkAndSetGlobalPostgreSQLConfiguration(pod *v1.Pod, effectiv
617578 }
618579 slotsToSet [slotName ] = desiredSlot
619580 }
581+ // check if there is any slot deletion
582+ for slotName , effectiveSlot := range effectivePatroniConfig .Slots {
583+ if desiredSlot , exists := desiredPatroniConfig .Slots [slotName ]; exists {
584+ if reflect .DeepEqual (effectiveSlot , desiredSlot ) {
585+ continue
586+ }
587+ }
588+ slotsToSet [slotName ] = nil
589+ }
620590 if len (slotsToSet ) > 0 {
621591 configToSet ["slots" ] = slotsToSet
622592 }
0 commit comments