Skip to content

Commit c780536

Browse files
jkatzJonathan S. Katz
authored andcommitted
Only consider running Pods for scheduled backups
Though the scheduled backup code would bail if it found multiple pgBackRest repository Pods, this ensures that only running pgBackRest Pods would be considered. Issue: #2237
1 parent 992b1d8 commit c780536

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pgo-scheduler/scheduler/pgbackrest.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ import (
2323
"github.com/crunchydata/postgres-operator/internal/kubeapi"
2424
crv1 "github.com/crunchydata/postgres-operator/pkg/apis/crunchydata.com/v1"
2525
log "github.com/sirupsen/logrus"
26+
v1 "k8s.io/api/core/v1"
2627
kerrors "k8s.io/apimachinery/pkg/api/errors"
2728
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
"k8s.io/apimachinery/pkg/fields"
2830
"k8s.io/apimachinery/pkg/util/wait"
2931
)
3032

@@ -134,17 +136,20 @@ func (b BackRestBackupJob) Run() {
134136
return
135137
}
136138

137-
selector := fmt.Sprintf("%s=%s,pgo-backrest-repo=true", config.LABEL_PG_CLUSTER, b.cluster)
138-
pods, err := kubeClient.CoreV1().Pods(b.namespace).List(metav1.ListOptions{LabelSelector: selector})
139+
selector := fmt.Sprintf("%s=%s,%s", config.LABEL_PG_CLUSTER, b.cluster, config.LABEL_PGO_BACKREST_REPO)
140+
options := metav1.ListOptions{
141+
FieldSelector: fields.OneTermEqualSelector("status.phase", string(v1.PodRunning)).String(),
142+
LabelSelector: selector,
143+
}
144+
145+
pods, err := kubeClient.CoreV1().Pods(b.namespace).List(options)
139146
if err != nil {
140147
contextLogger.WithFields(log.Fields{
141148
"selector": selector,
142149
"error": err,
143150
}).Error("error getting pods from selector")
144151
return
145-
}
146-
147-
if len(pods.Items) != 1 {
152+
} else if len(pods.Items) != 1 {
148153
contextLogger.WithFields(log.Fields{
149154
"selector": selector,
150155
"error": err,

0 commit comments

Comments
 (0)