本文整理汇总了Golang中k8s/io/contrib/cluster-autoscaler/utils/gce.GceManager.DeleteInstances方法的典型用法代码示例。如果您正苦于以下问题:Golang GceManager.DeleteInstances方法的具体用法?Golang GceManager.DeleteInstances怎么用?Golang GceManager.DeleteInstances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类k8s/io/contrib/cluster-autoscaler/utils/gce.GceManager
的用法示例。
在下文中一共展示了GceManager.DeleteInstances方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ScaleDown
// ScaleDown tries to scale down the cluster. It returns ScaleDownResult indicating if any node was
// removed and error if such occured.
func ScaleDown(
nodes []*kube_api.Node,
unneededNodes map[string]time.Time,
unneededTime time.Duration,
pods []*kube_api.Pod,
gceManager *gce.GceManager,
client *kube_client.Client,
predicateChecker *simulator.PredicateChecker) (ScaleDownResult, error) {
now := time.Now()
candidates := make([]*kube_api.Node, 0)
for _, node := range nodes {
if val, found := unneededNodes[node.Name]; found {
glog.V(2).Infof("%s was unneeded for %s", node.Name, now.Sub(val).String())
// Check how long the node was underutilized.
if !val.Add(unneededTime).Before(now) {
continue
}
// Check mig size.
instance, err := config.InstanceConfigFromProviderId(node.Spec.ProviderID)
if err != nil {
glog.Errorf("Error while parsing providerid of %s: %v", node.Name, err)
continue
}
migConfig, err := gceManager.GetMigForInstance(instance)
if err != nil {
glog.Errorf("Error while checking mig config for instance %v: %v", instance, err)
continue
}
size, err := gceManager.GetMigSize(migConfig)
if err != nil {
glog.Errorf("Error while checking mig size for instance %v: %v", instance, err)
continue
}
if size <= int64(migConfig.MinSize) {
glog.V(1).Infof("Skipping %s - mig min size reached", node.Name)
continue
}
candidates = append(candidates, node)
}
}
if len(candidates) == 0 {
glog.Infof("No candidates for scale down")
return ScaleDownNoUnneeded, nil
}
nodesToRemove, err := simulator.FindNodesToRemove(candidates, nodes, pods, client, predicateChecker, 1, false)
if err != nil {
return ScaleDownError, fmt.Errorf("Find node to remove failed: %v", err)
}
if len(nodesToRemove) == 0 {
glog.V(1).Infof("No node to remove")
return ScaleDownNoNodeDeleted, nil
}
nodeToRemove := nodesToRemove[0]
glog.Infof("Removing %s", nodeToRemove.Name)
instanceConfig, err := config.InstanceConfigFromProviderId(nodeToRemove.Spec.ProviderID)
if err != nil {
return ScaleDownError, fmt.Errorf("Failed to get instance config for %s: %v", nodeToRemove.Name, err)
}
err = gceManager.DeleteInstances([]*config.InstanceConfig{instanceConfig})
if err != nil {
return ScaleDownError, fmt.Errorf("Failed to delete %v: %v", instanceConfig, err)
}
return ScaleDownNodeDeleted, nil
}