sbom-operator icon indicating copy to clipboard operation
sbom-operator copied to clipboard

Feature Request: Support cache.SharedIndexInformer for auto-triggering

Open Dentrax opened this issue 2 years ago • 0 comments

As we already discussed this idea in Slack, dropping here so we do not forget!


Instead of run operator as scheduled runs using CronJob, we can use NewSharedIndexInformer to create an event loop in order to detect image changes instantly. For example;

deploymentInformer := cache.NewSharedIndexInformer(
			&cache.ListWatch{
				ListFunc: func(options metaV1.ListOptions) (runtime.Object, error) {
					return clientSet.AppsV1().Deployments(metaV1.NamespaceAll).List(ctx, options)
				},
				WatchFunc: func(options metaV1.ListOptions) (watch.Interface, error) {
					return clientSet.AppsV1().Deployments(metaV1.NamespaceAll).Watch(ctx, options)
				},
			},
			&appsV1.Deployment{},
			0,
			cache.Indexers{},
		)

Eventually we are able to get all add/update/remove events:

informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc: func(obj interface{}) {
			//
		},
		UpdateFunc: func(old, new interface{}) {
			//
		},
		DeleteFunc: func(obj interface{}) {
			//
		},
	})

P.S: We also do not want to drop scheduled runs. But both features are actually mutually-exclusive. So one of run type must be chosen in the config.

cc @developer-guy

Dentrax avatar Jun 02 '22 12:06 Dentrax