Skip to content

Commit 67b44d7

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 91d773c commit 67b44d7

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
@@ -21,8 +21,10 @@ import (
2121

2222
"github.com/crunchydata/postgres-operator/internal/config"
2323
log "github.com/sirupsen/logrus"
24+
v1 "k8s.io/api/core/v1"
2425
kerrors "k8s.io/apimachinery/pkg/api/errors"
2526
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
"k8s.io/apimachinery/pkg/fields"
2628
"k8s.io/apimachinery/pkg/util/wait"
2729
)
2830

@@ -113,17 +115,20 @@ func (b BackRestBackupJob) Run() {
113115
return
114116
}
115117

116-
selector := fmt.Sprintf("%s=%s,pgo-backrest-repo=true", config.LABEL_PG_CLUSTER, b.cluster)
117-
pods, err := clientset.CoreV1().Pods(b.namespace).List(metav1.ListOptions{LabelSelector: selector})
118+
selector := fmt.Sprintf("%s=%s,%s", config.LABEL_PG_CLUSTER, b.cluster, config.LABEL_PGO_BACKREST_REPO)
119+
options := metav1.ListOptions{
120+
FieldSelector: fields.OneTermEqualSelector("status.phase", string(v1.PodRunning)).String(),
121+
LabelSelector: selector,
122+
}
123+
124+
pods, err := clientset.CoreV1().Pods(b.namespace).List(options)
118125
if err != nil {
119126
contextLogger.WithFields(log.Fields{
120127
"selector": selector,
121128
"error": err,
122129
}).Error("error getting pods from selector")
123130
return
124-
}
125-
126-
if len(pods.Items) != 1 {
131+
} else if len(pods.Items) != 1 {
127132
contextLogger.WithFields(log.Fields{
128133
"selector": selector,
129134
"error": err,

0 commit comments

Comments
 (0)