Skip to content

Commit cf1ff08

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 8f4b8f0 commit cf1ff08

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

operator/config/localdb.go

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

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

221221
clusterName := l.configMap.GetObjectMeta().GetLabels()[config.LABEL_PG_CLUSTER]
@@ -238,6 +238,11 @@ func (l *LocalDB) apply(configName string) error {
238238
if err != nil {
239239
return err
240240
}
241+
// if the pod list is empty, also return an error
242+
if len(dbPodList.Items) == 0 {
243+
return fmt.Errorf("no pod found for %q", clusterName)
244+
}
245+
241246
dbPod := &dbPodList.Items[0]
242247

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

0 commit comments

Comments
 (0)