From 9b03d0759be59d1356213fed7f059f225e9f7ea4 Mon Sep 17 00:00:00 2001 From: Cheng XU Date: Thu, 2 Jun 2022 15:26:32 -0700 Subject: [PATCH] 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 --- pkg/operator/ceph/cluster/osd/topology.go | 5 +++++ pkg/operator/ceph/cluster/osd/topology_test.go | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/pkg/operator/ceph/cluster/osd/topology.go b/pkg/operator/ceph/cluster/osd/topology.go index 81f7735cf..548dd272b 100644 --- a/pkg/operator/ceph/cluster/osd/topology.go +++ b/pkg/operator/ceph/cluster/osd/topology.go @@ -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 { diff --git a/pkg/operator/ceph/cluster/osd/topology_test.go b/pkg/operator/ceph/cluster/osd/topology_test.go index 30b73db9c..e0327d501 100644 --- a/pkg/operator/ceph/cluster/osd/topology_test.go +++ b/pkg/operator/ceph/cluster/osd/topology_test.go @@ -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) }