()
| 57 | } |
| 58 | |
| 59 | func getWorkerNodeInfos() ([]schema.WorkerNodeInfo, int, error) { |
| 60 | pods, err := config.K8sAllNamspaces.ListPods(nil) |
| 61 | if err != nil { |
| 62 | return nil, 0, err |
| 63 | } |
| 64 | |
| 65 | nodes, err := config.K8sAllNamspaces.ListNodesByLabel("workload", "true") |
| 66 | if err != nil { |
| 67 | return nil, 0, err |
| 68 | } |
| 69 | |
| 70 | nodeInfoMap := make(map[string]*schema.WorkerNodeInfo, len(nodes)) // node name -> info |
| 71 | spotPriceCache := make(map[string]float64) // instance type -> spot price |
| 72 | |
| 73 | for i := range nodes { |
| 74 | node := nodes[i] |
| 75 | |
| 76 | instanceType := node.Labels["node.kubernetes.io/instance-type"] |
| 77 | nodeGroupName := node.Labels["alpha.eksctl.io/nodegroup-name"] |
| 78 | isSpot := node.Labels["node-lifecycle"] == "spot" |
| 79 | |
| 80 | price := aws.InstanceMetadatas[config.ClusterConfig.Region][instanceType].Price |
| 81 | if isSpot { |
| 82 | if spotPrice, ok := spotPriceCache[instanceType]; ok { |
| 83 | price = spotPrice |
| 84 | } else { |
| 85 | spotPrice, err := config.AWS.SpotInstancePrice(instanceType) |
| 86 | if err == nil && spotPrice != 0 { |
| 87 | price = spotPrice |
| 88 | spotPriceCache[instanceType] = spotPrice |
| 89 | } else { |
| 90 | spotPriceCache[instanceType] = price // the request failed, so no need to try again in the future |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | nodeInfoMap[node.Name] = &schema.WorkerNodeInfo{ |
| 96 | NodeInfo: schema.NodeInfo{ |
| 97 | NodeGroupName: nodeGroupName, |
| 98 | InstanceType: instanceType, |
| 99 | IsSpot: isSpot, |
| 100 | Price: price, |
| 101 | }, |
| 102 | Name: node.Name, |
| 103 | NumReplicas: 0, // will be added to below |
| 104 | ComputeUserCapacity: nodeComputeAllocatable(&node), // will be subtracted from below |
| 105 | ComputeAvailable: nodeComputeAllocatable(&node), // will be subtracted from below |
| 106 | ComputeUserRequested: userconfig.ZeroCompute(), // will be added to below |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | var numPendingReplicas int |
| 111 | |
| 112 | for i := range pods { |
| 113 | pod := pods[i] |
| 114 | |
| 115 | if pod.Status.Phase == kcore.PodSucceeded || pod.Status.Phase == kcore.PodFailed { |
| 116 | // note: pending pods can be scheduled on nodes (image pull in progress) |
no test coverage detected