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" )