pkg/util/node: update GetZoneKey to check both beta and GA labels

Signed-off-by: Andrew Sy Kim <kiman@vmware.com>
This commit is contained in:
Andrew Sy Kim
2019-08-28 12:59:09 -04:00
parent 4c194d52da
commit 07229d6c51
4 changed files with 294 additions and 88 deletions

View File

@@ -139,23 +139,37 @@ func GetNodeIP(client clientset.Interface, hostname string) net.IP {
// GetZoneKey is a helper function that builds a string identifier that is unique per failure-zone;
// it returns empty-string for no zone.
// Since there are currently two separate zone keys:
// * "failure-domain.beta.kubernetes.io/zone"
// * "topology.kubernetes.io/zone"
// GetZoneKey will first check failure-domain.beta.kubernetes.io/zone and if not exists, will then check
// topology.kubernetes.io/zone
func GetZoneKey(node *v1.Node) string {
labels := node.Labels
if labels == nil {
return ""
}
region, _ := labels[v1.LabelZoneRegion]
failureDomain, _ := labels[v1.LabelZoneFailureDomain]
// TODO: prefer stable labels for zone in v1.18
zone, ok := labels[v1.LabelZoneFailureDomain]
if !ok {
zone, _ = labels[v1.LabelZoneFailureDomainStable]
}
if region == "" && failureDomain == "" {
// TODO: prefer stable labels for region in v1.18
region, ok := labels[v1.LabelZoneRegion]
if !ok {
region, _ = labels[v1.LabelZoneRegionStable]
}
if region == "" && zone == "" {
return ""
}
// We include the null character just in case region or failureDomain has a colon
// (We do assume there's no null characters in a region or failureDomain)
// As a nice side-benefit, the null character is not printed by fmt.Print or glog
return region + ":\x00:" + failureDomain
return region + ":\x00:" + zone
}
type nodeForConditionPatch struct {