Skip to content

Poll backup status from the repo-host rather than the instance pod. #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: flyio-2.6.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2173ea8
Poll backup status from the repo-host rather than the instance pod.
gargakshit May 28, 2025
0299116
Build on all branches
gargakshit May 28, 2025
5f44ed0
more hints
jphenow May 28, 2025
b4a5604
tired of this misspelling error
jphenow May 28, 2025
b99aab0
fix linting
jphenow May 28, 2025
258ef88
some possible test fixes
jphenow May 28, 2025
ac250f3
bump jwt for vuln
jphenow May 28, 2025
02982ed
fix manifests check
jphenow May 28, 2025
39d0516
fixes manifests... again
jphenow May 28, 2025
e373794
see if claude can fix it
jphenow May 28, 2025
d915202
claude is bad
jphenow May 28, 2025
6d4f257
fixes generated files that get kustomized
jphenow May 28, 2025
23df737
see if this fixes our segf
jphenow May 28, 2025
b45b7f0
fix pgbackrest dance
jphenow May 28, 2025
a64d31b
fix reconciler test
jphenow May 28, 2025
4c8e46b
committing an abusive fix from claude so I can revert some
jphenow May 28, 2025
4bcf159
fix another more tests and maybe some pgbackrest handling
jphenow May 28, 2025
7cd1e4f
local testing simpler
jphenow May 28, 2025
ce1163a
fix manifests again? wtf?
jphenow May 28, 2025
65ffe4e
maybe fix this last set of failures
jphenow May 29, 2025
773416c
Merge remote-tracking branch 'origin/flyio-2.6.0-sidecars-upstreamabl…
gargakshit May 29, 2025
4f8d025
Exec repo commands in backrest container
gargakshit May 29, 2025
52c28d4
CI hates typos
gargakshit May 29, 2025
c2ef00d
Log execs
gargakshit May 29, 2025
e65c525
Also log the command
gargakshit May 29, 2025
0c81287
Move one more to repo host
gargakshit May 29, 2025
56b8393
Replace another instance with repo-host calls
gargakshit May 30, 2025
ff936c7
Thanks supermaven
gargakshit May 30, 2025
b0ad224
Merge remote-tracking branch 'origin/flyio-2.6.0' into akshit/flyio-2…
jphenow Jun 6, 2025
a9a6f8c
leftover from old branch
jphenow Jun 6, 2025
b549fa4
Use instance pod to finalize backup
gargakshit Jun 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for git describe
fetch-depth: 0 # Needed for git describe

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand Down Expand Up @@ -54,4 +54,4 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-to: type=gha,mode=max
3 changes: 3 additions & 0 deletions internal/naming/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const (
// LabelRepoName is used to specify the name of a pgBackRest repository
LabelRepoName = labelPrefix + "name"

// LabelPgbackrestDedicated is used to select the repo-host pod
LabelPgbackrestDedicated = labelPrefix + "pgbackrest-dedicated"

LabelPatroni = labelPrefix + "patroni"
LabelRole = labelPrefix + "role"

Expand Down
2 changes: 2 additions & 0 deletions internal/naming/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const (

// ContainerPGBackRestConfig is the name of a container supporting pgBackRest.
ContainerPGBackRestConfig = "pgbackrest-config"
// ContainerPGBackRest is the name of a container running pgBackRest.
ContainerPGBackRest = "pgbackrest"

// ContainerPGBouncer is the name of a container running PgBouncer.
ContainerPGBouncer = "pgbouncer"
Expand Down
11 changes: 11 additions & 0 deletions internal/naming/selectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ func ClusterBackupJobs(cluster string) metav1.LabelSelector {
}
}

func ClusterRepoHost(cluster string) metav1.LabelSelector {
return metav1.LabelSelector{
MatchLabels: map[string]string{
LabelCluster: cluster,
},
MatchExpressions: []metav1.LabelSelectorRequirement{
{Key: LabelPgbackrestDedicated, Operator: metav1.LabelSelectorOpExists},
},
}
}

// ClusterDataForPostgresAndPGBackRest selects things for PostgreSQL data and
// things for pgBackRest data.
func ClusterDataForPostgresAndPGBackRest(cluster string) metav1.LabelSelector {
Expand Down
2 changes: 2 additions & 0 deletions percona/clientcmd/clientcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package clientcmd
import (
"context"
"io"
"log"

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -68,6 +69,7 @@ func (c *Client) Exec(ctx context.Context, pod *corev1.Pod, containerName string
TTY: tty,
}, scheme.ParameterCodec)

log.Println("Execing in pod", pod.Name, containerName, command)
exec, err := remotecommand.NewSPDYExecutor(c.restconfig, "POST", req.URL())
if err != nil {
return errors.Wrap(err, "failed to create executor")
Expand Down
6 changes: 5 additions & 1 deletion percona/controller/pgbackup/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,13 @@ func updatePGBackrestInfo(ctx context.Context, c client.Client, pod *corev1.Pod,

func finishBackup(ctx context.Context, c client.Client, pgBackup *v2.PerconaPGBackup, job *batchv1.Job) (*reconcile.Result, error) {
if checkBackupJob(job) == v2.BackupSucceeded {
// MARK(AG): Pod for running pgbackrest info.
// Read the repo-host pod instead.

// readyPod, err := controller.GetReadyRepoHostPod(ctx, c, pgBackup.Spec.PGCluster, pgBackup.Namespace)
readyPod, err := controller.GetReadyInstancePod(ctx, c, pgBackup.Spec.PGCluster, pgBackup.Namespace)
if err != nil {
return nil, errors.Wrap(err, "get ready instance pod")
return nil, errors.Wrap(err, "get ready repo-host pod")
}

if err := updatePGBackrestInfo(ctx, c, readyPod, pgBackup); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion percona/controller/pgcluster/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r *PGClusterReconciler) cleanupOutdatedBackups(ctx context.Context, cr *v2
continue
}

readyPod, err := controller.GetReadyInstancePod(ctx, r.Client, cr.Name, cr.Namespace)
readyPod, err := controller.GetReadyRepoHostPod(ctx, r.Client, cr.Name, cr.Namespace)
if err != nil {
return errors.Wrap(err, "get ready instance pod")
}
Expand Down
20 changes: 20 additions & 0 deletions percona/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,32 @@ func (m *CustomManager) Add(r manager.Runnable) error {
return nil
}

func GetReadyRepoHostPod(ctx context.Context, c client.Client, clusterName, namespace string) (*corev1.Pod, error) {
pods := &corev1.PodList{}
selector, err := naming.AsSelector(naming.ClusterRepoHost(clusterName))
if err != nil {
return nil, err
}
if err := c.List(ctx, pods, client.InNamespace(namespace), client.MatchingLabelsSelector{Selector: selector}); err != nil {
return nil, errors.Wrap(err, "list pods")
}

for _, pod := range pods.Items {
if pod.Status.Phase != corev1.PodRunning {
continue
}
return &pod, nil
}
return nil, errors.New("no running repo-host found")
}

func GetReadyInstancePod(ctx context.Context, c client.Client, clusterName, namespace string) (*corev1.Pod, error) {
pods := &corev1.PodList{}
selector, err := naming.AsSelector(naming.ClusterInstances(clusterName))
if err != nil {
return nil, err
}
// Mark (AG): Do something similar for repo-host.
if err := c.List(ctx, pods, client.InNamespace(namespace), client.MatchingLabelsSelector{Selector: selector}); err != nil {
return nil, errors.Wrap(err, "list pods")
}
Expand Down
5 changes: 3 additions & 2 deletions percona/pgbackrest/pgbackrest.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func GetInfo(ctx context.Context, pod *corev1.Pod, repoName string) (InfoOutput,
return InfoOutput{}, errors.Wrap(err, "failed to create client")
}

if err := c.Exec(ctx, pod, naming.ContainerDatabase, nil, stdout, stderr, "pgbackrest", "info", "--output=json", "--repo="+strings.TrimPrefix(repoName, "repo")); err != nil {
// naming.PGBackRestRepoContainerName
if err := c.Exec(ctx, pod, naming.ContainerPGBackRest, nil, stdout, stderr, "pgbackrest", "info", "--output=json", "--repo="+strings.TrimPrefix(repoName, "repo")); err != nil {
return InfoOutput{}, errors.Wrapf(err, "exec: %s", stderr.String())
}

Expand Down Expand Up @@ -98,7 +99,7 @@ func SetAnnotationsToBackup(ctx context.Context, pod *corev1.Pod, stanza string,
cmd = append(cmd, annotationsOpts...)
cmd = append(cmd, "annotate")

if err := c.Exec(ctx, pod, naming.ContainerDatabase, nil, nil, stderr, cmd...); err != nil {
if err := c.Exec(ctx, pod, naming.ContainerPGBackRest, nil, nil, stderr, cmd...); err != nil {
return errors.Wrapf(err, "exec: %s", stderr.String())
}

Expand Down
25 changes: 23 additions & 2 deletions percona/postgres/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,37 @@ func GetPrimaryPod(ctx context.Context, cli client.Client, cr *v2.PerconaPGClust
"postgres-operator.crunchydata.com/role": role,
}),
})

if len(podList.Items) == 0 {
return nil, errors.New("no primary pod found")
}

if len(podList.Items) > 1 {
return nil, errors.New("multiple primary pods found")
}

return &podList.Items[0], nil
}

func GetRepoHostPod(ctx context.Context, cli client.Client, cr *v2.PerconaPGCluster) (*corev1.Pod, error) {
podList := &corev1.PodList{}
err := cli.List(ctx, podList, &client.ListOptions{
Namespace: cr.Namespace,
LabelSelector: labels.SelectorFromSet(map[string]string{
"app.kubernetes.io/instance": cr.Name,
"postgres-operator.crunchydata.com/pgbackrest-dedicated": "",
}),
})
if err != nil {
return nil, err
}

if len(podList.Items) == 0 {
return nil, errors.New("no primary pod found")
return nil, errors.New("no repo-host pod found")
}

if len(podList.Items) > 1 {
return nil, errors.New("multiple primary pods found")
return nil, errors.New("multiple repo-host pods found")
}

return &podList.Items[0], nil
Expand Down
4 changes: 3 additions & 1 deletion percona/watcher/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ func GetLatestCommitTimestamp(ctx context.Context, cli client.Client, execCli *c
}

func getBackupStartTimestamp(ctx context.Context, cli client.Client, cr *pgv2.PerconaPGCluster, backup *pgv2.PerconaPGBackup) (time.Time, error) {
primary, err := perconaPG.GetPrimaryPod(ctx, cli, cr)
// MARK(AG): This might break.
primary, err := perconaPG.GetRepoHostPod(ctx, cli, cr)
if err != nil {
return time.Time{}, PrimaryPodNotFound
}

// MARK(AG): More pgbackest stuff
pgbackrestInfo, err := pgbackrest.GetInfo(ctx, primary, backup.Spec.RepoName)
if err != nil {
return time.Time{}, errors.Wrap(err, "get pgbackrest info")
Expand Down
Loading