Skip to content

Commit 3421ae3

Browse files
authored
fix concurrent write map issue in egctl (#6628)
Signed-off-by: zirain <[email protected]>
1 parent 4f96691 commit 3421ae3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

internal/cmd/egctl/config.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ var (
3737
)
3838

3939
const (
40-
adminPort = 19000 // TODO: make this configurable until EG support
41-
rateLimitDebugPort = 6070 // TODO: make this configurable until EG support
42-
containerName = "envoy" // TODO: make this configurable until EG support
40+
adminPort = 19000 // TODO: make this configurable until EG support
41+
rateLimitDebugPort = 6070 // TODO: make this configurable until EG support
4342
)
4443

4544
type aggregatedConfigDump map[string]map[string]protoreflect.ProtoMessage
@@ -67,7 +66,8 @@ func retrieveConfigDump(args []string, includeEds bool, configType envoyConfigTy
6766
return nil, err
6867
}
6968

70-
podConfigDumps := make(aggregatedConfigDump, 0)
69+
podConfigDumps := make(aggregatedConfigDump)
70+
mu := sync.Mutex{}
7171
// Initialize the map with namespaces
7272
for _, pod := range pods {
7373
if _, ok := podConfigDumps[pod.Namespace]; !ok {
@@ -99,7 +99,9 @@ func retrieveConfigDump(args []string, includeEds bool, configType envoyConfigTy
9999
return
100100
}
101101

102+
mu.Lock()
102103
podConfigDumps[pod.Namespace][pod.Name] = configDump
104+
mu.Unlock()
103105
}()
104106
}
105107

@@ -167,7 +169,7 @@ func fetchRunningEnvoyPods(c kube.CLIClient, nn types.NamespacedName, labelSelec
167169
pods = podList.Items
168170
}
169171

170-
podsNamespacedNames := []types.NamespacedName{}
172+
podsNamespacedNames := make([]types.NamespacedName, 0, len(pods))
171173
for _, pod := range pods {
172174
podNsName := utils.NamespacedName(&pod)
173175
if pod.Status.Phase != "Running" {

0 commit comments

Comments
 (0)