diff --git a/cmd/ingress/ingress.go b/cmd/ingress/ingress.go index b633d3f20e..0c143c560e 100644 --- a/cmd/ingress/ingress.go +++ b/cmd/ingress/ingress.go @@ -23,7 +23,6 @@ import ( "syscall" "time" - "github.com/api7/ingress-controller/pkg/metrics" api6Informers "github.com/gxthrj/apisix-ingress-types/pkg/client/informers/externalversions" "github.com/spf13/cobra" @@ -32,6 +31,7 @@ import ( "github.com/api7/ingress-controller/pkg/ingress/controller" "github.com/api7/ingress-controller/pkg/kube" "github.com/api7/ingress-controller/pkg/log" + "github.com/api7/ingress-controller/pkg/metrics" "github.com/api7/ingress-controller/pkg/seven/conf" ) @@ -122,7 +122,7 @@ the apisix cluster and others are created`, kubeClientSet := kube.GetKubeClient() apisixClientset := kube.GetApisixClient() - sharedInformerFactory := api6Informers.NewSharedInformerFactory(apisixClientset, 0) + sharedInformerFactory := api6Informers.NewSharedInformerFactory(apisixClientset, 6.*time.Hour) stop := make(chan struct{}) c := &controller.Api6Controller{ KubeClientSet: kubeClientSet, diff --git a/pkg/ingress/controller/apisix_route.go b/pkg/ingress/controller/apisix_route.go index 9894602d9b..ed8cb06e52 100644 --- a/pkg/ingress/controller/apisix_route.go +++ b/pkg/ingress/controller/apisix_route.go @@ -63,12 +63,12 @@ func BuildApisixRouteController( apisixRouteSynced: api6RouteInformer.Informer().HasSynced, workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemFastSlowRateLimiter(1*time.Second, 60*time.Second, 5), "ApisixRoutes"), } - api6RouteInformer.Informer().AddEventHandler( + api6RouteInformer.Informer().AddEventHandlerWithResyncPeriod( cache.ResourceEventHandlerFuncs{ AddFunc: controller.addFunc, UpdateFunc: controller.updateFunc, DeleteFunc: controller.deleteFunc, - }) + }, 30.*time.Minute) return controller } diff --git a/pkg/ingress/controller/apisix_service.go b/pkg/ingress/controller/apisix_service.go index 474f5de0b4..3d75627565 100644 --- a/pkg/ingress/controller/apisix_service.go +++ b/pkg/ingress/controller/apisix_service.go @@ -57,12 +57,12 @@ func BuildApisixServiceController( apisixServiceSynced: apisixServiceInformer.Informer().HasSynced, workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemFastSlowRateLimiter(1*time.Second, 60*time.Second, 5), "ApisixServices"), } - apisixServiceInformer.Informer().AddEventHandler( + apisixServiceInformer.Informer().AddEventHandlerWithResyncPeriod( cache.ResourceEventHandlerFuncs{ AddFunc: controller.addFunc, UpdateFunc: controller.updateFunc, DeleteFunc: controller.deleteFunc, - }) + }, 2*time.Hour) return controller } diff --git a/pkg/ingress/controller/apisix_tls.go b/pkg/ingress/controller/apisix_tls.go index 0510d14621..c5d28a822b 100644 --- a/pkg/ingress/controller/apisix_tls.go +++ b/pkg/ingress/controller/apisix_tls.go @@ -63,12 +63,12 @@ func BuildApisixTlsController( apisixTlsSynced: apisixTlsInformer.Informer().HasSynced, workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemFastSlowRateLimiter(1*time.Second, 60*time.Second, 5), "ApisixTlses"), } - apisixTlsInformer.Informer().AddEventHandler( + apisixTlsInformer.Informer().AddEventHandlerWithResyncPeriod( cache.ResourceEventHandlerFuncs{ AddFunc: controller.addFunc, UpdateFunc: controller.updateFunc, DeleteFunc: controller.deleteFunc, - }) + }, 30*time.Minute) return controller } diff --git a/pkg/ingress/controller/apisix_upstream.go b/pkg/ingress/controller/apisix_upstream.go index bc08e823df..ea6aa8864f 100644 --- a/pkg/ingress/controller/apisix_upstream.go +++ b/pkg/ingress/controller/apisix_upstream.go @@ -58,12 +58,12 @@ func BuildApisixUpstreamController( apisixUpstreamSynced: apisixUpstreamInformer.Informer().HasSynced, workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemFastSlowRateLimiter(1*time.Second, 60*time.Second, 5), "ApisixUpstreams"), } - apisixUpstreamInformer.Informer().AddEventHandler( + apisixUpstreamInformer.Informer().AddEventHandlerWithResyncPeriod( cache.ResourceEventHandlerFuncs{ AddFunc: controller.addFunc, UpdateFunc: controller.updateFunc, DeleteFunc: controller.deleteFunc, - }) + }, 6*time.Hour) return controller } diff --git a/pkg/ingress/controller/endpoint.go b/pkg/ingress/controller/endpoint.go index 03504cacf2..7c104846d8 100644 --- a/pkg/ingress/controller/endpoint.go +++ b/pkg/ingress/controller/endpoint.go @@ -51,12 +51,12 @@ func BuildEndpointController(kubeclientset kubernetes.Interface) *EndpointContro endpointSynced: kube.EndpointsInformer.Informer().HasSynced, workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "endpoints"), } - kube.EndpointsInformer.Informer().AddEventHandler( + kube.EndpointsInformer.Informer().AddEventHandlerWithResyncPeriod( cache.ResourceEventHandlerFuncs{ AddFunc: controller.addFunc, UpdateFunc: controller.updateFunc, DeleteFunc: controller.deleteFunc, - }) + }, 6*time.Hour) return controller } diff --git a/pkg/kube/init.go b/pkg/kube/init.go index ef167d2949..488bdca24c 100644 --- a/pkg/kube/init.go +++ b/pkg/kube/init.go @@ -15,6 +15,8 @@ package kube import ( + "time" + clientSet "github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned" "k8s.io/client-go/informers" coreinformers "k8s.io/client-go/informers/core/v1" @@ -55,7 +57,7 @@ func InitInformer(cfg *config.Config) error { if err != nil { return err } - CoreSharedInformerFactory = informers.NewSharedInformerFactory(kubeClient, 0) + CoreSharedInformerFactory = informers.NewSharedInformerFactory(kubeClient, 6*time.Hour) return nil }