Skip to content

Commit

Permalink
fix:修复非预期同步的数据频繁处理问题 (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Dec 26, 2023
1 parent 2d535c0 commit 9a6da35
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions pkg/controller/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure on line 208 in pkg/controller/controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.21)

line is 155 characters (lll)
}

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

Check failure on line 214 in pkg/controller/controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.21)

line is 155 characters (lll)
}

func (p *PolarisController) allowDeleteConfig() bool {
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const (

const (
SyncDirectionKubernetesToPolaris = "kubernetesToPolaris"
SyncDirectionPolarisKubernetes = "polarisToKubernetes"
SyncDirectionPolarisToKubernetes = "polarisToKubernetes"
SyncDirectionBoth = "both"
)

Expand Down

0 comments on commit 9a6da35

Please sign in to comment.