mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
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
This commit is contained in:
commit
2cef77db8e
@ -145,6 +145,28 @@ func CreateManagedInstanceGroup(size int64, zone, template string) error {
|
||||
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 {
|
||||
// TODO(verult): make this hit the compute API directly instead of
|
||||
// shelling out to gcloud.
|
||||
@ -158,3 +180,29 @@ func DeleteManagedInstanceGroup(zone string) error {
|
||||
}
|
||||
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)
|
||||
Expect(err).NotTo(HaveOccurred(),
|
||||
"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)
|
||||
Expect(err).NotTo(HaveOccurred(),
|
||||
"Error deleting instance group in zone %s", podZone)
|
||||
@ -212,9 +215,6 @@ func testZonalFailover(c clientset.Interface, ns string) {
|
||||
defer func() {
|
||||
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),
|
||||
"Error recreating instance group %s in zone %s", instanceGroup.Name, podZone)
|
||||
framework.ExpectNoError(framework.WaitForReadyNodes(c, nodeCount, framework.RestartNodeReadyAgainTimeout),
|
||||
|
Loading…
Reference in New Issue
Block a user