Skip to content

Commit d58761d

Browse files
author
Xun Jiang
committed
Change controller-runtime List option from MatchingFields to ListOptions.
Signed-off-by: Xun Jiang <[email protected]>
1 parent ed441de commit d58761d

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Change controller-runtime List option from MatchingFields to ListOptions

pkg/cmd/cli/nodeagent/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func (s *nodeAgentServer) markDataDownloadsCancel(r *controller.DataDownloadReco
419419

420420
func (s *nodeAgentServer) markInProgressPVBsFailed(client ctrlclient.Client) {
421421
pvbs := &velerov1api.PodVolumeBackupList{}
422-
if err := client.List(s.ctx, pvbs, &ctrlclient.MatchingFields{"metadata.namespace": s.namespace}); err != nil {
422+
if err := client.List(s.ctx, pvbs, &ctrlclient.ListOptions{Namespace: s.namespace}); err != nil {
423423
s.logger.WithError(errors.WithStack(err)).Error("failed to list podvolumebackups")
424424
return
425425
}
@@ -445,7 +445,7 @@ func (s *nodeAgentServer) markInProgressPVBsFailed(client ctrlclient.Client) {
445445

446446
func (s *nodeAgentServer) markInProgressPVRsFailed(client ctrlclient.Client) {
447447
pvrs := &velerov1api.PodVolumeRestoreList{}
448-
if err := client.List(s.ctx, pvrs, &ctrlclient.MatchingFields{"metadata.namespace": s.namespace}); err != nil {
448+
if err := client.List(s.ctx, pvrs, &ctrlclient.ListOptions{Namespace: s.namespace}); err != nil {
449449
s.logger.WithError(errors.WithStack(err)).Error("failed to list podvolumerestores")
450450
return
451451
}

pkg/cmd/server/server.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
corev1api "k8s.io/api/core/v1"
4040
apierrors "k8s.io/apimachinery/pkg/api/errors"
4141
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
42+
"k8s.io/apimachinery/pkg/labels"
4243
"k8s.io/apimachinery/pkg/runtime"
4344
"k8s.io/apimachinery/pkg/types"
4445
kubeerrs "k8s.io/apimachinery/pkg/util/errors"
@@ -1056,7 +1057,7 @@ func markInProgressCRsFailed(ctx context.Context, cfg *rest.Config, scheme *runt
10561057

10571058
func markInProgressBackupsFailed(ctx context.Context, client ctrlclient.Client, namespace string, log logrus.FieldLogger) {
10581059
backups := &velerov1api.BackupList{}
1059-
if err := client.List(ctx, backups, &ctrlclient.MatchingFields{"metadata.namespace": namespace}); err != nil {
1060+
if err := client.List(ctx, backups, &ctrlclient.ListOptions{Namespace: namespace}); err != nil {
10601061
log.WithError(errors.WithStack(err)).Error("failed to list backups")
10611062
return
10621063
}
@@ -1081,7 +1082,7 @@ func markInProgressBackupsFailed(ctx context.Context, client ctrlclient.Client,
10811082

10821083
func markInProgressRestoresFailed(ctx context.Context, client ctrlclient.Client, namespace string, log logrus.FieldLogger) {
10831084
restores := &velerov1api.RestoreList{}
1084-
if err := client.List(ctx, restores, &ctrlclient.MatchingFields{"metadata.namespace": namespace}); err != nil {
1085+
if err := client.List(ctx, restores, &ctrlclient.ListOptions{Namespace: namespace}); err != nil {
10851086
log.WithError(errors.WithStack(err)).Error("failed to list restores")
10861087
return
10871088
}
@@ -1106,7 +1107,12 @@ func markInProgressRestoresFailed(ctx context.Context, client ctrlclient.Client,
11061107
func markDataUploadsCancel(ctx context.Context, client ctrlclient.Client, backup velerov1api.Backup, log logrus.FieldLogger) {
11071108
dataUploads := &velerov2alpha1api.DataUploadList{}
11081109

1109-
if err := client.List(ctx, dataUploads, &ctrlclient.MatchingFields{"metadata.namespace": backup.GetNamespace()}, &ctrlclient.MatchingLabels{velerov1api.BackupUIDLabel: string(backup.GetUID())}); err != nil {
1110+
if err := client.List(ctx, dataUploads, &ctrlclient.ListOptions{
1111+
Namespace: backup.GetNamespace(),
1112+
LabelSelector: labels.Set(map[string]string{
1113+
velerov1api.BackupUIDLabel: string(backup.GetUID()),
1114+
}).AsSelector(),
1115+
}); err != nil {
11101116
log.WithError(errors.WithStack(err)).Error("failed to list dataUploads")
11111117
return
11121118
}
@@ -1134,7 +1140,12 @@ func markDataUploadsCancel(ctx context.Context, client ctrlclient.Client, backup
11341140
func markDataDownloadsCancel(ctx context.Context, client ctrlclient.Client, restore velerov1api.Restore, log logrus.FieldLogger) {
11351141
dataDownloads := &velerov2alpha1api.DataDownloadList{}
11361142

1137-
if err := client.List(ctx, dataDownloads, &ctrlclient.MatchingFields{"metadata.namespace": restore.GetNamespace()}, &ctrlclient.MatchingLabels{velerov1api.RestoreUIDLabel: string(restore.GetUID())}); err != nil {
1143+
if err := client.List(ctx, dataDownloads, &ctrlclient.ListOptions{
1144+
Namespace: restore.GetNamespace(),
1145+
LabelSelector: labels.Set(map[string]string{
1146+
velerov1api.RestoreUIDLabel: string(restore.GetUID()),
1147+
}).AsSelector(),
1148+
}); err != nil {
11381149
log.WithError(errors.WithStack(err)).Error("failed to list dataDownloads")
11391150
return
11401151
}

0 commit comments

Comments
 (0)