Use gcloud for enabling/disabling autoscaling in e2e tests

This commit is contained in:
Aleksandra Malinowska 2017-10-10 14:42:53 +02:00
parent 6c081c3d53
commit 0078c64d9e

View File

@ -812,10 +812,9 @@ func isAutoscalerEnabled(expectedMaxNodeCountInTargetPool int) (bool, error) {
} }
func enableAutoscaler(nodePool string, minCount, maxCount int) error { func enableAutoscaler(nodePool string, minCount, maxCount int) error {
if nodePool == "default-pool" {
glog.Infof("Using gcloud to enable autoscaling for pool %s", nodePool) glog.Infof("Using gcloud to enable autoscaling for pool %s", nodePool)
output, err := execCmd("gcloud", "alpha", "container", "clusters", "update", framework.TestContext.CloudConfig.Cluster, output, err := execCmd("gcloud", "container", "clusters", "update", framework.TestContext.CloudConfig.Cluster,
"--enable-autoscaling", "--enable-autoscaling",
"--min-nodes="+strconv.Itoa(minCount), "--min-nodes="+strconv.Itoa(minCount),
"--max-nodes="+strconv.Itoa(maxCount), "--max-nodes="+strconv.Itoa(maxCount),
@ -828,27 +827,6 @@ func enableAutoscaler(nodePool string, minCount, maxCount int) error {
return fmt.Errorf("Failed to enable autoscaling: %v", err) return fmt.Errorf("Failed to enable autoscaling: %v", err)
} }
glog.Infof("Config update result: %s", output) glog.Infof("Config update result: %s", output)
} else {
glog.Infof("Using direct api access to enable autoscaling for pool %s", nodePool)
updateRequest := "{" +
" \"update\": {" +
" \"desiredNodePoolId\": \"" + nodePool + "\"," +
" \"desiredNodePoolAutoscaling\": {" +
" \"enabled\": \"true\"," +
" \"minNodeCount\": \"" + strconv.Itoa(minCount) + "\"," +
" \"maxNodeCount\": \"" + strconv.Itoa(maxCount) + "\"" +
" }" +
" }" +
"}"
url := getGKEClusterURL()
glog.Infof("Using gke api url %s", url)
putResult, err := doPut(url, updateRequest)
if err != nil {
return fmt.Errorf("Failed to put %s: %v", url, err)
}
glog.Infof("Config update result: %s", putResult)
}
var finalErr error var finalErr error
for startTime := time.Now(); startTime.Add(gkeUpdateTimeout).After(time.Now()); time.Sleep(30 * time.Second) { for startTime := time.Now(); startTime.Add(gkeUpdateTimeout).After(time.Now()); time.Sleep(30 * time.Second) {
@ -862,11 +840,9 @@ func enableAutoscaler(nodePool string, minCount, maxCount int) error {
} }
func disableAutoscaler(nodePool string, minCount, maxCount int) error { func disableAutoscaler(nodePool string, minCount, maxCount int) error {
if nodePool == "default-pool" {
glog.Infof("Using gcloud to disable autoscaling for pool %s", nodePool) glog.Infof("Using gcloud to disable autoscaling for pool %s", nodePool)
output, err := execCmd("gcloud", "alpha", "container", "clusters", "update", framework.TestContext.CloudConfig.Cluster, output, err := execCmd("gcloud", "container", "clusters", "update", framework.TestContext.CloudConfig.Cluster,
"--no-enable-autoscaling", "--no-enable-autoscaling",
"--node-pool="+nodePool, "--node-pool="+nodePool,
"--project="+framework.TestContext.CloudConfig.ProjectID, "--project="+framework.TestContext.CloudConfig.ProjectID,
@ -878,26 +854,6 @@ func disableAutoscaler(nodePool string, minCount, maxCount int) error {
} }
glog.Infof("Config update result: %s", output) glog.Infof("Config update result: %s", output)
} else {
glog.Infof("Using direct api access to disable autoscaling for pool %s", nodePool)
updateRequest := "{" +
" \"update\": {" +
" \"desiredNodePoolId\": \"" + nodePool + "\"," +
" \"desiredNodePoolAutoscaling\": {" +
" \"enabled\": \"false\"," +
" }" +
" }" +
"}"
url := getGKEClusterURL()
glog.Infof("Using gke api url %s", url)
putResult, err := doPut(url, updateRequest)
if err != nil {
return fmt.Errorf("Failed to put %s: %v", url, err)
}
glog.Infof("Config update result: %s", putResult)
}
var finalErr error var finalErr error
for startTime := time.Now(); startTime.Add(gkeUpdateTimeout).After(time.Now()); time.Sleep(30 * time.Second) { for startTime := time.Now(); startTime.Add(gkeUpdateTimeout).After(time.Now()); time.Sleep(30 * time.Second) {
val, err := isAutoscalerEnabled(maxCount) val, err := isAutoscalerEnabled(maxCount)