mirror of https://github.com/k3s-io/k3s
Merge pull request #55605 from bskiba/e2e-fix
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Regional support in Cluster Autoscaler e2e tests. **What this PR does / why we need it**: When calling GKE API and gcloud in Autoscaling e2 tests, take into account that clusters can be regional. This currently uses MultiZonal as an indicator that cluster is regional, which is suboptimal, but considering that our tests do not work with multizonal clusters at the moment, there is no regression.This should be changed once there is an indicator available that the cluster is regional. **Release note**: ``` NONE ```pull/6/head
commit
48d062722b
|
@ -977,10 +977,18 @@ func getGKEURL(apiVersion string, suffix string) string {
|
|||
}
|
||||
|
||||
func getGKEClusterURL(apiVersion string) string {
|
||||
return getGKEURL(apiVersion, fmt.Sprintf("projects/%s/zones/%s/clusters/%s",
|
||||
framework.TestContext.CloudConfig.ProjectID,
|
||||
framework.TestContext.CloudConfig.Zone,
|
||||
framework.TestContext.CloudConfig.Cluster))
|
||||
if isRegionalCluster() {
|
||||
// TODO(bskiba): Use locations API for all clusters once it's graduated to v1.
|
||||
return getGKEURL(apiVersion, fmt.Sprintf("projects/%s/locations/%s/clusters/%s",
|
||||
framework.TestContext.CloudConfig.ProjectID,
|
||||
framework.TestContext.CloudConfig.Region,
|
||||
framework.TestContext.CloudConfig.Cluster))
|
||||
} else {
|
||||
return getGKEURL(apiVersion, fmt.Sprintf("projects/%s/zones/%s/clusters/%s",
|
||||
framework.TestContext.CloudConfig.ProjectID,
|
||||
framework.TestContext.CloudConfig.Zone,
|
||||
framework.TestContext.CloudConfig.Cluster))
|
||||
}
|
||||
}
|
||||
|
||||
func getCluster(apiVersion string) (string, error) {
|
||||
|
@ -1001,7 +1009,11 @@ func getCluster(apiVersion string) (string, error) {
|
|||
}
|
||||
|
||||
func isAutoscalerEnabled(expectedMaxNodeCountInTargetPool int) (bool, error) {
|
||||
strBody, err := getCluster("v1")
|
||||
apiVersion := "v1"
|
||||
if isRegionalCluster() {
|
||||
apiVersion = "v1beta1"
|
||||
}
|
||||
strBody, err := getCluster(apiVersion)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -1011,16 +1023,43 @@ func isAutoscalerEnabled(expectedMaxNodeCountInTargetPool int) (bool, error) {
|
|||
return false, nil
|
||||
}
|
||||
|
||||
func getClusterLocation() string {
|
||||
if isRegionalCluster() {
|
||||
return "--region=" + framework.TestContext.CloudConfig.Region
|
||||
} else {
|
||||
return "--zone=" + framework.TestContext.CloudConfig.Zone
|
||||
}
|
||||
}
|
||||
|
||||
func getGcloudCommand(commandTrack string, args []string) []string {
|
||||
command := []string{"gcloud"}
|
||||
if commandTrack == "beta" || commandTrack == "alpha" {
|
||||
command = append(command, commandTrack)
|
||||
}
|
||||
command = append(command, args...)
|
||||
command = append(command, getClusterLocation())
|
||||
command = append(command, "--project="+framework.TestContext.CloudConfig.ProjectID)
|
||||
return command
|
||||
}
|
||||
|
||||
func isRegionalCluster() bool {
|
||||
// TODO(bskiba): Use an appropriate indicator that the cluster is regional.
|
||||
return framework.TestContext.CloudConfig.MultiZone
|
||||
}
|
||||
|
||||
func enableAutoscaler(nodePool string, minCount, maxCount int) error {
|
||||
glog.Infof("Using gcloud to enable autoscaling for pool %s", nodePool)
|
||||
|
||||
output, err := execCmd("gcloud", "container", "clusters", "update", framework.TestContext.CloudConfig.Cluster,
|
||||
args := []string{"container", "clusters", "update", framework.TestContext.CloudConfig.Cluster,
|
||||
"--enable-autoscaling",
|
||||
"--min-nodes="+strconv.Itoa(minCount),
|
||||
"--max-nodes="+strconv.Itoa(maxCount),
|
||||
"--node-pool="+nodePool,
|
||||
"--project="+framework.TestContext.CloudConfig.ProjectID,
|
||||
"--zone="+framework.TestContext.CloudConfig.Zone).CombinedOutput()
|
||||
"--min-nodes=" + strconv.Itoa(minCount),
|
||||
"--max-nodes=" + strconv.Itoa(maxCount),
|
||||
"--node-pool=" + nodePool}
|
||||
track := ""
|
||||
if isRegionalCluster() {
|
||||
track = "beta"
|
||||
}
|
||||
output, err := execCmd(getGcloudCommand(track, args)...).CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
glog.Errorf("Failed config update result: %s", output)
|
||||
|
@ -1041,12 +1080,14 @@ func enableAutoscaler(nodePool string, minCount, maxCount int) error {
|
|||
|
||||
func disableAutoscaler(nodePool string, minCount, maxCount int) error {
|
||||
glog.Infof("Using gcloud to disable autoscaling for pool %s", nodePool)
|
||||
|
||||
output, err := execCmd("gcloud", "container", "clusters", "update", framework.TestContext.CloudConfig.Cluster,
|
||||
args := []string{"container", "clusters", "update", framework.TestContext.CloudConfig.Cluster,
|
||||
"--no-enable-autoscaling",
|
||||
"--node-pool="+nodePool,
|
||||
"--project="+framework.TestContext.CloudConfig.ProjectID,
|
||||
"--zone="+framework.TestContext.CloudConfig.Zone).CombinedOutput()
|
||||
"--node-pool=" + nodePool}
|
||||
track := ""
|
||||
if isRegionalCluster() {
|
||||
track = "beta"
|
||||
}
|
||||
output, err := execCmd(getGcloudCommand(track, args)...).CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
glog.Errorf("Failed config update result: %s", output)
|
||||
|
@ -1218,22 +1259,20 @@ func waitTillAllNAPNodePoolsAreRemoved() error {
|
|||
}
|
||||
|
||||
func addNodePool(name string, machineType string, numNodes int) {
|
||||
output, err := execCmd("gcloud", "alpha", "container", "node-pools", "create", name, "--quiet",
|
||||
"--machine-type="+machineType,
|
||||
"--num-nodes="+strconv.Itoa(numNodes),
|
||||
"--project="+framework.TestContext.CloudConfig.ProjectID,
|
||||
"--zone="+framework.TestContext.CloudConfig.Zone,
|
||||
"--cluster="+framework.TestContext.CloudConfig.Cluster).CombinedOutput()
|
||||
args := []string{"container", "node-pools", "create", name, "--quiet",
|
||||
"--machine-type=" + machineType,
|
||||
"--num-nodes=" + strconv.Itoa(numNodes),
|
||||
"--cluster=" + framework.TestContext.CloudConfig.Cluster}
|
||||
output, err := execCmd(getGcloudCommand("alpha", args)...).CombinedOutput()
|
||||
glog.Infof("Creating node-pool %s: %s", name, output)
|
||||
framework.ExpectNoError(err)
|
||||
}
|
||||
|
||||
func deleteNodePool(name string) {
|
||||
glog.Infof("Deleting node pool %s", name)
|
||||
output, err := execCmd("gcloud", "alpha", "container", "node-pools", "delete", name, "--quiet",
|
||||
"--project="+framework.TestContext.CloudConfig.ProjectID,
|
||||
"--zone="+framework.TestContext.CloudConfig.Zone,
|
||||
"--cluster="+framework.TestContext.CloudConfig.Cluster).CombinedOutput()
|
||||
args := []string{"container", "node-pools", "delete", name, "--quiet",
|
||||
"--cluster=" + framework.TestContext.CloudConfig.Cluster}
|
||||
output, err := execCmd(getGcloudCommand("alpha", args)...).CombinedOutput()
|
||||
if err != nil {
|
||||
glog.Infof("Error: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue