Make tests deal with old and new topology labels

This commit is contained in:
Tim Hockin 2020-11-06 08:47:32 -08:00
parent f63ca48a1f
commit 3bd337baf4
4 changed files with 13 additions and 7 deletions

View File

@ -15,6 +15,8 @@ metadata:
cloud.google.com/gke-os-distribution: cos
failure-domain.beta.kubernetes.io/region: us-central1
failure-domain.beta.kubernetes.io/zone: us-central1-b
topology.kubernetes.io/region: us-central1
topology.kubernetes.io/zone: us-central1-b
kubernetes.io/hostname: node-default-pool-something
name: node-default-pool-something
resourceVersion: "211582541"

View File

@ -163,6 +163,8 @@ func RestartNodes(c clientset.Interface, nodes []v1.Node) error {
zone := framework.TestContext.CloudConfig.Zone
if z, ok := node.Labels[v1.LabelFailureDomainBetaZone]; ok {
zone = z
} else if z, ok := node.Labels[v1.LabelTopologyZone]; ok {
zone = z
}
nodeNamesByZone[zone] = append(nodeNamesByZone[zone], node.Name)
}

View File

@ -182,6 +182,8 @@ var _ = SIGDescribe("Firewall rule", func() {
zone := cloudConfig.Zone
if zoneInLabel, ok := nodeList.Items[0].Labels[v1.LabelFailureDomainBetaZone]; ok {
zone = zoneInLabel
} else if zoneInLabel, ok := nodeList.Items[0].Labels[v1.LabelTopologyZone]; ok {
zone = zoneInLabel
}
removedTags := gce.SetInstanceTags(cloudConfig, nodesNames[0], zone, []string{})
defer func() {

View File

@ -23,7 +23,7 @@ import (
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/intstr"
@ -120,13 +120,13 @@ func SpreadServiceOrFail(f *framework.Framework, replicaCount int, image string)
// Find the name of the zone in which a Node is running
func getZoneNameForNode(node v1.Node) (string, error) {
for key, value := range node.Labels {
if key == v1.LabelFailureDomainBetaZone {
return value, nil
}
if z, ok := node.Labels[v1.LabelFailureDomainBetaZone]; ok {
return z, nil
} else if z, ok := node.Labels[v1.LabelTopologyZone]; ok {
return z, nil
}
return "", fmt.Errorf("node %s doesn't have zone label %s",
node.Name, v1.LabelFailureDomainBetaZone)
return "", fmt.Errorf("node %s doesn't have zone label %s or %s",
node.Name, v1.LabelFailureDomainBetaZone, v1.LabelTopologyZone)
}
// Return the number of zones in which we have nodes in this cluster.