in pkg/networkaware/networkoverhead/networkoverhead.go [444:493]
func (no *NetworkOverhead) populateCostMap(
costMap map[networkawareutil.CostKey]int64,
networkTopology *ntv1alpha1.NetworkTopology,
region string,
zone string) {
for _, w := range networkTopology.Spec.Weights { // Check the weights List
if w.Name != no.weightsName { // If it is not the Preferred algorithm, continue
continue
}
if region != "" { // Add Region Costs
// Binary search through CostList: find the Topology Key for region
topologyList := networkawareutil.FindTopologyKey(w.TopologyList, ntv1alpha1.NetworkTopologyRegion)
if no.weightsName != ntv1alpha1.NetworkTopologyNetperfCosts {
// Sort Costs by origin, might not be sorted since were manually defined
sort.Sort(networkawareutil.ByOrigin(topologyList))
}
// Binary search through TopologyList: find the costs for the given Region
costs := networkawareutil.FindOriginCosts(topologyList, region)
// Add Region Costs
for _, c := range costs {
costMap[networkawareutil.CostKey{ // Add the cost to the map
Origin: region,
Destination: c.Destination}] = c.NetworkCost
}
}
if zone != "" { // Add Zone Costs
// Binary search through CostList: find the Topology Key for zone
topologyList := networkawareutil.FindTopologyKey(w.TopologyList, ntv1alpha1.NetworkTopologyZone)
if no.weightsName != ntv1alpha1.NetworkTopologyNetperfCosts {
// Sort Costs by origin, might not be sorted since were manually defined
sort.Sort(networkawareutil.ByOrigin(topologyList))
}
// Binary search through TopologyList: find the costs for the given Region
costs := networkawareutil.FindOriginCosts(topologyList, zone)
// Add Zone Costs
for _, c := range costs {
costMap[networkawareutil.CostKey{ // Add the cost to the map
Origin: zone,
Destination: c.Destination}] = c.NetworkCost
}
}
}
}