mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Modified regional PD test to fetch template name from GCE
This commit is contained in:
parent
65a819338a
commit
82f9d9365e
@ -145,6 +145,28 @@ func CreateManagedInstanceGroup(size int64, zone, template string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
func DeleteManagedInstanceGroup(zone string) error {
|
func DeleteManagedInstanceGroup(zone string) error {
|
||||||
// TODO(verult): make this hit the compute API directly instead of
|
// TODO(verult): make this hit the compute API directly instead of
|
||||||
// shelling out to gcloud.
|
// shelling out to gcloud.
|
||||||
@ -158,3 +180,29 @@ func DeleteManagedInstanceGroup(zone string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
@ -205,6 +205,9 @@ func testZonalFailover(c clientset.Interface, ns string) {
|
|||||||
instanceGroup, err := cloud.GetInstanceGroup(instanceGroupName, podZone)
|
instanceGroup, err := cloud.GetInstanceGroup(instanceGroupName, podZone)
|
||||||
Expect(err).NotTo(HaveOccurred(),
|
Expect(err).NotTo(HaveOccurred(),
|
||||||
"Error getting instance group %s in zone %s", instanceGroupName, podZone)
|
"Error getting instance group %s in zone %s", instanceGroupName, podZone)
|
||||||
|
templateName, err := framework.GetManagedInstanceGroupTemplateName(podZone)
|
||||||
|
Expect(err).NotTo(HaveOccurred(),
|
||||||
|
"Error getting instance group template in zone %s", podZone)
|
||||||
err = framework.DeleteManagedInstanceGroup(podZone)
|
err = framework.DeleteManagedInstanceGroup(podZone)
|
||||||
Expect(err).NotTo(HaveOccurred(),
|
Expect(err).NotTo(HaveOccurred(),
|
||||||
"Error deleting instance group in zone %s", podZone)
|
"Error deleting instance group in zone %s", podZone)
|
||||||
@ -212,9 +215,6 @@ func testZonalFailover(c clientset.Interface, ns string) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
framework.Logf("recreating instance group %s", instanceGroup.Name)
|
framework.Logf("recreating instance group %s", instanceGroup.Name)
|
||||||
|
|
||||||
// HACK improve this when Managed Instance Groups are available through the cloud provider API
|
|
||||||
templateName := strings.Replace(instanceGroupName, "group", "template", 1 /* n */)
|
|
||||||
|
|
||||||
framework.ExpectNoError(framework.CreateManagedInstanceGroup(instanceGroup.Size, podZone, templateName),
|
framework.ExpectNoError(framework.CreateManagedInstanceGroup(instanceGroup.Size, podZone, templateName),
|
||||||
"Error recreating instance group %s in zone %s", instanceGroup.Name, podZone)
|
"Error recreating instance group %s in zone %s", instanceGroup.Name, podZone)
|
||||||
framework.ExpectNoError(framework.WaitForReadyNodes(c, nodeCount, framework.RestartNodeReadyAgainTimeout),
|
framework.ExpectNoError(framework.WaitForReadyNodes(c, nodeCount, framework.RestartNodeReadyAgainTimeout),
|
||||||
|
Loading…
Reference in New Issue
Block a user