INNER CODE UNIT · Go

InformerConnectProperty

getseabird/seabird · api/cluster.go:259

func InformerConnectProperty[T client.Object](ctx context.Context, cluster *Cluster, gvr schema.GroupVersionResource, prop pubsub.Property[[]T]) error {
	updateProperty, _ := debounce.Debounce(func() {
		var objects []T
		err := cache.ListAll(cluster.GetInformer(gvr).Informer().GetIndexer(), labels.Everything(), func(m interface{}) {
			objects = append(objects, m.(T))
		})
		if err != nil {
			klog.Warning("list all: %v", err)
			return
		}
		slices.SortFunc(objects, func(a, b T) int {
			return strings.Compare(a.GetName(), b.GetName())
		})
		prop.Pub(objects)
	}, 100*time.Millisecond)
	defer updateProperty()

	return cluster.AddInformerEventHandler(ctx, gvr, cache.ResourceEventHandlerFuncs{

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…