Skip to content

Commit

Permalink
fix:修复没有触发fetchConfigFiles逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Dec 26, 2023
1 parent 524365c commit 7cc9762
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions pkg/controller/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,11 @@ func (p *PolarisConfigWatcher) doRecv(ctx context.Context) {
default:
msg, err := discoverClient.Recv()
if err != nil {
log.SyncConfigMapScope().Info("receive fetch config resource fail", zap.Error(err))
log.SyncConfigMapScope().Error("receive fetch config resource fail", zap.Error(err))
continue
}

log.SyncConfigMapScope().Infof("receive fetch config resource for type(%v) code(%d)",
log.SyncConfigMapScope().Debugf("receive fetch config resource for type(%v) code(%d)",
msg.GetType().String(), msg.GetCode())
if msg.Code != uint32(apimodel.Code_ExecuteSuccess) {
continue
Expand Down Expand Up @@ -471,7 +471,8 @@ func (p *PolarisConfigWatcher) receiveGroups(resp *config_manage.ConfigDiscoverR
return
}

p.groupRevisions.Store(resp.GetConfigFile().GetNamespace().GetValue(), resp.GetRevision())
nsVal := resp.GetConfigFile().GetNamespace().GetValue()
p.groupRevisions.Store(nsVal, resp.GetRevision())
for i := range groups {
item := groups[i]
nsName := item.GetNamespace().GetValue()
Expand All @@ -484,6 +485,12 @@ func (p *PolarisConfigWatcher) receiveGroups(resp *config_manage.ConfigDiscoverR
return util.NewSyncMap[string, *configFileRefrence]()
})
}

if nsBucket, ok := p.groups.Load(nsVal); ok {
nsBucket.Range(func(groupName string) {
p.fetchConfigFiles(nsVal, groupName)
})
}
}

func (p *PolarisConfigWatcher) fetchConfigFiles(namespace, group string) {
Expand All @@ -510,6 +517,8 @@ func (p *PolarisConfigWatcher) receiveConfigFiles(resp *config_manage.ConfigDisc
return
}

log.SyncConfigMapScope().Debugf("begin fetch config files, count %d", len(resp.GetConfigFileNames()))

var (
start = time.Now()
wait = &sync.WaitGroup{}
Expand All @@ -525,6 +534,9 @@ func (p *PolarisConfigWatcher) receiveConfigFiles(resp *config_manage.ConfigDisc
nsBucket, _ := p.needSyncFiles.Load(nsName)
groupBucket, _ := nsBucket.Load(groupName)
if p.allowSyncToConfigMap(item) {
log.SyncConfigMapScope().Info("fetch config file", zap.String("namespace", nsName),
zap.String("group", groupName), zap.String("file", fileName),
zap.Uint64("version", item.GetVersion().Value))
val, isNew := groupBucket.ComputeIfAbsent(fileName, func(k string) *configFileRefrence {
return &configFileRefrence{
Revision: 0,
Expand All @@ -534,8 +546,6 @@ func (p *PolarisConfigWatcher) receiveConfigFiles(resp *config_manage.ConfigDisc
val.Revision = item.GetVersion().Value
groupBucket.Store(fileName, val)
wait.Add(1)
log.SyncConfigMapScope().Info("begin fetch config file", zap.String("namespace", nsName),
zap.String("group", groupName), zap.String("file", fileName), zap.Uint64("cur-version", val.Revision))
// 异步任务进行任务处理
p.executor.Execute(func() {
defer wait.Done()
Expand All @@ -544,6 +554,8 @@ func (p *PolarisConfigWatcher) receiveConfigFiles(resp *config_manage.ConfigDisc
})
}
} else {
log.SyncConfigMapScope().Info("remove config file", zap.String("namespace", nsName),
zap.String("group", groupName), zap.String("file", fileName))
delCnt.Add(1)
groupBucket.Delete(fileName)
err := p.k8sClient.CoreV1().ConfigMaps(nsName).Delete(context.Background(),
Expand Down

0 comments on commit 7cc9762

Please sign in to comment.