Skip to content

Commit

Permalink
Handle AddEventHandler error.
Browse files Browse the repository at this point in the history
The `AddEventHandler` interface has changed and now returns an
error (and a registration object that we do not need to use for
now). This handles the error if any arise and also makes the linter
happy :).

Signed-off-by: Vincent Demeester <[email protected]>
  • Loading branch information
vdemeester committed Jul 28, 2023
1 parent 4b8c9a1 commit 9f056cd
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 43 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ require (

// TODO: Remove this once https://github.com/knative/pkg/issues/2759 is fixed
replace (
k8s.io/api => k8s.io/api v0.26.5
k8s.io/apimachinery => k8s.io/apimachinery v0.26.5
k8s.io/client-go => k8s.io/client-go v0.26.5
k8s.io/code-generator => k8s.io/code-generator v0.26.5
k8s.io/api => k8s.io/api v0.26.7
k8s.io/apimachinery => k8s.io/apimachinery v0.26.7
k8s.io/client-go => k8s.io/client-go v0.26.7
k8s.io/code-generator => k8s.io/code-generator v0.26.7
)

require github.com/benbjohnson/clock v1.1.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pkg/reconciler/notifications/customrun/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ func NewController() func(context.Context, configmap.Watcher) *controller.Impl {
}
})

customRunInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue))
if _, err := customRunInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)); err != nil {
logging.FromContext(ctx).Panicf("Couldn't register CustomRun informer event handler: %w", err)
}

return impl
}
Expand Down
24 changes: 17 additions & 7 deletions pkg/reconciler/pipelinerun/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,30 @@ func NewController(opts *pipeline.Options, clock clock.PassiveClock, tracerProvi
}
})

pipelineRunInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue))
if _, err := pipelineRunInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)); err != nil {
logging.FromContext(ctx).Panicf("Couldn't register PipelineRun informer event handler: %w", err)
}

taskRunInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
if _, err := taskRunInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: controller.FilterController(&v1.PipelineRun{}),
Handler: controller.HandleAll(impl.EnqueueControllerOf),
})
customRunInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
}); err != nil {
logging.FromContext(ctx).Panicf("Couldn't register TaskRun informer event handler: %w", err)
}

if _, err := customRunInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: controller.FilterController(&v1.PipelineRun{}),
Handler: controller.HandleAll(impl.EnqueueControllerOf),
})
resolutionInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
}); err != nil {
logging.FromContext(ctx).Panicf("Couldn't register CustomRun informer event handler: %w", err)
}

if _, err := resolutionInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: controller.FilterController(&v1.PipelineRun{}),
Handler: controller.HandleAll(impl.EnqueueControllerOf),
})
}); err != nil {
logging.FromContext(ctx).Panicf("Couldn't register ResolutionRequest informer event handler: %w", err)
}

return impl
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/reconciler/resolutionrequest/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"k8s.io/utils/clock"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/logging"
)

// NewController returns a func that returns a knative controller for processing
Expand All @@ -36,7 +37,9 @@ func NewController(clock clock.PassiveClock) func(ctx context.Context, cmw confi
impl := resolutionrequestreconciler.NewImpl(ctx, r)

reqinformer := resolutionrequestinformer.Get(ctx)
reqinformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue))
if _, err := reqinformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)); err != nil {
logging.FromContext(ctx).Panicf("Couldn't register ResolutionRequest informer event handler: %w", err)
}

return impl
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/reconciler/taskrun/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,16 @@ func NewController(opts *pipeline.Options, clock clock.PassiveClock, tracerProvi
}
})

taskRunInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue))
if _, err := taskRunInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)); err != nil {
logging.FromContext(ctx).Panicf("Couldn't register TaskRun informer event handler: %w", err)
}

podInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
if _, err := podInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: controller.FilterController(&v1.TaskRun{}),
Handler: controller.HandleAll(impl.EnqueueControllerOf),
})
}); err != nil {
logging.FromContext(ctx).Panicf("Couldn't register Pod informer event handler: %w", err)
}

return impl
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/resolution/resolver/framework/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func NewController(ctx context.Context, resolver Resolver, modifiers ...Reconcil
Logger: logger,
})

rrInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
_, err := rrInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: filterResolutionRequestsBySelector(resolver.GetSelector(ctx)),
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: impl.Enqueue,
Expand All @@ -93,6 +93,9 @@ func NewController(ctx context.Context, resolver Resolver, modifiers ...Reconcil
// DeleteFunc: impl.Enqueue,
},
})
if err != nil {
logging.FromContext(ctx).Panicf("Couldn't register ResolutionRequest informer event handler: %w", err)
}

return impl
}
Expand Down
7 changes: 5 additions & 2 deletions test/custom-task-ctrls/wait-task-beta/cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/injection/sharedmain"
"knative.dev/pkg/logging"
)

const controllerName = "wait-task-controller"
Expand All @@ -46,10 +47,12 @@ func newController(ctx context.Context, cmw configmap.Watcher) *controller.Impl
}
})

customruninformer.Get(ctx).Informer().AddEventHandler(cache.FilteringResourceEventHandler{
if _, err := customruninformer.Get(ctx).Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: tkncontroller.FilterCustomRunRef("wait.testing.tekton.dev/v1beta1", "Wait"),
Handler: controller.HandleAll(impl.Enqueue),
})
}); err != nil {
logging.FromContext(ctx).Panicf("Couldn't register CustomRun informer event handler: %w", err)
}

return impl
}
2 changes: 1 addition & 1 deletion test/custom-task-ctrls/wait-task-beta/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/tektoncd/pipeline v0.49.0
k8s.io/api v0.26.7
k8s.io/apimachinery v0.26.7
k8s.io/client-go v0.25.11
k8s.io/client-go v0.26.7
k8s.io/utils v0.0.0-20230209194617-a36077c30491
knative.dev/pkg v0.0.0-20230221145627-8efb3485adcf
)
2 changes: 2 additions & 0 deletions test/custom-task-ctrls/wait-task-beta/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/k8s.io/api/core/v1/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/k8s.io/apimachinery/pkg/runtime/converter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 22 additions & 5 deletions vendor/k8s.io/client-go/util/cert/cert.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions vendor/modules.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9f056cd

Please sign in to comment.