github.com/oam-dev/cluster-gateway@v1.9.0/pkg/event/apiservice_handler.go (about) 1 package event 2 3 import ( 4 "github.com/oam-dev/cluster-gateway/pkg/common" 5 6 "context" 7 8 "k8s.io/apimachinery/pkg/types" 9 "k8s.io/client-go/util/workqueue" 10 apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" 11 "sigs.k8s.io/controller-runtime/pkg/event" 12 "sigs.k8s.io/controller-runtime/pkg/handler" 13 "sigs.k8s.io/controller-runtime/pkg/reconcile" 14 ) 15 16 var _ handler.EventHandler = &APIServiceHandler{} 17 18 type APIServiceHandler struct { 19 WatchingName string 20 } 21 22 func (a *APIServiceHandler) Create(_ context.Context, event event.CreateEvent, q workqueue.RateLimitingInterface) { 23 a.process(event.Object.(*apiregistrationv1.APIService), q) 24 } 25 26 func (a *APIServiceHandler) Update(_ context.Context, event event.UpdateEvent, q workqueue.RateLimitingInterface) { 27 a.process(event.ObjectNew.(*apiregistrationv1.APIService), q) 28 } 29 30 func (a *APIServiceHandler) Delete(_ context.Context, event event.DeleteEvent, q workqueue.RateLimitingInterface) { 31 a.process(event.Object.(*apiregistrationv1.APIService), q) 32 } 33 34 func (a *APIServiceHandler) Generic(_ context.Context, event event.GenericEvent, q workqueue.RateLimitingInterface) { 35 a.process(event.Object.(*apiregistrationv1.APIService), q) 36 } 37 38 func (a *APIServiceHandler) process(apiService *apiregistrationv1.APIService, q workqueue.RateLimitingInterface) { 39 if apiService.Name == a.WatchingName { 40 q.Add(reconcile.Request{ 41 NamespacedName: types.NamespacedName{ 42 Name: common.AddonName, 43 }, 44 }) 45 } 46 }