本文整理匯總了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
}