Merge pull request #103269 from mgutierrez98/Refactor-Master-ControlPlane-test-e2e

Refactor instances of master to controlplane in test/e2e.go
This commit is contained in:
Kubernetes Prow Robot 2021-08-16 10:03:17 -07:00 committed by GitHub
commit c2674bb766
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -275,17 +275,17 @@ func setupSuite() {
// logClusterImageSources writes out cluster image sources. // logClusterImageSources writes out cluster image sources.
func logClusterImageSources() { func logClusterImageSources() {
masterImg, nodeImg, err := lookupClusterImageSources() controlPlaneNodeImg, workerNodeImg, err := lookupClusterImageSources()
if err != nil { if err != nil {
framework.Logf("Cluster image sources lookup failed: %v\n", err) framework.Logf("Cluster image sources lookup failed: %v\n", err)
return return
} }
framework.Logf("cluster-master-image: %s", masterImg) framework.Logf("cluster-control-plane-node-image: %s", controlPlaneNodeImg)
framework.Logf("cluster-node-image: %s", nodeImg) framework.Logf("cluster-worker-node-image: %s", workerNodeImg)
images := map[string]string{ images := map[string]string{
"master_os_image": masterImg, "control_plane_node_os_image": controlPlaneNodeImg,
"node_os_image": nodeImg, "worker_node_os_image": workerNodeImg,
} }
outputBytes, _ := json.MarshalIndent(images, "", " ") outputBytes, _ := json.MarshalIndent(images, "", " ")
@ -298,7 +298,7 @@ func logClusterImageSources() {
// TODO: These should really just use the GCE API client library or at least use // TODO: These should really just use the GCE API client library or at least use
// better formatted output from the --format flag. // better formatted output from the --format flag.
// Returns master & node image string, or error // Returns control plane node & worker node image string, or error
func lookupClusterImageSources() (string, string, error) { func lookupClusterImageSources() (string, string, error) {
// Given args for a gcloud compute command, run it with other args, and return the values, // Given args for a gcloud compute command, run it with other args, and return the values,
// whether separated by newlines, commas or semicolons. // whether separated by newlines, commas or semicolons.
@ -347,35 +347,35 @@ func lookupClusterImageSources() (string, string, error) {
} }
// gcloud compute instance-groups list-instances {GROUPNAME} --format="get(instance)" // gcloud compute instance-groups list-instances {GROUPNAME} --format="get(instance)"
nodeName := "" workerNodeName := ""
instGroupName := strings.Split(framework.TestContext.CloudConfig.NodeInstanceGroup, ",")[0] instGroupName := strings.Split(framework.TestContext.CloudConfig.NodeInstanceGroup, ",")[0]
if lines, err := gcloudf("instance-groups", "list-instances", instGroupName, "--format=get(instance)"); err != nil { if lines, err := gcloudf("instance-groups", "list-instances", instGroupName, "--format=get(instance)"); err != nil {
return "", "", err return "", "", err
} else if len(lines) == 0 { } else if len(lines) == 0 {
return "", "", fmt.Errorf("no instances inside instance-group %q", instGroupName) return "", "", fmt.Errorf("no instances inside instance-group %q", instGroupName)
} else { } else {
nodeName = lines[0] workerNodeName = lines[0]
} }
nodeImg, err := host2image(nodeName) workerNodeImg, err := host2image(workerNodeName)
if err != nil { if err != nil {
return "", "", err return "", "", err
} }
frags := strings.Split(nodeImg, "/") frags := strings.Split(workerNodeImg, "/")
nodeImg = frags[len(frags)-1] workerNodeImg = frags[len(frags)-1]
// For GKE clusters, MasterName will not be defined; we just leave masterImg blank. // For GKE clusters, controlPlaneNodeName will not be defined; we just leave controlPlaneNodeImg blank.
masterImg := "" controlPlaneNodeImg := ""
if masterName := framework.TestContext.CloudConfig.MasterName; masterName != "" { if controlPlaneNodeName := framework.TestContext.CloudConfig.MasterName; controlPlaneNodeName != "" {
img, err := host2image(masterName) img, err := host2image(controlPlaneNodeName)
if err != nil { if err != nil {
return "", "", err return "", "", err
} }
frags = strings.Split(img, "/") frags = strings.Split(img, "/")
masterImg = frags[len(frags)-1] controlPlaneNodeImg = frags[len(frags)-1]
} }
return masterImg, nodeImg, nil return controlPlaneNodeImg, workerNodeImg, nil
} }
// setupSuitePerGinkgoNode is the boilerplate that can be used to setup ginkgo test suites, on the SynchronizedBeforeSuite step. // setupSuitePerGinkgoNode is the boilerplate that can be used to setup ginkgo test suites, on the SynchronizedBeforeSuite step.