From 97217e27ed73aec0fe8ac74ed30ac96456d113d7 Mon Sep 17 00:00:00 2001 From: Dmitrii Dolgov <9erthalion6@gmail.com> Date: Mon, 17 Feb 2020 15:34:10 +0100 Subject: [PATCH] Delete if a new specification is nil Use coalesce for username too. --- pkg/cluster/cluster.go | 7 +++---- pkg/cluster/sync.go | 8 ++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 4f2fe4efb..1328646ac 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -868,10 +868,9 @@ func (c *Cluster) initSystemUsers() { c.Spec.ConnectionPool = &acidv1.ConnectionPool{} } - username := c.Spec.ConnectionPool.User - if username == "" { - username = c.OpConfig.ConnectionPool.User - } + username := util.Coalesce( + c.Spec.ConnectionPool.User, + c.OpConfig.ConnectionPool.User) c.systemUsers[constants.ConnectionPoolUserKeyName] = spec.PgUser{ Origin: spec.RoleConnectionPool, diff --git a/pkg/cluster/sync.go b/pkg/cluster/sync.go index 47c8c01d6..bd4a7fc28 100644 --- a/pkg/cluster/sync.go +++ b/pkg/cluster/sync.go @@ -115,6 +115,14 @@ func (c *Cluster) Sync(newSpec *acidv1.Postgresql) error { oldPool := oldSpec.Spec.ConnectionPool newPool := newSpec.Spec.ConnectionPool + if newPool == nil { + // previously specified connectionPool was removed, so delete + // connection pool + if err := c.deleteConnectionPool(); err != nil { + c.logger.Warningf("could not remove connection pool: %v", err) + } + } + // do sync in case if any resources were not remembered (it means they // probably were not created, or if specification differs if c.ConnectionPool == nil ||