osd: ignore the region label when it is the same as zone label in topology

Ceph requires all topology label being unique. And it is quite common to
have topology.kubernetes.io/region and topology.kubernetes.io/zone being set
to the same value. In this case, let's just ignore the region label.

See https://github.com/rook/rook/issues/9419#issuecomment-1144311818

Signed-off-by: Cheng XU <git@xuc.me>
(cherry picked from commit 9b03d0759b)
This commit is contained in:
Cheng XU authored and Mergify committed 2022-06-03 17:42:31 +00:00
1 parent 43cb1b46bf
commit 1750986830
2 files changed
+15

No files matched your search

@@ -93,6 +93,11 @@ func extractTopologyFromLabels(labels map[string]string) (map[string]string, str
topologyAffinity = formatTopologyAffinity(corev1.LabelZoneFailureDomainStable, zone)
}
// ignore the region k8s topology label when it has the same value as the k8s zone label
if topology[regionLabel] == topology[zoneLabel] {
delete(topology, regionLabel)
}
// get host
host, ok := labels[corev1.LabelHostname]
if ok {
@@ -134,4 +134,14 @@ func TestTopologyLabels(t *testing.T) {
topology, affinity = extractTopologyFromLabels(nodeLabels)
assert.Equal(t, 0, len(topology))
assert.Equal(t, "", affinity)
// ignore the region k8s topology label when it has the same value as the k8s zone label
nodeLabels = map[string]string{
corev1.LabelZoneRegionStable: "zone",
corev1.LabelZoneFailureDomainStable: "zone",
}
topology, affinity = extractTopologyFromLabels(nodeLabels)
assert.Equal(t, 1, len(topology))
assert.Equal(t, "zone", topology["zone"])
assert.Equal(t, "topology.kubernetes.io/zone=zone", affinity)
}