Skip to content

Commit

Permalink
feat(secret): add informer event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Souheil-Yazji committed Mar 22, 2024
1 parent 6cf6e73 commit d2d5c70
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions cmd/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"
)
Expand Down Expand Up @@ -46,7 +47,7 @@ var secretCmd = &cobra.Command{
kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, time.Minute*(time.Duration(requeue_time)))
kubeflowInformerFactory := kubeflowinformers.NewSharedInformerFactory(kubeflowClient, time.Minute*(time.Duration(requeue_time)))

// secretInformer := kubeInformerFactory.Core().V1().Secrets()
secretInformer := kubeInformerFactory.Core().V1().Secrets()
// secretLister := secretInformer.Lister()

// Setup controller
Expand All @@ -58,15 +59,29 @@ var secretCmd = &cobra.Command{
},
)

secretInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
UpdateFunc: func(old, new interface{}) {
newNP := new.(*corev1.Secret)
oldNP := old.(*corev1.Secret)

if newNP.ResourceVersion == oldNP.ResourceVersion {
return
}

controller.HandleObject(new)
},
DeleteFunc: controller.HandleObject,
})

// Start informers
kubeInformerFactory.Start(stopCh)
kubeflowInformerFactory.Start(stopCh)

// Wait for caches
// klog.Info("Waiting for informer caches to sync")
// if ok := cache.WaitForCacheSync(stopCh, secretInformer.Informer().HasSynced); !ok {
// klog.Fatalf("failed to wait for caches to sync")
// }
klog.Info("Waiting for informer caches to sync")
if ok := cache.WaitForCacheSync(stopCh, secretInformer.Informer().HasSynced); !ok {
klog.Fatalf("failed to wait for caches to sync")
}

// Run the controller
if err = controller.Run(2, stopCh); err != nil {
Expand Down

0 comments on commit d2d5c70

Please sign in to comment.