Skip to content

Commit

Permalink
Add comments to improve readability
Browse files Browse the repository at this point in the history
Signed-off-by: Chetan Banavikalmutt <chetanrns1997@gmail.com>
  • Loading branch information
chetan-rns committed Feb 27, 2024
1 parent 9567279 commit b1e7466
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/cache/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ func (c *clusterCache) IterateHierarchy(key kube.ResourceKey, action func(resour
childResources[childRef] = c.resources[childRef]
}
}
// Merge the maps into a different copy to avoid updating the original nsIndex map
nsNodes = mergeResourceMaps(nsNodes, childResources)
}
if !action(res, nsNodes) {
Expand Down Expand Up @@ -1198,6 +1199,8 @@ func (c *clusterCache) onNodeRemoved(key kube.ResourceKey) {
}
}

// mergeResourceMaps merges the given maps into a different copy in order to avoid updates
// to the original maps
func mergeResourceMaps(a, b map[kube.ResourceKey]*Resource) map[kube.ResourceKey]*Resource {
mergedMap := map[kube.ResourceKey]*Resource{}
for k, v := range a {
Expand Down Expand Up @@ -1254,6 +1257,7 @@ func (c *clusterCache) removeFromChildrenByParentMap(key kube.ResourceKey) {
for i, childRef := range childRefs {
childRefKey := kube.NewResourceKey(childRef.Group, childRef.Kind, childRef.Namespace, childRef.Name)
if childRefKey == key {
// remove the childRef that matches the deleted resource
childRefs[i] = childRefs[len(childRefs)-1]
c.childrenByParent[k] = childRefs[:len(childRefs)-1]
}
Expand Down

0 comments on commit b1e7466

Please sign in to comment.