diff --git a/pkg/cluster/sync.go b/pkg/cluster/sync.go index 1c3f73b7f..908806dda 100644 --- a/pkg/cluster/sync.go +++ b/pkg/cluster/sync.go @@ -1033,12 +1033,20 @@ func (c *Cluster) syncStandbyClusterConfiguration() error { if c.Spec.StandbyCluster.StandbyHost != "" { standbyOptionsToSet["host"] = c.Spec.StandbyCluster.StandbyHost - if c.Spec.StandbyCluster.StandbyPort != "" { - standbyOptionsToSet["port"] = c.Spec.StandbyCluster.StandbyPort - } - if c.Spec.StandbyCluster.StandbyPrimarySlotName != "" { - standbyOptionsToSet["primary_slot_name"] = c.Spec.StandbyCluster.StandbyPrimarySlotName - } + } else { + standbyOptionsToSet["host"] = nil + } + + if c.Spec.StandbyCluster.StandbyPort != "" { + standbyOptionsToSet["port"] = c.Spec.StandbyCluster.StandbyPort + } else { + standbyOptionsToSet["port"] = nil + } + + if c.Spec.StandbyCluster.StandbyPrimarySlotName != "" { + standbyOptionsToSet["primary_slot_name"] = c.Spec.StandbyCluster.StandbyPrimarySlotName + } else { + standbyOptionsToSet["primary_slot_name"] = nil } } else { c.logger.Infof("promoting standby cluster and detach from source") diff --git a/pkg/cluster/sync_test.go b/pkg/cluster/sync_test.go index 9e2c026e9..e2b242d9d 100644 --- a/pkg/cluster/sync_test.go +++ b/pkg/cluster/sync_test.go @@ -819,6 +819,23 @@ func TestSyncStandbyClusterConfiguration(t *testing.T) { // this should update the Patroni config with host, port and primary_slot_name err = cluster.syncStandbyClusterConfiguration() assert.NoError(t, err) + + // test property deletion: remove standby_primary_slot_name + cluster.Spec.StandbyCluster = &acidv1.StandbyDescription{ + StandbyHost: "remote-primary.example.com", + StandbyPort: "5433", + } + cluster.syncStatefulSet() + updatedSts5 := cluster.Statefulset + + // check that STANDBY_PRIMARY_SLOT_NAME is not present + assert.Contains(t, updatedSts5.Spec.Template.Spec.Containers[0].Env, v1.EnvVar{Name: "STANDBY_HOST", Value: "remote-primary.example.com"}) + assert.Contains(t, updatedSts5.Spec.Template.Spec.Containers[0].Env, v1.EnvVar{Name: "STANDBY_PORT", Value: "5433"}) + assert.NotContains(t, updatedSts5.Spec.Template.Spec.Containers[0].Env, v1.EnvVar{Name: "STANDBY_PRIMARY_SLOT_NAME", Value: "standby_slot"}) + + // this should update the Patroni config and set primary_slot_name to nil + err = cluster.syncStandbyClusterConfiguration() + assert.NoError(t, err) } func TestUpdateSecret(t *testing.T) {