From 71e3fa03b21e58cd81c650a34d2eb67753d4efc8 Mon Sep 17 00:00:00 2001 From: Zhonghu Xu Date: Thu, 18 Jul 2024 15:10:23 +0800 Subject: [PATCH 1/2] remove resync period Signed-off-by: Zhonghu Xu --- pkg/controller/bypass/bypass_controller.go | 9 +++------ pkg/controller/manage/kmesh_manage.go | 10 ++++------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/pkg/controller/bypass/bypass_controller.go b/pkg/controller/bypass/bypass_controller.go index 683756dc2..6a4cc2737 100644 --- a/pkg/controller/bypass/bypass_controller.go +++ b/pkg/controller/bypass/bypass_controller.go @@ -20,7 +20,6 @@ import ( "context" "fmt" "os" - "time" netns "github.com/containernetworking/plugins/pkg/ns" corev1 "k8s.io/api/core/v1" @@ -42,16 +41,14 @@ var ( ) const ( - DefaultInformerSyncPeriod = 30 * time.Second - LabelSelectorBypass = "kmesh.net/bypass=enabled" - KmeshAnnotation = "kmesh.net/redirection" - SidecarAnnotation = "sidecar.istio.io/inject" + KmeshAnnotation = "kmesh.net/redirection" + SidecarAnnotation = "sidecar.istio.io/inject" ) func StartByPassController(client kubernetes.Interface, stopChan <-chan struct{}) error { nodeName := os.Getenv("NODE_NAME") - informerFactory := informers.NewSharedInformerFactoryWithOptions(client, DefaultInformerSyncPeriod, + informerFactory := informers.NewSharedInformerFactoryWithOptions(client, 0, informers.WithTweakListOptions(func(options *metav1.ListOptions) { options.FieldSelector = fmt.Sprintf("spec.nodeName=%s", nodeName) })) diff --git a/pkg/controller/manage/kmesh_manage.go b/pkg/controller/manage/kmesh_manage.go index 000ef3f57..80e55e7c2 100644 --- a/pkg/controller/manage/kmesh_manage.go +++ b/pkg/controller/manage/kmesh_manage.go @@ -21,7 +21,6 @@ import ( "fmt" "os" "strings" - "time" netns "github.com/containernetworking/plugins/pkg/ns" "istio.io/istio/pkg/spiffe" @@ -54,10 +53,9 @@ var ( ) const ( - DefaultInformerSyncPeriod = 2 * time.Second - MaxRetries = 5 - ActionAddAnnotation = "add" - ActionDeleteAnnotation = "delete" + MaxRetries = 5 + ActionAddAnnotation = "add" + ActionDeleteAnnotation = "delete" ) type QueueItem struct { @@ -68,7 +66,7 @@ type QueueItem struct { func NewKmeshManageController(client kubernetes.Interface, security *kmeshsecurity.SecretManager) (*KmeshManageController, error) { nodeName := os.Getenv("NODE_NAME") - informerFactory := informers.NewSharedInformerFactoryWithOptions(client, DefaultInformerSyncPeriod, + informerFactory := informers.NewSharedInformerFactoryWithOptions(client, 0, informers.WithTweakListOptions(func(options *metav1.ListOptions) { options.FieldSelector = fmt.Sprintf("spec.nodeName=%s", nodeName) })) From df1c32c91b2ac03a605b874b8273d1d4bcdf49e1 Mon Sep 17 00:00:00 2001 From: Zhonghu Xu Date: Fri, 19 Jul 2024 11:57:13 +0800 Subject: [PATCH 2/2] Update Signed-off-by: Zhonghu Xu --- pkg/controller/bypass/bypass_controller.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/controller/bypass/bypass_controller.go b/pkg/controller/bypass/bypass_controller.go index 6a4cc2737..8c654555f 100644 --- a/pkg/controller/bypass/bypass_controller.go +++ b/pkg/controller/bypass/bypass_controller.go @@ -41,7 +41,6 @@ var ( ) const ( - KmeshAnnotation = "kmesh.net/redirection" SidecarAnnotation = "sidecar.istio.io/inject" ) @@ -239,7 +238,7 @@ func checkSidecar(client kubernetes.Interface, pod *corev1.Pod) (bool, error) { func isKmeshManaged(pod *corev1.Pod) bool { annotations := pod.Annotations if annotations != nil { - if value, ok := annotations[KmeshAnnotation]; ok && value == "enabled" { + if value, ok := annotations[constants.KmeshRedirectionAnnotation]; ok && value == "enabled" { return true } }