mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-13 11:34:54 +00:00
Merge pull request #8275 from ywk253100/241008_discovery
Bump up version of client-go and controller-runtime
This commit is contained in:
@@ -31,7 +31,6 @@ import (
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/event"
|
||||
"sigs.k8s.io/controller-runtime/pkg/handler"
|
||||
"sigs.k8s.io/controller-runtime/pkg/predicate"
|
||||
)
|
||||
|
||||
@@ -62,11 +61,12 @@ type PeriodicalEnqueueSource struct {
|
||||
}
|
||||
|
||||
type PeriodicalEnqueueSourceOption struct {
|
||||
OrderFunc func(objList client.ObjectList) client.ObjectList
|
||||
OrderFunc func(objList client.ObjectList) client.ObjectList
|
||||
Predicates []predicate.Predicate // the predicates only apply to the GenericEvent
|
||||
}
|
||||
|
||||
// Start enqueue items periodically. The predicates only apply to the GenericEvent
|
||||
func (p *PeriodicalEnqueueSource) Start(ctx context.Context, h handler.EventHandler, q workqueue.RateLimitingInterface, predicates ...predicate.Predicate) error {
|
||||
// Start enqueue items periodically
|
||||
func (p *PeriodicalEnqueueSource) Start(ctx context.Context, q workqueue.RateLimitingInterface) error {
|
||||
go wait.Until(func() {
|
||||
p.logger.Debug("enqueueing resources ...")
|
||||
// empty the list otherwise the result of the new list call will be appended
|
||||
@@ -92,7 +92,7 @@ func (p *PeriodicalEnqueueSource) Start(ctx context.Context, h handler.EventHand
|
||||
return nil
|
||||
}
|
||||
event := event.GenericEvent{Object: obj}
|
||||
for _, predicate := range predicates {
|
||||
for _, predicate := range p.option.Predicates {
|
||||
if !predicate.Generic(event) {
|
||||
p.logger.Debugf("skip enqueue object %s/%s due to the predicate.", obj.GetNamespace(), obj.GetName())
|
||||
return nil
|
||||
@@ -118,7 +118,7 @@ func (p *PeriodicalEnqueueSource) Start(ctx context.Context, h handler.EventHand
|
||||
|
||||
func (p *PeriodicalEnqueueSource) String() string {
|
||||
if p.objList != nil {
|
||||
return fmt.Sprintf("kind source: %T", p.objList)
|
||||
return fmt.Sprintf("periodical enqueue source: %T", p.objList)
|
||||
}
|
||||
return "kind source: unknown type"
|
||||
return "periodical enqueue source: unknown type"
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"k8s.io/client-go/util/workqueue"
|
||||
crclient "sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||
"sigs.k8s.io/controller-runtime/pkg/predicate"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
|
||||
"github.com/vmware-tanzu/velero/internal/storage"
|
||||
@@ -44,7 +45,7 @@ func TestStart(t *testing.T) {
|
||||
queue := workqueue.NewRateLimitingQueue(workqueue.DefaultItemBasedRateLimiter())
|
||||
source := NewPeriodicalEnqueueSource(logrus.WithContext(ctx).WithField("controller", "PES_TEST"), client, &velerov1.ScheduleList{}, 1*time.Second, PeriodicalEnqueueSourceOption{})
|
||||
|
||||
require.NoError(t, source.Start(ctx, nil, queue))
|
||||
require.NoError(t, source.Start(ctx, queue))
|
||||
|
||||
// no resources
|
||||
time.Sleep(1 * time.Second)
|
||||
@@ -74,18 +75,22 @@ func TestPredicate(t *testing.T) {
|
||||
ctx, cancelFunc := context.WithCancel(context.TODO())
|
||||
client := (&fake.ClientBuilder{}).Build()
|
||||
queue := workqueue.NewRateLimitingQueue(workqueue.DefaultItemBasedRateLimiter())
|
||||
|
||||
pred := NewGenericEventPredicate(func(object crclient.Object) bool {
|
||||
location := object.(*velerov1.BackupStorageLocation)
|
||||
return storage.IsReadyToValidate(location.Spec.ValidationFrequency, location.Status.LastValidationTime, 1*time.Minute, logrus.WithContext(ctx).WithField("BackupStorageLocation", location.Name))
|
||||
})
|
||||
source := NewPeriodicalEnqueueSource(
|
||||
logrus.WithContext(ctx).WithField("controller", "PES_TEST"),
|
||||
client,
|
||||
&velerov1.BackupStorageLocationList{},
|
||||
1*time.Second,
|
||||
PeriodicalEnqueueSourceOption{},
|
||||
PeriodicalEnqueueSourceOption{
|
||||
Predicates: []predicate.Predicate{pred},
|
||||
},
|
||||
)
|
||||
|
||||
require.NoError(t, source.Start(ctx, nil, queue, NewGenericEventPredicate(func(object crclient.Object) bool {
|
||||
location := object.(*velerov1.BackupStorageLocation)
|
||||
return storage.IsReadyToValidate(location.Spec.ValidationFrequency, location.Status.LastValidationTime, 1*time.Minute, logrus.WithContext(ctx).WithField("BackupStorageLocation", location.Name))
|
||||
})))
|
||||
require.NoError(t, source.Start(ctx, queue))
|
||||
|
||||
// Should not patch a backup storage location object status phase
|
||||
// if the location's validation frequency is specifically set to zero
|
||||
@@ -137,7 +142,7 @@ func TestOrder(t *testing.T) {
|
||||
},
|
||||
)
|
||||
|
||||
require.NoError(t, source.Start(ctx, nil, queue))
|
||||
require.NoError(t, source.Start(ctx, queue))
|
||||
|
||||
// Should not patch a backup storage location object status phase
|
||||
// if the location's validation frequency is specifically set to zero
|
||||
|
||||
Reference in New Issue
Block a user