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 ZBuilderWatcher struct { Client client.Client } //监听create事件 func (zbuilderWatcher *ZBuilderWatcher) Create(ctx context.Context, e event.CreateEvent, limitingInterface workqueue.RateLimitingInterface) { labels := e.Object.GetLabels() if builderName, ok := labels["zbuilders.zelda.io"]; ok { //等待50ms limitingInterface.AddAfter(&reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.Object.GetNamespace(), Name: builderName}}, time.Millisecond*50) } } //监听update事件 func (zbuilderWatcher *ZBuilderWatcher) Update(ctx context.Context, e event.UpdateEvent, limitingInterface workqueue.RateLimitingInterface) { labels := e.ObjectNew.GetLabels() if builderName, ok := labels["zbuilders.zelda.io"]; ok { //等待50ms limitingInterface.AddAfter(&reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.ObjectNew.GetNamespace(), Name: builderName}}, time.Millisecond*50) } } //监听delete事件 func (zbuilderWatcher *ZBuilderWatcher) Delete(ctx context.Context, e event.DeleteEvent, limitingInerface workqueue.RateLimitingInterface) { } //监听generic事件 func (zbuilderWatcher *ZBuilderWatcher) Generic(ctx context.Context, e event.GenericEvent, limitingInterface workqueue.RateLimitingInterface) { }