1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

fix: interface conversion panic (#5708)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-12-16 18:43:02 +01:00 committed by GitHub
parent 4679766879
commit dacb465e10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,7 @@ import (
"time"
"github.com/go-logr/logr"
kubeutils "github.com/kyverno/kyverno/pkg/utils/kube"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"
@ -27,16 +28,19 @@ func AddEventHandlers(informer cache.SharedInformer, a addFunc, u updateFunc, d
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: a,
UpdateFunc: u,
DeleteFunc: d,
DeleteFunc: func(obj interface{}) {
d(kubeutils.GetObjectWithTombstone(obj))
},
})
}
func AddEventHandlersT[T any](informer cache.SharedInformer, a addFuncT[T], u updateFuncT[T], d deleteFuncT[T]) {
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) { a(obj.(T)) },
UpdateFunc: func(old, obj interface{}) { u(old.(T), obj.(T)) },
DeleteFunc: func(obj interface{}) { d(obj.(T)) },
})
AddEventHandlers(
informer,
func(obj interface{}) { a(obj.(T)) },
func(old, obj interface{}) { u(old.(T), obj.(T)) },
func(obj interface{}) { d(obj.(T)) },
)
}
func AddKeyedEventHandlers(logger logr.Logger, informer cache.SharedInformer, queue workqueue.RateLimitingInterface, parseKey keyFunc) EnqueueFunc {