k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/test/e2e/framework/providers/gcp.go (about) 1 /* 2 Copyright 2014 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package providers 18 19 import ( 20 "context" 21 "fmt" 22 "path" 23 24 "k8s.io/kubernetes/test/e2e/framework" 25 e2enode "k8s.io/kubernetes/test/e2e/framework/node" 26 ) 27 28 // LocationParamGKE returns parameter related to location for gcloud command. 29 func LocationParamGKE() string { 30 if framework.TestContext.CloudConfig.MultiMaster { 31 // GKE Regional Clusters are being tested. 32 return fmt.Sprintf("--region=%s", framework.TestContext.CloudConfig.Region) 33 } 34 return fmt.Sprintf("--zone=%s", framework.TestContext.CloudConfig.Zone) 35 } 36 37 // MasterUpgradeGKE upgrades master node to the specified version on GKE. 38 func MasterUpgradeGKE(ctx context.Context, namespace string, v string) error { 39 framework.Logf("Upgrading master to %q", v) 40 args := []string{ 41 "container", 42 "clusters", 43 fmt.Sprintf("--project=%s", framework.TestContext.CloudConfig.ProjectID), 44 LocationParamGKE(), 45 "upgrade", 46 framework.TestContext.CloudConfig.Cluster, 47 "--master", 48 fmt.Sprintf("--cluster-version=%s", v), 49 "--quiet", 50 } 51 _, _, err := framework.RunCmd("gcloud", framework.AppendContainerCommandGroupIfNeeded(args)...) 52 if err != nil { 53 return err 54 } 55 56 e2enode.WaitForSSHTunnels(ctx, namespace) 57 58 return nil 59 } 60 61 // GCEUpgradeScript returns path of script for upgrading on GCE. 62 func GCEUpgradeScript() string { 63 if len(framework.TestContext.GCEUpgradeScript) == 0 { 64 return path.Join(framework.TestContext.RepoRoot, "cluster/gce/upgrade.sh") 65 } 66 return framework.TestContext.GCEUpgradeScript 67 }