Skip to content

Added namespace limiters to all client.List() calls in pgbackrest and… #3438

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

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions internal/controller/postgrescluster/pgbackrest.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ func (r *Reconciler) observeRestoreEnv(ctx context.Context,

restoreJobs := &batchv1.JobList{}
if err := r.Client.List(ctx, restoreJobs, &client.ListOptions{
Namespace: cluster.Namespace,
LabelSelector: naming.PGBackRestRestoreJobSelector(cluster.GetName()),
}); err != nil {
return nil, nil, errors.WithStack(err)
Expand Down Expand Up @@ -836,8 +837,9 @@ func (r *Reconciler) observeRestoreEnv(ctx context.Context,
selector := naming.PGBackRestRestoreConfigSelector(cluster.GetName())
restoreConfigMaps := &corev1.ConfigMapList{}
if err := r.Client.List(ctx, restoreConfigMaps, &client.ListOptions{
Namespace: cluster.Namespace,
LabelSelector: selector,
}, client.InNamespace(cluster.Namespace)); err != nil {
}); err != nil {
return nil, nil, errors.WithStack(err)
}
for i := range restoreConfigMaps.Items {
Expand All @@ -847,8 +849,9 @@ func (r *Reconciler) observeRestoreEnv(ctx context.Context,
}
restoreSecrets := &corev1.SecretList{}
if err := r.Client.List(ctx, restoreSecrets, &client.ListOptions{
Namespace: cluster.Namespace,
LabelSelector: selector,
}, client.InNamespace(cluster.Namespace)); err != nil {
}); err != nil {
return nil, nil, errors.WithStack(err)
}
for i := range restoreSecrets.Items {
Expand Down
3 changes: 3 additions & 0 deletions internal/controller/postgrescluster/pgbackrest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,7 @@ func TestReconcileManualBackup(t *testing.T) {

jobs := &batchv1.JobList{}
err := tClient.List(ctx, jobs, &client.ListOptions{
Namespace: postgresCluster.Namespace,
LabelSelector: naming.PGBackRestBackupJobSelector(clusterName,
tc.manual.RepoName, naming.BackupManual),
})
Expand Down Expand Up @@ -1417,6 +1418,7 @@ func TestReconcileManualBackup(t *testing.T) {
// just use a pgbackrest selector to check for the existence of any job since
// we might not have a repo name for tests within a manual backup defined
err := tClient.List(ctx, jobs, &client.ListOptions{
Namespace: postgresCluster.Namespace,
LabelSelector: naming.PGBackRestSelector(clusterName),
})
assert.NilError(t, err)
Expand Down Expand Up @@ -3365,6 +3367,7 @@ func TestPrepareForRestore(t *testing.T) {

restoreJobs := &batchv1.JobList{}
assert.NilError(t, r.Client.List(ctx, restoreJobs, &client.ListOptions{
Namespace: cluster.Namespace,
LabelSelector: naming.PGBackRestRestoreJobSelector(cluster.GetName()),
}))

Expand Down
1 change: 1 addition & 0 deletions internal/controller/postgrescluster/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ func (r *Reconciler) reconcileDirMoveJobs(ctx context.Context,

moveJobs := &batchv1.JobList{}
if err := r.Client.List(ctx, moveJobs, &client.ListOptions{
Namespace: cluster.Namespace,
LabelSelector: naming.DirectoryMoveJobLabels(cluster.Name).AsSelector(),
}); err != nil {
return false, errors.WithStack(err)
Expand Down
1 change: 1 addition & 0 deletions internal/controller/postgrescluster/volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ func TestReconcileMoveDirectories(t *testing.T) {

moveJobs := &batchv1.JobList{}
err = r.Client.List(ctx, moveJobs, &client.ListOptions{
Namespace: cluster.Namespace,
LabelSelector: naming.DirectoryMoveJobLabels(cluster.Name).AsSelector(),
})
assert.NilError(t, err)
Expand Down