Skip to content

Commit

Permalink
k8s/watchers: preallocate label map in getNamespaceLabels
Browse files Browse the repository at this point in the history
Avoid under- or overallocating the map and thus increasing memory
pressure.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
  • Loading branch information
tklauser committed Aug 31, 2023
1 parent e0b7e81 commit 1f0c4c3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/k8s/watchers/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ type namespaceUpdater struct {
}

func getNamespaceLabels(ns *slim_corev1.Namespace) labels.Labels {
labelMap := map[string]string{}
for k, v := range ns.GetLabels() {
lbls := ns.GetLabels()
labelMap := make(map[string]string, len(lbls))
for k, v := range lbls {
labelMap[policy.JoinPath(ciliumio.PodNamespaceMetaLabels, k)] = v
}
return labels.Map2Labels(labelMap, labels.LabelSourceK8s)
Expand Down

0 comments on commit 1f0c4c3

Please sign in to comment.