Merge pull request #86796 from tanjunchen/remove-unused-code-test/e2e/framework/google_compute.go
remove unused code test/e2e/framework/google_compute.go
This commit is contained in:
		@@ -129,84 +129,3 @@ func LogClusterImageSources() {
 | 
				
			|||||||
		Logf("cluster images sources, could not write to %q: %v", filePath, err)
 | 
							Logf("cluster images sources, could not write to %q: %v", filePath, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
// CreateManagedInstanceGroup creates a Compute Engine managed instance group.
 | 
					 | 
				
			||||||
func CreateManagedInstanceGroup(size int64, zone, template string) error {
 | 
					 | 
				
			||||||
	// TODO(verult): make this hit the compute API directly instead of
 | 
					 | 
				
			||||||
	// shelling out to gcloud.
 | 
					 | 
				
			||||||
	_, _, err := retryCmd("gcloud", "compute", "instance-groups", "managed",
 | 
					 | 
				
			||||||
		"create",
 | 
					 | 
				
			||||||
		fmt.Sprintf("--project=%s", TestContext.CloudConfig.ProjectID),
 | 
					 | 
				
			||||||
		fmt.Sprintf("--zone=%s", zone),
 | 
					 | 
				
			||||||
		TestContext.CloudConfig.NodeInstanceGroup,
 | 
					 | 
				
			||||||
		fmt.Sprintf("--size=%d", size),
 | 
					 | 
				
			||||||
		fmt.Sprintf("--template=%s", template))
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return fmt.Errorf("gcloud compute instance-groups managed create call failed with err: %v", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// GetManagedInstanceGroupTemplateName returns the list of Google Compute Engine managed instance groups.
 | 
					 | 
				
			||||||
func GetManagedInstanceGroupTemplateName(zone string) (string, error) {
 | 
					 | 
				
			||||||
	// TODO(verult): make this hit the compute API directly instead of
 | 
					 | 
				
			||||||
	// shelling out to gcloud. Use InstanceGroupManager to get Instance Template name.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	stdout, _, err := retryCmd("gcloud", "compute", "instance-groups", "managed",
 | 
					 | 
				
			||||||
		"list",
 | 
					 | 
				
			||||||
		fmt.Sprintf("--filter=name:%s", TestContext.CloudConfig.NodeInstanceGroup),
 | 
					 | 
				
			||||||
		fmt.Sprintf("--project=%s", TestContext.CloudConfig.ProjectID),
 | 
					 | 
				
			||||||
		fmt.Sprintf("--zones=%s", zone),
 | 
					 | 
				
			||||||
	)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return "", fmt.Errorf("gcloud compute instance-groups managed list call failed with err: %v", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	templateName, err := parseInstanceTemplateName(stdout)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return "", fmt.Errorf("error parsing gcloud output: %v", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return templateName, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// DeleteManagedInstanceGroup deletes Google Compute Engine managed instance group.
 | 
					 | 
				
			||||||
func DeleteManagedInstanceGroup(zone string) error {
 | 
					 | 
				
			||||||
	// TODO(verult): make this hit the compute API directly instead of
 | 
					 | 
				
			||||||
	// shelling out to gcloud.
 | 
					 | 
				
			||||||
	_, _, err := retryCmd("gcloud", "compute", "instance-groups", "managed",
 | 
					 | 
				
			||||||
		"delete",
 | 
					 | 
				
			||||||
		fmt.Sprintf("--project=%s", TestContext.CloudConfig.ProjectID),
 | 
					 | 
				
			||||||
		fmt.Sprintf("--zone=%s", zone),
 | 
					 | 
				
			||||||
		TestContext.CloudConfig.NodeInstanceGroup)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return fmt.Errorf("gcloud compute instance-groups managed delete call failed with err: %v", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func parseInstanceTemplateName(gcloudOutput string) (string, error) {
 | 
					 | 
				
			||||||
	const templateNameField = "INSTANCE_TEMPLATE"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	lines := strings.Split(gcloudOutput, "\n")
 | 
					 | 
				
			||||||
	if len(lines) <= 1 { // Empty output or only contains column names
 | 
					 | 
				
			||||||
		return "", fmt.Errorf("the list is empty")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Otherwise, there should be exactly 1 entry, i.e. 2 lines
 | 
					 | 
				
			||||||
	fieldNames := strings.Fields(lines[0])
 | 
					 | 
				
			||||||
	instanceTemplateColumn := 0
 | 
					 | 
				
			||||||
	for instanceTemplateColumn < len(fieldNames) &&
 | 
					 | 
				
			||||||
		fieldNames[instanceTemplateColumn] != templateNameField {
 | 
					 | 
				
			||||||
		instanceTemplateColumn++
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if instanceTemplateColumn == len(fieldNames) {
 | 
					 | 
				
			||||||
		return "", fmt.Errorf("the list does not contain instance template information")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	fields := strings.Fields(lines[1])
 | 
					 | 
				
			||||||
	instanceTemplateName := fields[instanceTemplateColumn]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return instanceTemplateName, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1714,22 +1714,6 @@ func RunCmdEnv(env []string, command string, args ...string) (string, string, er
 | 
				
			|||||||
	return stdout, stderr, nil
 | 
						return stdout, stderr, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// retryCmd runs cmd using args and retries it for up to SingleCallTimeout if
 | 
					 | 
				
			||||||
// it returns an error. It returns stdout and stderr.
 | 
					 | 
				
			||||||
func retryCmd(command string, args ...string) (string, string, error) {
 | 
					 | 
				
			||||||
	var err error
 | 
					 | 
				
			||||||
	stdout, stderr := "", ""
 | 
					 | 
				
			||||||
	wait.Poll(Poll, SingleCallTimeout, func() (bool, error) {
 | 
					 | 
				
			||||||
		stdout, stderr, err = RunCmd(command, args...)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			Logf("Got %v", err)
 | 
					 | 
				
			||||||
			return false, nil
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return true, nil
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
	return stdout, stderr, err
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// E2ETestNodePreparer implements testutils.TestNodePreparer interface, which is used
 | 
					// E2ETestNodePreparer implements testutils.TestNodePreparer interface, which is used
 | 
				
			||||||
// to create/modify Nodes before running a test.
 | 
					// to create/modify Nodes before running a test.
 | 
				
			||||||
type E2ETestNodePreparer struct {
 | 
					type E2ETestNodePreparer struct {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user