Unverified Commit 2cef77db authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #64480 from verult/repd-ig-fix

Automatic merge from submit-queue (batch tested with PRs 62460, 64480, 63774, 64540, 64337). 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>. Modified regional PD test to fetch template name from GCE **What this PR does / why we need it**: Previously, the regional PD failover e2e test assumes a specific relationship between the names of an instance group and its corresponding template. It turns out to not always hold true for different types of clusters. Instead, the test should fetch the correct template name by calling out to GCE. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Part of #59988 Need to cherry pick this back to 1.10 along with #64223 **Release note**: ```release-note NONE ``` /assign @saad-ali @wojtek-t /sig storage
parents 73037762 82f9d936
...@@ -145,6 +145,28 @@ func CreateManagedInstanceGroup(size int64, zone, template string) error { ...@@ -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 { ...@@ -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) { ...@@ -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) { ...@@ -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),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment