mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-07 22:05:25 +00:00
Upgrade go.mod k8s.io/ go.mod to v0.31.3 and set klog.SetLogger() for client-go (#8450)
Some checks failed
Run the E2E test on kind / build (push) Failing after 5m44s
Run the E2E test on kind / setup-test-matrix (push) Successful in 3s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
build-image / Build (push) Failing after 10s
Main CI / Build (push) Failing after 31s
Close stale issues and PRs / stale (push) Successful in 7s
Trivy Nightly Scan / Trivy nightly scan (velero, main) (push) Failing after 59s
Trivy Nightly Scan / Trivy nightly scan (velero-restore-helper, main) (push) Failing after 45s
Some checks failed
Run the E2E test on kind / build (push) Failing after 5m44s
Run the E2E test on kind / setup-test-matrix (push) Successful in 3s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
build-image / Build (push) Failing after 10s
Main CI / Build (push) Failing after 31s
Close stale issues and PRs / stale (push) Successful in 7s
Trivy Nightly Scan / Trivy nightly scan (velero, main) (push) Failing after 59s
Trivy Nightly Scan / Trivy nightly scan (velero-restore-helper, main) (push) Failing after 45s
Also bumped to support upgraded k8s.io/ deps. - controller-gen to v0.16.5 - sigs.k8s.io/controller-runtime v0.19.2 Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
This commit is contained in:
@@ -26,46 +26,48 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
)
|
||||
|
||||
type MapUpdateFunc func(context.Context, client.Object) []reconcile.Request
|
||||
|
||||
// EnqueueRequestsFromMapUpdateFunc has the same purpose with handler.EnqueueRequestsFromMapFunc.
|
||||
// MapUpdateFunc is simpler on Update event because mapAndEnqueue is called once with the new object. EnqueueRequestsFromMapFunc is called twice with the old and new object.
|
||||
func EnqueueRequestsFromMapUpdateFunc(fn MapUpdateFunc) handler.EventHandler {
|
||||
return &enqueueRequestsFromMapFunc{
|
||||
// It's simpler on Update event because mapAndEnqueue is called once with the new object. EnqueueRequestsFromMapFunc is called twice with the old and new object.
|
||||
func EnqueueRequestsFromMapUpdateFunc(fn handler.MapFunc) handler.EventHandler {
|
||||
return TypedEnqueueRequestsFromMapUpdateFunc(fn)
|
||||
}
|
||||
|
||||
func TypedEnqueueRequestsFromMapUpdateFunc[object any, request comparable](fn handler.TypedMapFunc[object, request]) handler.TypedEventHandler[object, request] {
|
||||
return &enqueueRequestsFromMapFunc[object, request]{
|
||||
toRequests: fn,
|
||||
}
|
||||
}
|
||||
|
||||
var _ handler.EventHandler = &enqueueRequestsFromMapFunc{}
|
||||
var _ handler.EventHandler = &enqueueRequestsFromMapFunc[client.Object, reconcile.Request]{}
|
||||
|
||||
type enqueueRequestsFromMapFunc struct {
|
||||
toRequests MapUpdateFunc
|
||||
type enqueueRequestsFromMapFunc[object any, request comparable] struct {
|
||||
toRequests handler.TypedMapFunc[object, request]
|
||||
}
|
||||
|
||||
// Create implements EventHandler.
|
||||
func (e *enqueueRequestsFromMapFunc) Create(ctx context.Context, evt event.CreateEvent, q workqueue.RateLimitingInterface) {
|
||||
func (e *enqueueRequestsFromMapFunc[object, request]) Create(ctx context.Context, evt event.TypedCreateEvent[object], q workqueue.TypedRateLimitingInterface[request]) {
|
||||
e.mapAndEnqueue(ctx, q, evt.Object)
|
||||
}
|
||||
|
||||
// Update implements EventHandler.
|
||||
func (e *enqueueRequestsFromMapFunc) Update(ctx context.Context, evt event.UpdateEvent, q workqueue.RateLimitingInterface) {
|
||||
func (e *enqueueRequestsFromMapFunc[object, request]) Update(ctx context.Context, evt event.TypedUpdateEvent[object], q workqueue.TypedRateLimitingInterface[request]) {
|
||||
e.mapAndEnqueue(ctx, q, evt.ObjectNew)
|
||||
}
|
||||
|
||||
// Delete implements EventHandler.
|
||||
func (e *enqueueRequestsFromMapFunc) Delete(ctx context.Context, evt event.DeleteEvent, q workqueue.RateLimitingInterface) {
|
||||
func (e *enqueueRequestsFromMapFunc[object, request]) Delete(ctx context.Context, evt event.TypedDeleteEvent[object], q workqueue.TypedRateLimitingInterface[request]) {
|
||||
e.mapAndEnqueue(ctx, q, evt.Object)
|
||||
}
|
||||
|
||||
// Generic implements EventHandler.
|
||||
func (e *enqueueRequestsFromMapFunc) Generic(ctx context.Context, evt event.GenericEvent, q workqueue.RateLimitingInterface) {
|
||||
func (e *enqueueRequestsFromMapFunc[object, request]) Generic(ctx context.Context, evt event.TypedGenericEvent[object], q workqueue.TypedRateLimitingInterface[request]) {
|
||||
e.mapAndEnqueue(ctx, q, evt.Object)
|
||||
}
|
||||
|
||||
func (e *enqueueRequestsFromMapFunc) mapAndEnqueue(ctx context.Context, q workqueue.RateLimitingInterface, object client.Object) {
|
||||
reqs := map[reconcile.Request]struct{}{}
|
||||
func (e *enqueueRequestsFromMapFunc[object, request]) mapAndEnqueue(ctx context.Context, q workqueue.TypedRateLimitingInterface[request], obj object) {
|
||||
reqs := map[request]struct{}{}
|
||||
|
||||
for _, req := range e.toRequests(ctx, object) {
|
||||
for _, req := range e.toRequests(ctx, obj) {
|
||||
_, ok := reqs[req]
|
||||
if !ok {
|
||||
q.Add(req)
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/event"
|
||||
"sigs.k8s.io/controller-runtime/pkg/predicate"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
)
|
||||
|
||||
func NewPeriodicalEnqueueSource(
|
||||
@@ -66,7 +67,7 @@ type PeriodicalEnqueueSourceOption struct {
|
||||
}
|
||||
|
||||
// Start enqueue items periodically
|
||||
func (p *PeriodicalEnqueueSource) Start(ctx context.Context, q workqueue.RateLimitingInterface) error {
|
||||
func (p *PeriodicalEnqueueSource) Start(ctx context.Context, q workqueue.TypedRateLimitingInterface[reconcile.Request]) error {
|
||||
go wait.Until(func() {
|
||||
p.logger.Debug("enqueueing resources ...")
|
||||
// empty the list otherwise the result of the new list call will be appended
|
||||
|
||||
@@ -42,7 +42,7 @@ func TestStart(t *testing.T) {
|
||||
|
||||
ctx, cancelFunc := context.WithCancel(context.TODO())
|
||||
client := (&fake.ClientBuilder{}).Build()
|
||||
queue := workqueue.NewRateLimitingQueue(workqueue.DefaultItemBasedRateLimiter())
|
||||
queue := workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedItemBasedRateLimiter[reconcile.Request]())
|
||||
source := NewPeriodicalEnqueueSource(logrus.WithContext(ctx).WithField("controller", "PES_TEST"), client, &velerov1.ScheduleList{}, 1*time.Second, PeriodicalEnqueueSourceOption{})
|
||||
|
||||
require.NoError(t, source.Start(ctx, queue))
|
||||
@@ -74,7 +74,7 @@ func TestPredicate(t *testing.T) {
|
||||
|
||||
ctx, cancelFunc := context.WithCancel(context.TODO())
|
||||
client := (&fake.ClientBuilder{}).Build()
|
||||
queue := workqueue.NewRateLimitingQueue(workqueue.DefaultItemBasedRateLimiter())
|
||||
queue := workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedItemBasedRateLimiter[reconcile.Request]())
|
||||
|
||||
pred := NewGenericEventPredicate(func(object crclient.Object) bool {
|
||||
location := object.(*velerov1.BackupStorageLocation)
|
||||
@@ -118,7 +118,7 @@ func TestOrder(t *testing.T) {
|
||||
|
||||
ctx, cancelFunc := context.WithCancel(context.TODO())
|
||||
client := (&fake.ClientBuilder{}).Build()
|
||||
queue := workqueue.NewRateLimitingQueue(workqueue.DefaultItemBasedRateLimiter())
|
||||
queue := workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedItemBasedRateLimiter[reconcile.Request]())
|
||||
source := NewPeriodicalEnqueueSource(
|
||||
logrus.WithContext(ctx).WithField("controller", "PES_TEST"),
|
||||
client,
|
||||
@@ -175,8 +175,8 @@ func TestOrder(t *testing.T) {
|
||||
|
||||
first, _ := queue.Get()
|
||||
bsl := &velerov1.BackupStorageLocation{}
|
||||
require.Equal(t, "location2", first.(reconcile.Request).Name)
|
||||
require.NoError(t, client.Get(ctx, first.(reconcile.Request).NamespacedName, bsl))
|
||||
require.Equal(t, "location2", first.Name)
|
||||
require.NoError(t, client.Get(ctx, first.NamespacedName, bsl))
|
||||
require.True(t, bsl.Spec.Default)
|
||||
|
||||
cancelFunc()
|
||||
|
||||
Reference in New Issue
Block a user