Skip to content

Commit cacb4fa

Browse files
committed
Prevent Panic if PG Deployments Scaled Down
If the primary and all replica Deployments are scaled to zero outside of the context of the PostgreSQL Operator (e.g. by using 'kubectl scale deployment --replicas=0' instead of 'pgo update cluster --shutdown') and the associated pgcluster for the Deployment(s) being scaled is not manually set to the proper "shutdown" status, then the PostgreSQL Operator could panic as it continues to attempt to synchronize Patroni/PostgreSQL configuration for the PG cluster (specifically because no pods are found for the cluster). This commit protects against a panic in this scenario by simply logging an error when no Pods are found during an attempt to sync configuration. Issue: [ch9278]
1 parent 233c9dc commit cacb4fa

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

internal/operator/config/localdb.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ func (l *LocalDB) Update(configName string, localDBConfig LocalDBConfig) error {
217217
return nil
218218
}
219219

220-
// apply applies the configuration stored in the CusterConig's configMap for a
221-
// specific database server to that server. This is done by updating the contents of that
222-
// database server's local configuration with the configuration for that cluster stored in
223-
// the LocalDB's configMap, and the issuing a Patroni "reload" for that specific server.
220+
// apply applies the configuration stored in the cluster ConfigMap for a specific database server
221+
// to that server. This is done by updating the contents of that database server's local
222+
// configuration with the configuration for that cluster stored in the LocalDB's configMap, and
223+
// then issuing a Patroni "reload" for that specific server.
224224
func (l *LocalDB) apply(configName string) error {
225225

226226
clusterName := l.configMap.GetObjectMeta().GetLabels()[config.LABEL_PG_CLUSTER]
@@ -243,6 +243,11 @@ func (l *LocalDB) apply(configName string) error {
243243
if err != nil {
244244
return err
245245
}
246+
// if the pod list is empty, also return an error
247+
if len(dbPodList.Items) == 0 {
248+
return fmt.Errorf("no pod found for %q", clusterName)
249+
}
250+
246251
dbPod := &dbPodList.Items[0]
247252

248253
// add the config name and patroni port as params for the call to the apply & reload script

0 commit comments

Comments
 (0)