From 9a6da35f4e0919d70be821a6061ab7ec11e6b14b Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Tue, 26 Dec 2023 12:00:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E9=9D=9E=E9=A2=84?= =?UTF-8?q?=E6=9C=9F=E5=90=8C=E6=AD=A5=E7=9A=84=E6=95=B0=E6=8D=AE=E9=A2=91?= =?UTF-8?q?=E7=B9=81=E5=A4=84=E7=90=86=E9=97=AE=E9=A2=98=20(#153)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/controller/configmap.go | 3 +++ pkg/controller/controller.go | 8 ++++---- pkg/controller/service.go | 3 +++ pkg/util/types.go | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/controller/configmap.go b/pkg/controller/configmap.go index d23567d0..f5466650 100644 --- a/pkg/controller/configmap.go +++ b/pkg/controller/configmap.go @@ -231,6 +231,9 @@ func (p *PolarisController) onConfigMapUpdate(old, cur interface{}) { // 5. 如果: [old/not polaris -> new/not polaris] 舍弃 oldIsPolaris := p.IsPolarisConfigMap(oldCm) curIsPolaris := p.IsPolarisConfigMap(curCm) + if !oldIsPolaris && !curIsPolaris { + return + } // 现在已经不是需要同步的北极星配置 if !curIsPolaris { diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 4ef68c4e..a443475f 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -204,14 +204,14 @@ func NewPolarisController( // AllowSyncFromConfigMap 是否开启配置同步从 ConfigMap 到 Polaris func (p *PolarisController) AllowSyncFromConfigMap() bool { - return p.config.PolarisController.ConfigSync.Enable && - p.config.PolarisController.ConfigSync.SyncDirection != util.SyncDirectionPolarisKubernetes + syncDirection := p.config.PolarisController.ConfigSync.SyncDirection + return p.config.PolarisController.ConfigSync.Enable && (syncDirection == util.SyncDirectionKubernetesToPolaris || syncDirection == util.SyncDirectionBoth) } // AllowSyncToConfigMap 是否开启配置同步从 Polaris 到 Kubernetes func (p *PolarisController) AllowSyncToConfigMap() bool { - return p.config.PolarisController.ConfigSync.Enable && - p.config.PolarisController.ConfigSync.SyncDirection != util.SyncDirectionKubernetesToPolaris + syncDirection := p.config.PolarisController.ConfigSync.SyncDirection + return p.config.PolarisController.ConfigSync.Enable && (syncDirection == util.SyncDirectionPolarisToKubernetes || syncDirection == util.SyncDirectionBoth) } func (p *PolarisController) allowDeleteConfig() bool { diff --git a/pkg/controller/service.go b/pkg/controller/service.go index 5bf99b3a..5109accf 100644 --- a/pkg/controller/service.go +++ b/pkg/controller/service.go @@ -54,6 +54,9 @@ func (p *PolarisController) onServiceUpdate(old, current interface{}) { // 5. 如果: [old/not polaris -> new/not polaris] 舍弃 oldIsPolaris := p.IsPolarisService(oldService) curIsPolaris := p.IsPolarisService(curService) + if !oldIsPolaris && !curIsPolaris { + return + } // 现在已经不是需要同步的北极星服务 if !curIsPolaris { diff --git a/pkg/util/types.go b/pkg/util/types.go index 7e5c4fd3..58966a54 100644 --- a/pkg/util/types.go +++ b/pkg/util/types.go @@ -67,7 +67,7 @@ const ( const ( SyncDirectionKubernetesToPolaris = "kubernetesToPolaris" - SyncDirectionPolarisKubernetes = "polarisToKubernetes" + SyncDirectionPolarisToKubernetes = "polarisToKubernetes" SyncDirectionBoth = "both" )