mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user