Skip to content

Commit

Permalink
parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
ying-zhu committed Oct 5, 2022
1 parent c2ce816 commit 635eafe
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pilot/pkg/model/push_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -1655,15 +1655,33 @@ func (ps *PushContext) initSidecarScopes(env *Environment) error {
// Currently we expect that it has no workloadSelectors
var rootNSConfig *config.Config
ps.sidecarIndex.sidecarsByNamespace = make(map[string][]*SidecarScope, sidecarNum)

for i, sidecarConfig := range sidecarConfigs {
ps.sidecarIndex.sidecarsByNamespace[sidecarConfig.Namespace] = append(ps.sidecarIndex.sidecarsByNamespace[sidecarConfig.Namespace],
ConvertToSidecarScope(ps, &sidecarConfig, sidecarConfig.Namespace))
if rootNSConfig == nil && sidecarConfig.Namespace == ps.Mesh.RootNamespace &&
sidecarConfig.Spec.(*networking.Sidecar).WorkloadSelector == nil {
rootNSConfig = &sidecarConfigs[i]
}
}
ps.sidecarIndex.rootConfig = rootNSConfig

ch := make(chan *SidecarScope)
var wg sync.WaitGroup
for _, sidecarConfig := range sidecarConfigs {
go func(c config.Config) {
defer wg.Done()
ch <- ConvertToSidecarScope(ps, &sidecarConfig, sidecarConfig.Namespace)
}(sidecarConfig)
}

go func() {
wg.Wait()
close(ch)
}()

for sidecarScope := range ch {
ps.sidecarIndex.sidecarsByNamespace[sidecarScope.Namespace] = append(ps.sidecarIndex.sidecarsByNamespace[sidecarScope.Namespace], sidecarScope)
}

log.Infof("[Ying] populate sidecarIndex took %v seconds", time.Since(t))

return nil
Expand Down

0 comments on commit 635eafe

Please sign in to comment.