mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-07-28 11:02:43 +00:00
Bump up the versions of severel Kubernetes-related libs
Bump up the versions of severel Kubernetes-related libs Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com>
This commit is contained in:
@@ -24,7 +24,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
@@ -101,7 +101,7 @@ func (r *backupDeletionReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
s := kube.NewPeriodicalEnqueueSource(r.logger, mgr.GetClient(), &velerov1api.DeleteBackupRequestList{}, time.Hour, kube.PeriodicalEnqueueSourceOption{})
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
For(&velerov1api.DeleteBackupRequest{}).
|
||||
Watches(s, nil).
|
||||
WatchesRawSource(s, nil).
|
||||
Complete(r)
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ func (r *backupDeletionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
|
||||
// Wait for the deletion of restores within certain amount of time.
|
||||
// Notice that there could be potential errors during the finalization process, which may result in the failure to delete the restore.
|
||||
// Therefore, it is advisable to set a timeout period for waiting.
|
||||
err := wait.PollImmediate(time.Second, time.Minute, func() (bool, error) {
|
||||
err := wait.PollUntilContextTimeout(ctx, time.Second, time.Minute, true, func(ctx context.Context) (bool, error) {
|
||||
restoreList := &velerov1api.RestoreList{}
|
||||
if err := r.List(ctx, restoreList, &client.ListOptions{Namespace: backup.Namespace, LabelSelector: selector}); err != nil {
|
||||
return false, err
|
||||
|
||||
@@ -92,7 +92,7 @@ func (c *backupOperationsReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
})
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
For(&velerov1api.Backup{}, builder.WithPredicates(kube.FalsePredicate{})).
|
||||
Watches(s, nil, builder.WithPredicates(gp)).
|
||||
WatchesRawSource(s, nil, builder.WithPredicates(gp)).
|
||||
Complete(c)
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/builder"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
"sigs.k8s.io/controller-runtime/pkg/source"
|
||||
|
||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||
"github.com/vmware-tanzu/velero/pkg/label"
|
||||
@@ -74,8 +73,8 @@ func (r *BackupRepoReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
For(&velerov1api.BackupRepository{}).
|
||||
Watches(s, nil).
|
||||
Watches(&source.Kind{Type: &velerov1api.BackupStorageLocation{}}, kube.EnqueueRequestsFromMapUpdateFunc(r.invalidateBackupReposForBSL),
|
||||
WatchesRawSource(s, nil).
|
||||
Watches(&velerov1api.BackupStorageLocation{}, kube.EnqueueRequestsFromMapUpdateFunc(r.invalidateBackupReposForBSL),
|
||||
builder.WithPredicates(
|
||||
// When BSL updates, check if the backup repositories need to be invalidated
|
||||
kube.NewUpdateEventPredicate(r.needInvalidBackupRepo),
|
||||
@@ -84,7 +83,7 @@ func (r *BackupRepoReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
Complete(r)
|
||||
}
|
||||
|
||||
func (r *BackupRepoReconciler) invalidateBackupReposForBSL(bslObj client.Object) []reconcile.Request {
|
||||
func (r *BackupRepoReconciler) invalidateBackupReposForBSL(ctx context.Context, bslObj client.Object) []reconcile.Request {
|
||||
bsl := bslObj.(*velerov1api.BackupStorageLocation)
|
||||
|
||||
list := &velerov1api.BackupRepositoryList{}
|
||||
|
||||
@@ -203,7 +203,7 @@ func (r *backupStorageLocationReconciler) SetupWithManager(mgr ctrl.Manager) err
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
// As the "status.LastValidationTime" field is always updated, this triggers new reconciling process, skip the update event that include no spec change to avoid the reconcile loop
|
||||
For(&velerov1api.BackupStorageLocation{}, builder.WithPredicates(kube.SpecChangePredicate{})).
|
||||
Watches(g, nil, builder.WithPredicates(gp)).
|
||||
WatchesRawSource(g, nil, builder.WithPredicates(gp)).
|
||||
Complete(r)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
@@ -108,7 +108,7 @@ func (b *backupSyncReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
||||
log.WithError(err).Error("Error listing backups in backup store")
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
backupStoreBackups := sets.NewString(res...)
|
||||
backupStoreBackups := sets.New[string](res...)
|
||||
log.WithField("backupCount", len(backupStoreBackups)).Debug("Got backups from backup store")
|
||||
|
||||
// get a list of all the backups that exist as custom resources in the cluster
|
||||
@@ -126,7 +126,7 @@ func (b *backupSyncReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
||||
}
|
||||
|
||||
// get a list of backups that *are* in the backup storage location and *aren't* in the cluster
|
||||
clusterBackupsSet := sets.NewString()
|
||||
clusterBackupsSet := sets.New[string]()
|
||||
for _, b := range clusterBackupList.Items {
|
||||
clusterBackupsSet.Insert(b.Name)
|
||||
}
|
||||
@@ -349,13 +349,13 @@ func (b *backupSyncReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
// Filter all BSL events, because this controller is supposed to run periodically, not by event.
|
||||
For(&velerov1api.BackupStorageLocation{}, builder.WithPredicates(kube.FalsePredicate{})).
|
||||
Watches(backupSyncSource, nil, builder.WithPredicates(gp)).
|
||||
WatchesRawSource(backupSyncSource, nil, builder.WithPredicates(gp)).
|
||||
Complete(b)
|
||||
}
|
||||
|
||||
// deleteOrphanedBackups deletes backup objects (CRDs) from Kubernetes that have the specified location
|
||||
// and a phase of Completed, but no corresponding backup in object storage.
|
||||
func (b *backupSyncReconciler) deleteOrphanedBackups(ctx context.Context, locationName string, backupStoreBackups sets.String, log logrus.FieldLogger) {
|
||||
func (b *backupSyncReconciler) deleteOrphanedBackups(ctx context.Context, locationName string, backupStoreBackups sets.Set[string], log logrus.FieldLogger) {
|
||||
var backupList velerov1api.BackupList
|
||||
listOption := client.ListOptions{
|
||||
LabelSelector: labels.Set(map[string]string{
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
|
||||
"github.com/sirupsen/logrus"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
@@ -547,50 +547,50 @@ var _ = Describe("Backup Sync Reconciler", func() {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
cloudBackups sets.String
|
||||
cloudBackups sets.Set[string]
|
||||
k8sBackups []*velerov1api.Backup
|
||||
namespace string
|
||||
expectedDeletes sets.String
|
||||
expectedDeletes sets.Set[string]
|
||||
useLongBSLName bool
|
||||
}{
|
||||
{
|
||||
name: "no overlapping backups",
|
||||
namespace: "ns-1",
|
||||
cloudBackups: sets.NewString("backup-1", "backup-2", "backup-3"),
|
||||
cloudBackups: sets.New[string]("backup-1", "backup-2", "backup-3"),
|
||||
k8sBackups: []*velerov1api.Backup{
|
||||
baseBuilder("backupA").Phase(velerov1api.BackupPhaseCompleted).Result(),
|
||||
baseBuilder("backupB").Phase(velerov1api.BackupPhaseCompleted).Result(),
|
||||
baseBuilder("backupC").Phase(velerov1api.BackupPhasePartiallyFailed).Result(),
|
||||
},
|
||||
expectedDeletes: sets.NewString("backupA", "backupB", "backupC"),
|
||||
expectedDeletes: sets.New[string]("backupA", "backupB", "backupC"),
|
||||
},
|
||||
{
|
||||
name: "some overlapping backups",
|
||||
namespace: "ns-1",
|
||||
cloudBackups: sets.NewString("backup-1", "backup-2", "backup-3"),
|
||||
cloudBackups: sets.New[string]("backup-1", "backup-2", "backup-3"),
|
||||
k8sBackups: []*velerov1api.Backup{
|
||||
baseBuilder("backup-1").Phase(velerov1api.BackupPhaseCompleted).Result(),
|
||||
baseBuilder("backup-2").Phase(velerov1api.BackupPhaseCompleted).Result(),
|
||||
baseBuilder("backup-B").Phase(velerov1api.BackupPhaseCompleted).Result(),
|
||||
baseBuilder("backup-C").Phase(velerov1api.BackupPhasePartiallyFailed).Result(),
|
||||
},
|
||||
expectedDeletes: sets.NewString("backup-B", "backup-C"),
|
||||
expectedDeletes: sets.New[string]("backup-B", "backup-C"),
|
||||
},
|
||||
{
|
||||
name: "all overlapping backups",
|
||||
namespace: "ns-1",
|
||||
cloudBackups: sets.NewString("backup-1", "backup-2", "backup-3"),
|
||||
cloudBackups: sets.New[string]("backup-1", "backup-2", "backup-3"),
|
||||
k8sBackups: []*velerov1api.Backup{
|
||||
baseBuilder("backup-1").Phase(velerov1api.BackupPhaseCompleted).Result(),
|
||||
baseBuilder("backup-2").Phase(velerov1api.BackupPhaseCompleted).Result(),
|
||||
baseBuilder("backup-3").Phase(velerov1api.BackupPhasePartiallyFailed).Result(),
|
||||
},
|
||||
expectedDeletes: sets.NewString(),
|
||||
expectedDeletes: sets.New[string](),
|
||||
},
|
||||
{
|
||||
name: "no overlapping backups but including backups that are not complete",
|
||||
namespace: "ns-1",
|
||||
cloudBackups: sets.NewString("backup-1", "backup-2", "backup-3"),
|
||||
cloudBackups: sets.New[string]("backup-1", "backup-2", "backup-3"),
|
||||
k8sBackups: []*velerov1api.Backup{
|
||||
baseBuilder("backupA").Phase(velerov1api.BackupPhaseCompleted).Result(),
|
||||
baseBuilder("backupB").Phase(velerov1api.BackupPhasePartiallyFailed).Result(),
|
||||
@@ -600,23 +600,23 @@ var _ = Describe("Backup Sync Reconciler", func() {
|
||||
baseBuilder("InProgress").Phase(velerov1api.BackupPhaseInProgress).Result(),
|
||||
baseBuilder("New").Phase(velerov1api.BackupPhaseNew).Result(),
|
||||
},
|
||||
expectedDeletes: sets.NewString("backupA", "backupB"),
|
||||
expectedDeletes: sets.New[string]("backupA", "backupB"),
|
||||
},
|
||||
{
|
||||
name: "all overlapping backups and all backups that are not complete",
|
||||
namespace: "ns-1",
|
||||
cloudBackups: sets.NewString("backup-1", "backup-2", "backup-3"),
|
||||
cloudBackups: sets.New[string]("backup-1", "backup-2", "backup-3"),
|
||||
k8sBackups: []*velerov1api.Backup{
|
||||
baseBuilder("backup-1").Phase(velerov1api.BackupPhaseFailed).Result(),
|
||||
baseBuilder("backup-2").Phase(velerov1api.BackupPhaseFailedValidation).Result(),
|
||||
baseBuilder("backup-3").Phase(velerov1api.BackupPhaseInProgress).Result(),
|
||||
},
|
||||
expectedDeletes: sets.NewString(),
|
||||
expectedDeletes: sets.New[string](),
|
||||
},
|
||||
{
|
||||
name: "no completed backups in other locations are deleted",
|
||||
namespace: "ns-1",
|
||||
cloudBackups: sets.NewString("backup-1", "backup-2", "backup-3"),
|
||||
cloudBackups: sets.New[string]("backup-1", "backup-2", "backup-3"),
|
||||
k8sBackups: []*velerov1api.Backup{
|
||||
baseBuilder("backup-1").Phase(velerov1api.BackupPhaseCompleted).Result(),
|
||||
baseBuilder("backup-2").Phase(velerov1api.BackupPhaseCompleted).Result(),
|
||||
@@ -627,12 +627,12 @@ var _ = Describe("Backup Sync Reconciler", func() {
|
||||
baseBuilder("backup-5").ObjectMeta(builder.WithLabels(velerov1api.StorageLocationLabel, "alternate")).Phase(velerov1api.BackupPhaseCompleted).Result(),
|
||||
baseBuilder("backup-6").ObjectMeta(builder.WithLabels(velerov1api.StorageLocationLabel, "alternate")).Phase(velerov1api.BackupPhasePartiallyFailed).Result(),
|
||||
},
|
||||
expectedDeletes: sets.NewString("backup-C", "backup-D"),
|
||||
expectedDeletes: sets.New[string]("backup-C", "backup-D"),
|
||||
},
|
||||
{
|
||||
name: "some overlapping backups",
|
||||
namespace: "ns-1",
|
||||
cloudBackups: sets.NewString("backup-1", "backup-2", "backup-3"),
|
||||
cloudBackups: sets.New[string]("backup-1", "backup-2", "backup-3"),
|
||||
k8sBackups: []*velerov1api.Backup{
|
||||
builder.ForBackup("ns-1", "backup-1").
|
||||
ObjectMeta(
|
||||
@@ -659,7 +659,7 @@ var _ = Describe("Backup Sync Reconciler", func() {
|
||||
Phase(velerov1api.BackupPhasePartiallyFailed).
|
||||
Result(),
|
||||
},
|
||||
expectedDeletes: sets.NewString("backup-C", "backup-D"),
|
||||
expectedDeletes: sets.New[string]("backup-C", "backup-D"),
|
||||
useLongBSLName: true,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -35,13 +35,13 @@ type BackupTracker interface {
|
||||
|
||||
type backupTracker struct {
|
||||
lock sync.RWMutex
|
||||
backups sets.String
|
||||
backups sets.Set[string]
|
||||
}
|
||||
|
||||
// NewBackupTracker returns a new BackupTracker.
|
||||
func NewBackupTracker() BackupTracker {
|
||||
return &backupTracker{
|
||||
backups: sets.NewString(),
|
||||
backups: sets.New[string](),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/event"
|
||||
"sigs.k8s.io/controller-runtime/pkg/predicate"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
"sigs.k8s.io/controller-runtime/pkg/source"
|
||||
|
||||
"github.com/vmware-tanzu/velero/internal/credentials"
|
||||
"github.com/vmware-tanzu/velero/pkg/apis/velero/shared"
|
||||
@@ -476,8 +475,8 @@ func (r *DataDownloadReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
For(&velerov2alpha1api.DataDownload{}).
|
||||
Watches(s, nil, builder.WithPredicates(gp)).
|
||||
Watches(&source.Kind{Type: &v1.Pod{}}, kube.EnqueueRequestsFromMapUpdateFunc(r.findSnapshotRestoreForPod),
|
||||
WatchesRawSource(s, nil, builder.WithPredicates(gp)).
|
||||
Watches(&v1.Pod{}, kube.EnqueueRequestsFromMapUpdateFunc(r.findSnapshotRestoreForPod),
|
||||
builder.WithPredicates(predicate.Funcs{
|
||||
UpdateFunc: func(ue event.UpdateEvent) bool {
|
||||
newObj := ue.ObjectNew.(*v1.Pod)
|
||||
@@ -505,7 +504,7 @@ func (r *DataDownloadReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
Complete(r)
|
||||
}
|
||||
|
||||
func (r *DataDownloadReconciler) findSnapshotRestoreForPod(podObj client.Object) []reconcile.Request {
|
||||
func (r *DataDownloadReconciler) findSnapshotRestoreForPod(ctx context.Context, podObj client.Object) []reconcile.Request {
|
||||
pod := podObj.(*v1.Pod)
|
||||
dd, err := findDataDownloadByPod(r.client, *pod)
|
||||
|
||||
@@ -780,7 +779,7 @@ func isDataDownloadInFinalState(dd *velerov2alpha1api.DataDownload) bool {
|
||||
}
|
||||
|
||||
func UpdateDataDownloadWithRetry(ctx context.Context, client client.Client, namespacedName types.NamespacedName, log *logrus.Entry, updateFunc func(dataDownload *velerov2alpha1api.DataDownload)) error {
|
||||
return wait.PollUntilWithContext(ctx, time.Second, func(ctx context.Context) (done bool, err error) {
|
||||
return wait.PollUntilContextCancel(ctx, time.Second, true, func(ctx context.Context) (done bool, err error) {
|
||||
dd := &velerov2alpha1api.DataDownload{}
|
||||
if err := client.Get(ctx, namespacedName, dd); err != nil {
|
||||
return false, errors.Wrap(err, "getting DataDownload")
|
||||
|
||||
@@ -670,7 +670,7 @@ func TestFindDataDownloadForPod(t *testing.T) {
|
||||
assert.NoError(t, r.client.Create(ctx, test.pod))
|
||||
assert.NoError(t, r.client.Create(ctx, test.du))
|
||||
// Call the findSnapshotRestoreForPod function
|
||||
requests := r.findSnapshotRestoreForPod(test.pod)
|
||||
requests := r.findSnapshotRestoreForPod(context.Background(), test.pod)
|
||||
test.checkFunc(test.du, requests)
|
||||
r.client.Delete(ctx, test.du, &kbclient.DeleteOptions{})
|
||||
if test.pod != nil {
|
||||
|
||||
@@ -37,9 +37,8 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/event"
|
||||
"sigs.k8s.io/controller-runtime/pkg/predicate"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
"sigs.k8s.io/controller-runtime/pkg/source"
|
||||
|
||||
snapshotter "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned/typed/volumesnapshot/v1"
|
||||
snapshotter "github.com/kubernetes-csi/external-snapshotter/client/v7/clientset/versioned/typed/volumesnapshot/v1"
|
||||
|
||||
"github.com/vmware-tanzu/velero/internal/credentials"
|
||||
"github.com/vmware-tanzu/velero/pkg/apis/velero/shared"
|
||||
@@ -512,8 +511,8 @@ func (r *DataUploadReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
For(&velerov2alpha1api.DataUpload{}).
|
||||
Watches(s, nil, builder.WithPredicates(gp)).
|
||||
Watches(&source.Kind{Type: &corev1.Pod{}}, kube.EnqueueRequestsFromMapUpdateFunc(r.findDataUploadForPod),
|
||||
WatchesRawSource(s, nil, builder.WithPredicates(gp)).
|
||||
Watches(&corev1.Pod{}, kube.EnqueueRequestsFromMapUpdateFunc(r.findDataUploadForPod),
|
||||
builder.WithPredicates(predicate.Funcs{
|
||||
UpdateFunc: func(ue event.UpdateEvent) bool {
|
||||
newObj := ue.ObjectNew.(*corev1.Pod)
|
||||
@@ -541,7 +540,7 @@ func (r *DataUploadReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
Complete(r)
|
||||
}
|
||||
|
||||
func (r *DataUploadReconciler) findDataUploadForPod(podObj client.Object) []reconcile.Request {
|
||||
func (r *DataUploadReconciler) findDataUploadForPod(ctx context.Context, podObj client.Object) []reconcile.Request {
|
||||
pod := podObj.(*corev1.Pod)
|
||||
du, err := findDataUploadByPod(r.client, *pod)
|
||||
log := r.logger.WithFields(logrus.Fields{
|
||||
@@ -874,7 +873,7 @@ func isDataUploadInFinalState(du *velerov2alpha1api.DataUpload) bool {
|
||||
}
|
||||
|
||||
func UpdateDataUploadWithRetry(ctx context.Context, client client.Client, namespacedName types.NamespacedName, log *logrus.Entry, updateFunc func(dataUpload *velerov2alpha1api.DataUpload)) error {
|
||||
return wait.PollUntilWithContext(ctx, time.Second, func(ctx context.Context) (done bool, err error) {
|
||||
return wait.PollUntilContextCancel(ctx, time.Second, true, func(ctx context.Context) (done bool, err error) {
|
||||
du := &velerov2alpha1api.DataUpload{}
|
||||
if err := client.Get(ctx, namespacedName, du); err != nil {
|
||||
return false, errors.Wrap(err, "getting DataUpload")
|
||||
|
||||
@@ -22,8 +22,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
|
||||
snapshotFake "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned/fake"
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
|
||||
snapshotFake "github.com/kubernetes-csi/external-snapshotter/client/v7/clientset/versioned/fake"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -71,7 +71,7 @@ type FakeClient struct {
|
||||
listError error
|
||||
}
|
||||
|
||||
func (c *FakeClient) Get(ctx context.Context, key kbclient.ObjectKey, obj kbclient.Object) error {
|
||||
func (c *FakeClient) Get(ctx context.Context, key kbclient.ObjectKey, obj kbclient.Object, opts ...kbclient.GetOption) error {
|
||||
if c.getError != nil {
|
||||
return c.getError
|
||||
}
|
||||
@@ -465,8 +465,16 @@ func TestReconcile(t *testing.T) {
|
||||
}()
|
||||
ctx := context.Background()
|
||||
if test.du.Namespace == velerov1api.DefaultNamespace {
|
||||
isDeletionTimestampSet := test.du.DeletionTimestamp != nil
|
||||
err = r.client.Create(ctx, test.du)
|
||||
require.NoError(t, err)
|
||||
// because of the changes introduced by https://github.com/kubernetes-sigs/controller-runtime/commit/7a66d580c0c53504f5b509b45e9300cc18a1cc30
|
||||
// the fake client ignores the DeletionTimestamp when calling the Create(),
|
||||
// so call Delete() here
|
||||
if isDeletionTimestampSet {
|
||||
err = r.client.Delete(ctx, test.du)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
if test.pod != nil {
|
||||
@@ -720,7 +728,7 @@ func TestFindDataUploadForPod(t *testing.T) {
|
||||
assert.NoError(t, r.client.Create(ctx, test.pod))
|
||||
assert.NoError(t, r.client.Create(ctx, test.du))
|
||||
// Call the findDataUploadForPod function
|
||||
requests := r.findDataUploadForPod(test.pod)
|
||||
requests := r.findDataUploadForPod(context.Background(), test.pod)
|
||||
test.checkFunc(test.du, requests)
|
||||
r.client.Delete(ctx, test.du, &kbclient.DeleteOptions{})
|
||||
if test.pod != nil {
|
||||
|
||||
@@ -229,6 +229,6 @@ func (r *downloadRequestReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
For(&velerov1api.DownloadRequest{}).
|
||||
Watches(downloadRequestSource, nil, builder.WithPredicates(downloadRequestPredicates)).
|
||||
WatchesRawSource(downloadRequestSource, nil, builder.WithPredicates(downloadRequestPredicates)).
|
||||
Complete(r)
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ func (c *gcReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
return false
|
||||
},
|
||||
})).
|
||||
Watches(s, nil).
|
||||
WatchesRawSource(s, nil).
|
||||
Complete(c)
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/handler"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
"sigs.k8s.io/controller-runtime/pkg/source"
|
||||
|
||||
"github.com/vmware-tanzu/velero/internal/credentials"
|
||||
veleroapishared "github.com/vmware-tanzu/velero/pkg/apis/velero/shared"
|
||||
@@ -207,11 +206,11 @@ func (c *PodVolumeRestoreReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
// By watching the pods, we can trigger the PVR reconciliation again once the pod is finally scheduled on the node.
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
For(&velerov1api.PodVolumeRestore{}).
|
||||
Watches(&source.Kind{Type: &corev1api.Pod{}}, handler.EnqueueRequestsFromMapFunc(c.findVolumeRestoresForPod)).
|
||||
Watches(&corev1api.Pod{}, handler.EnqueueRequestsFromMapFunc(c.findVolumeRestoresForPod)).
|
||||
Complete(c)
|
||||
}
|
||||
|
||||
func (c *PodVolumeRestoreReconciler) findVolumeRestoresForPod(pod client.Object) []reconcile.Request {
|
||||
func (c *PodVolumeRestoreReconciler) findVolumeRestoresForPod(ctx context.Context, pod client.Object) []reconcile.Request {
|
||||
list := &velerov1api.PodVolumeRestoreList{}
|
||||
options := &client.ListOptions{
|
||||
LabelSelector: labels.Set(map[string]string{
|
||||
|
||||
@@ -491,7 +491,7 @@ func TestFindVolumeRestoresForPod(t *testing.T) {
|
||||
Client: clientBuilder.Build(),
|
||||
logger: logrus.New(),
|
||||
}
|
||||
requests := reconciler.findVolumeRestoresForPod(pod)
|
||||
requests := reconciler.findVolumeRestoresForPod(context.Background(), pod)
|
||||
assert.Len(t, requests, 0)
|
||||
|
||||
// contain one matching PVR
|
||||
@@ -515,6 +515,6 @@ func TestFindVolumeRestoresForPod(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}).Build()
|
||||
requests = reconciler.findVolumeRestoresForPod(pod)
|
||||
requests = reconciler.findVolumeRestoresForPod(context.Background(), pod)
|
||||
assert.Len(t, requests, 1)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -473,7 +473,15 @@ func TestRestoreReconcile(t *testing.T) {
|
||||
}
|
||||
|
||||
if test.restore != nil {
|
||||
isDeletionTimestampSet := test.restore.DeletionTimestamp != nil
|
||||
require.NoError(t, r.kbClient.Create(context.Background(), test.restore))
|
||||
// because of the changes introduced by https://github.com/kubernetes-sigs/controller-runtime/commit/7a66d580c0c53504f5b509b45e9300cc18a1cc30
|
||||
// the fake client ignores the DeletionTimestamp when calling the Create(),
|
||||
// so call Delete() here
|
||||
if isDeletionTimestampSet {
|
||||
err = r.kbClient.Delete(ctx, test.restore)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
var warnings, errors results.Result
|
||||
|
||||
@@ -90,7 +90,7 @@ func (r *restoreOperationsReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
})
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
For(&velerov1api.Restore{}, builder.WithPredicates(kube.FalsePredicate{})).
|
||||
Watches(s, nil, builder.WithPredicates(gp)).
|
||||
WatchesRawSource(s, nil, builder.WithPredicates(gp)).
|
||||
Complete(r)
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ func (c *scheduleReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
return true
|
||||
})).
|
||||
For(&velerov1.Schedule{}, bld.WithPredicates(kube.SpecChangePredicate{})).
|
||||
Watches(s, nil).
|
||||
WatchesRawSource(s, nil).
|
||||
Complete(c)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user