1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
| func ScaleUp(context *context.AutoscalingContext, processors *ca_processors.AutoscalingProcessors, clusterStateRegistry *clusterstate.ClusterStateRegistry, unschedulablePods []*apiv1.Pod, nodes []*apiv1.Node, daemonSets []*extensionsv1.DaemonSet) (*status.ScaleUpStatus, errors.AutoscalerError) { glog.V(0).Info("kce cloud provider begin scale up ***********************") if len(unschedulablePods) == 0 { glog.V(1).Info("No unschedulable pods") return &status.ScaleUpStatus{ScaledUp: false}, nil } now := time.Now() loggingQuota := glogx.PodsLoggingQuota() podsRemainUnschedulable := make(map[*apiv1.Pod]bool) for _, pod := range unschedulablePods { glogx.V(1).UpTo(loggingQuota).Infof("Pod %s/%s is unschedulable", pod.Namespace, pod.Name) podsRemainUnschedulable[pod] = true } glogx.V(1).Over(loggingQuota).Infof("%v other pods are also unschedulable", -loggingQuota.Left()) nodeInfos, err := GetNodeInfosForGroups(nodes, context.CloudProvider, context.ClientSet, daemonSets, context.PredicateChecker) for k,v := range nodeInfos{ glog.V(0).Infof("kce get nodegroup by all node, nodegroup: %s , nodeinfo: %v", k,v) } if err != nil { return nil, err.AddPrefix("failed to build node infos for node groups: ") } nodesFromNotAutoscaledGroups, err := FilterOutNodesFromNotAutoscaledGroups(nodes, context.CloudProvider) for notGroupNode := range nodesFromNotAutoscaledGroups{ glog.V(0).Infof("kce node not in FilterOutNodesFromNotAutoscaledGroups: node : %v",notGroupNode) } if err != nil { return nil, err.AddPrefix("failed to filter out nodes which are from not autoscaled groups: ") } nodeGroups := context.CloudProvider.NodeGroups() for ng := range nodeGroups{ glog.V(0).Infof("kce provider autoscale node group from yaml : %v",ng) } resourceLimiter, errCP := context.CloudProvider.GetResourceLimiter() glog.V(0).Infof("kce autoscale resource limiter : %v",resourceLimiter) if errCP != nil { return nil, errors.ToAutoscalerError( errors.CloudProviderError, errCP) } scaleUpResourcesLeft, errLimits := computeScaleUpResourcesLeftLimits(nodeGroups, nodeInfos, nodesFromNotAutoscaledGroups, resourceLimiter) glog.V(0).Infof("kce autoscale up resource left : %v",scaleUpResourcesLeft) if errLimits != nil { return nil, errLimits.AddPrefix("Could not compute total resources: ") } upcomingNodes := make([]*schedulercache.NodeInfo, 0) for nodeGroup, numberOfNodes := range clusterStateRegistry.GetUpcomingNodes() { nodeTemplate, found := nodeInfos[nodeGroup] if !found { return nil, errors.NewAutoscalerError( errors.InternalError, "failed to find template node for node group %s", nodeGroup) } for i := 0; i < numberOfNodes; i++ { upcomingNodes = append(upcomingNodes, nodeTemplate) } } for upcomingnode := range upcomingNodes{ glog.V(0).Infof("kce upcoming nodes :", upcomingnode) } podsPassingPredicates := make(map[string][]*apiv1.Pod) expansionOptions := make([]expander.Option, 0) if processors != nil && processors.NodeGroupListProcessor != nil { var errProc error nodeGroups, nodeInfos, errProc = processors.NodeGroupListProcessor.Process(context, nodeGroups, nodeInfos, unschedulablePods) if errProc != nil { return nil, errors.ToAutoscalerError(errors.InternalError, errProc) } } for _, nodeGroup := range nodeGroups { glog.V(0).Info("kce begin foreach nodeGroups : %s",nodeGroup.Id()) if nodeGroup.Exist() && !clusterStateRegistry.IsNodeGroupSafeToScaleUp(nodeGroup.Id(), now) { glog.Warningf("Node group %s is not ready for scaleup", nodeGroup.Id()) continue } currentTargetSize, err := nodeGroup.TargetSize() if err != nil { glog.Errorf("Failed to get node group size: %v", err) continue } if currentTargetSize >= nodeGroup.MaxSize() { glog.V(4).Infof("Skipping node group %s - max size reached", nodeGroup.Id()) continue } nodeInfo, found := nodeInfos[nodeGroup.Id()] if !found { glog.Errorf("No node info (kce template info) for: %s", nodeGroup.Id()) continue } glog.V(0).Infof("kce begin compute scale up resources delta, nodeGroup : %s ,nodeInfo : %v, resourceLimiter : %v", nodeGroup.Id(),nodeInfo,resourceLimiter) scaleUpResourcesDelta, err := computeScaleUpResourcesDelta(nodeInfo, nodeGroup, resourceLimiter) if err != nil { glog.Errorf("Skipping node group %s; error getting node group resources: %v", nodeGroup.Id(), err) continue } for k,v := range scaleUpResourcesDelta{ glog.V(0).Infof("kce complate compute scale up resources delta key : %s ,value : %v ",k,v) } checkResult := scaleUpResourcesLeft.checkScaleUpDeltaWithinLimits(scaleUpResourcesDelta) if checkResult.exceeded { glog.V(4).Infof("Skipping node group %s; maximal limit exceeded for %v", nodeGroup.Id(), checkResult.exceededResources) continue } glog.V(0).Infof("kce scaleUpResourcesLeft node group %s; maximal limit exceeded for %v", nodeGroup.Id(), checkResult.exceededResources) option := expander.Option{ NodeGroup: nodeGroup, Pods: make([]*apiv1.Pod, 0), } glog.V(0).Info("kce unscheduler pod begin scheduler test... nodeGroup : %s ,nodeInfo : %v",nodeGroup.Id(),nodeInfo) option.Pods = FilterSchedulablePodsForNode(context, unschedulablePods, nodeGroup.Id(), nodeInfo) for _, pod := range option.Pods { glogx.V(1).UpTo(loggingQuota).Infof("Option Pod %s/%s will be scheduler ", pod.Namespace, pod.Name) podsRemainUnschedulable[pod] = false } passingPods := make([]*apiv1.Pod, len(option.Pods)) copy(passingPods, option.Pods) podsPassingPredicates[nodeGroup.Id()] = passingPods if len(option.Pods) > 0 { if context.EstimatorName == estimator.BinpackingEstimatorName { binpackingEstimator := estimator.NewBinpackingNodeEstimator(context.PredicateChecker) option.NodeCount = binpackingEstimator.Estimate(option.Pods, nodeInfo, upcomingNodes) glog.V(0).Info("kce pod base estimator need node count : ",option.NodeCount) } else if context.EstimatorName == estimator.BasicEstimatorName { basicEstimator := estimator.NewBasicNodeEstimator() for _, pod := range option.Pods { basicEstimator.Add(pod) } option.NodeCount, option.Debug = basicEstimator.Estimate(nodeInfo.Node(), upcomingNodes) glog.V(0).Info("kce pod binpacking estimator : ",option.Debug) glog.V(0).Info("kce pod binpacking estimator need node count : ",option.NodeCount) } else { glog.Fatalf("Unrecognized estimator: %s", context.EstimatorName) } if option.NodeCount > 0 { expansionOptions = append(expansionOptions, option) } else { glog.V(0).Infof("No need for any nodes in %s", nodeGroup.Id()) } } else { glog.V(0).Infof("No pod can fit to %s", nodeGroup.Id()) } } if len(expansionOptions) == 0 { glog.V(1).Info("No expansion options") return &status.ScaleUpStatus{ScaledUp: false, PodsRemainUnschedulable: getRemainingPods(podsRemainUnschedulable)}, nil } bestOption := context.ExpanderStrategy.BestOption(expansionOptions, nodeInfos) if bestOption != nil && bestOption.NodeCount > 0 { glog.V(0).Infof("Best option to resize: %s", bestOption.NodeGroup.Id()) if len(bestOption.Debug) > 0 { glog.V(0).Info(bestOption.Debug) } glog.V(0).Infof("Estimated %d nodes needed in %s", bestOption.NodeCount, bestOption.NodeGroup.Id()) newNodes := bestOption.NodeCount if context.MaxNodesTotal > 0 && len(nodes)+newNodes > context.MaxNodesTotal { glog.V(0).Infof("Capping size to max cluster total size (%d)", context.MaxNodesTotal) newNodes = context.MaxNodesTotal - len(nodes) if newNodes < 1 { return nil, errors.NewAutoscalerError( errors.TransientError, "max node total count already reached") } } if !bestOption.NodeGroup.Exist() { oldId := bestOption.NodeGroup.Id() bestOption.NodeGroup, err = processors.NodeGroupManager.CreateNodeGroup(context, bestOption.NodeGroup) if err != nil { return nil, err } if oldId != bestOption.NodeGroup.Id() { podsPassingPredicates[bestOption.NodeGroup.Id()] = podsPassingPredicates[oldId] delete(podsPassingPredicates, oldId) nodeInfos[bestOption.NodeGroup.Id()] = nodeInfos[oldId] delete(nodeInfos, oldId) } } nodeInfo, found := nodeInfos[bestOption.NodeGroup.Id()] if !found { glog.Errorf("No node info for: %s", bestOption.NodeGroup.Id()) return nil, errors.NewAutoscalerError( errors.CloudProviderError, "No node info for best expansion option!") } newNodes, err = applyScaleUpResourcesLimits(newNodes, scaleUpResourcesLeft, nodeInfo, bestOption.NodeGroup, resourceLimiter) if err != nil { return nil, err } targetNodeGroups := []cloudprovider.NodeGroup{bestOption.NodeGroup} if context.BalanceSimilarNodeGroups { similarNodeGroups, typedErr := nodegroupset.FindSimilarNodeGroups(bestOption.NodeGroup, context.CloudProvider, nodeInfos) if typedErr != nil { return nil, typedErr.AddPrefix("Failed to find matching node groups: ") } similarNodeGroups = filterNodeGroupsByPods(similarNodeGroups, bestOption.Pods, podsPassingPredicates) glog.V(0).Infof("kce fine node similar group %v ", similarNodeGroups) for _, ng := range similarNodeGroups { if clusterStateRegistry.IsNodeGroupSafeToScaleUp(ng.Id(), now) { targetNodeGroups = append(targetNodeGroups, ng) } else { glog.V(2).Infof("Ignoring node group %s when balancing: group is not ready for scaleup", ng.Id()) } } if len(targetNodeGroups) > 1 { var buffer bytes.Buffer for i, ng := range targetNodeGroups { if i > 0 { buffer.WriteString(", ") } buffer.WriteString(ng.Id()) } glog.V(0).Infof("Splitting scale-up between %v similar node groups: {%v}", len(targetNodeGroups), buffer.String()) } } scaleUpInfos, typedErr := nodegroupset.BalanceScaleUpBetweenGroups( targetNodeGroups, newNodes) if typedErr != nil { return nil, typedErr } glog.V(0).Infof("Final scale-up plan: %v", scaleUpInfos) for _, info := range scaleUpInfos { typedErr := executeScaleUp(context, clusterStateRegistry, info, gpu.GetGpuTypeForMetrics(nodeInfo.Node(), nil)) if typedErr != nil { return nil, typedErr } } clusterStateRegistry.Recalculate() glog.V(0).Info("kce cloud provider end scale up ***********************") return &status.ScaleUpStatus{ ScaledUp: true, ScaleUpInfos: scaleUpInfos, PodsRemainUnschedulable: getRemainingPods(podsRemainUnschedulable), PodsTriggeredScaleUp: bestOption.Pods, PodsAwaitEvaluation: getPodsAwaitingEvaluation(unschedulablePods, podsRemainUnschedulable, bestOption.Pods)}, nil } return &status.ScaleUpStatus{ScaledUp: false, PodsRemainUnschedulable: getRemainingPods(podsRemainUnschedulable)}, nil }
|