in pkg/networkaware/networkoverhead/networkoverhead.go [571:633]
func (no *NetworkOverhead) getAccumulatedCost(
scheduledList networkawareutil.ScheduledList,
dependencyList []agv1alpha1.DependenciesInfo,
nodeName string,
region string,
zone string,
costMap map[networkawareutil.CostKey]int64) (int64, error) {
// keep track of the accumulated cost
var cost int64 = 0
// calculate accumulated shortest path
for _, podAllocated := range scheduledList { // For each pod already allocated
for _, d := range dependencyList { // For each pod dependency
// If the pod allocated is not an established dependency, continue.
if podAllocated.Selector != d.Workload.Selector {
continue
}
if podAllocated.Hostname == nodeName { // If the Pod hostname is the node being scored
cost += SameHostname
} else { // If Nodes are not the same
// Get NodeInfo from pod Hostname
podNodeInfo, err := no.handle.SnapshotSharedLister().NodeInfos().Get(podAllocated.Hostname)
if err != nil {
klog.ErrorS(nil, "getting pod hostname %q from Snapshot: %v", podNodeInfo, err)
return cost, err
}
// Get zone and region from Pod Hostname
regionPodNodeInfo := networkawareutil.GetNodeRegion(podNodeInfo.Node())
zonePodNodeInfo := networkawareutil.GetNodeZone(podNodeInfo.Node())
if regionPodNodeInfo == "" && zonePodNodeInfo == "" { // Node has no zone and region defined
cost += MaxCost
} else if region == regionPodNodeInfo { // If Nodes belong to the same region
if zone == zonePodNodeInfo { // If Nodes belong to the same zone
cost += SameZone
} else { // belong to a different zone
value, ok := costMap[networkawareutil.CostKey{ // Retrieve the cost from the map (origin: zone, destination: pod zoneHostname)
Origin: zone, // Time Complexity: O(1)
Destination: zonePodNodeInfo,
}]
if ok {
cost += value // Add the cost to the sum
} else {
cost += MaxCost
}
}
} else { // belong to a different region
value, ok := costMap[networkawareutil.CostKey{ // Retrieve the cost from the map (origin: region, destination: pod regionHostname)
Origin: region, // Time Complexity: O(1)
Destination: regionPodNodeInfo,
}]
if ok {
cost += value // Add the cost to the sum
} else {
cost += MaxCost
}
}
}
}
}
return cost, nil
}