package watchers import ( "context" "time" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/util/workqueue" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) type ZUserWatcher struct { Client client.Client } //监听create事件 func (zserviceWatcher *ZUserWatcher) Create(ctx context.Context, e event.CreateEvent, limitingInterface workqueue.RateLimitingInterface) { labels := e.Object.GetLabels() if serviceName, ok := labels["zusers.zelda.io"]; ok { //等待50ms limitingInterface.AddAfter(&reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.Object.GetNamespace(), Name: serviceName}}, time.Millisecond*50) } } //监听update事件 func (zserviceWatcher *ZUserWatcher) Update(ctx context.Context, e event.UpdateEvent, limitingInterface workqueue.RateLimitingInterface) { labels := e.ObjectNew.GetLabels() if serviceName, ok := labels["zusers.zelda.io"]; ok { //等待50ms limitingInterface.AddAfter(&reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.ObjectNew.GetNamespace(), Name: serviceName}}, time.Millisecond*50) } } //监听delete事件 func (zserviceWatcher *ZUserWatcher) Delete(ctx context.Context, e event.DeleteEvent, limitingInterface workqueue.RateLimitingInterface) { labels := e.Object.GetLabels() if serviceName, ok := labels["zusers.zelda.io"]; ok { //等待50ms limitingInterface.AddAfter(&reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.Object.GetNamespace(), Name: serviceName}}, time.Millisecond*50) } } //监听generic事件 func (zserviceWatcher *ZUserWatcher) Generic(ctx context.Context, e event.GenericEvent, limitingInterface workqueue.RateLimitingInterface) { }