From d460f0254d490288613b0fd3ff191c894b8b0f40 Mon Sep 17 00:00:00 2001 From: savitaashture Date: Wed, 20 Jul 2022 17:51:46 +0530 Subject: [PATCH] Add watching mechanism to watch on caBundle for core interceptor --- cmd/interceptors/main.go | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/cmd/interceptors/main.go b/cmd/interceptors/main.go index 1c77c8a25..52d2ae00e 100644 --- a/cmd/interceptors/main.go +++ b/cmd/interceptors/main.go @@ -91,15 +91,24 @@ func main() { if err != nil { return } - - clusterInterceptorList, err := clusterinterceptorsinformer.Get(ctx).Lister().List(labels.NewSelector()) - if err != nil { - return - } - - if err := service.UpdateCRDWithCaCert(ctx, tc.TriggersV1alpha1(), clusterInterceptorList, caCert); err != nil { + if err := listAndUpdateClusterInterceptorCRD(ctx, tc, service, caCert); err != nil { return } + ticker := time.NewTicker(time.Minute) + quit := make(chan struct{}) + go func() { + for { + select { + case <-ticker.C: + if err := listAndUpdateClusterInterceptorCRD(ctx, tc, service, caCert); err != nil { + return + } + case <-quit: + ticker.Stop() + return + } + } + }() srv := &http.Server{ Addr: fmt.Sprintf(":%d", HTTPSPort), @@ -121,3 +130,15 @@ func main() { func handler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } + +func listAndUpdateClusterInterceptorCRD(ctx context.Context, tc *triggersclientset.Clientset, service *server.Server, caCert []byte) error { + clusterInterceptorList, err := clusterinterceptorsinformer.Get(ctx).Lister().List(labels.NewSelector()) + if err != nil { + return err + } + + if err := service.UpdateCRDWithCaCert(ctx, tc.TriggersV1alpha1(), clusterInterceptorList, caCert); err != nil { + return err + } + return nil +}