Skip to content

Commit bee1ef5

Browse files
jkatzJonathan S. Katz
authored andcommitted
Update logic for pgbouncer password modification on creation
If the AddPgBouncer call is invoked as the Operator attempts to add a new pgBouncer and it is determined that a pgBouncer Secret already exists, do not attempt to update the password within PostgreSQL. This also ensures that an existing Secret storing the pgbouncer user credential is synchronized to be the password represented for the pgbouncer user in the database itself. Issue: [ch9457]
1 parent 0df9094 commit bee1ef5

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

operator/cluster/pgbouncer.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,30 @@ func AddPgbouncer(clientset *kubernetes.Clientset, restclient *rest.RESTClient,
154154
}
155155
}
156156

157-
// set the password that will be used for the "pgbouncer" PostgreSQL account
158-
pgBouncerPassword, err := generatePassword()
159-
160-
if err != nil {
161-
return err
162-
}
163-
164157
// only attempt to set the password if the cluster is not in standby mode
158+
// and the secret does not already exist. If GetPasswordFromSecret returns
159+
// no errors, then we can assume that the Secret does not exist
165160
if !cluster.Spec.Standby {
161+
secretName := util.GeneratePgBouncerSecretName(cluster.Name)
162+
pgBouncerPassword, err := util.GetPasswordFromSecret(clientset, cluster.Namespace, secretName)
163+
164+
if err != nil {
165+
// set the password that will be used for the "pgbouncer" PostgreSQL account
166+
newPassword, err := generatePassword()
167+
168+
if err != nil {
169+
return err
170+
}
171+
172+
pgBouncerPassword = newPassword
173+
174+
// create the secret that pgbouncer will include the pgBouncer
175+
// credentials
176+
if err := createPgbouncerSecret(clientset, cluster, pgBouncerPassword); err != nil {
177+
return err
178+
}
179+
}
180+
166181
// attempt to update the password in PostgreSQL, as this is how pgBouncer
167182
// will properly interface with PostgreSQL
168183
if err := setPostgreSQLPassword(clientset, restconfig, pod, cluster.Spec.Port, pgBouncerPassword); err != nil {
@@ -218,7 +233,8 @@ func DeletePgbouncer(clientset *kubernetes.Clientset, restclient *rest.RESTClien
218233
}
219234

220235
// next, delete the various Kubernetes objects associated with the pgbouncer
221-
// these include the Service, Deployment, and the pgBouncer secret
236+
// these include the Service, Deployment, Secret and ConfigMap associated with
237+
// pgbouncer
222238
// If these fail, we'll just pass through
223239
//
224240
// First, delete the Service and Deployment, which share the same naem

0 commit comments

Comments
 (0)