sbom-operator
sbom-operator copied to clipboard
Feature Request: Support cache.SharedIndexInformer for auto-triggering
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