From a1ba4155f829cd47050b2261998d77373152e86c Mon Sep 17 00:00:00 2001 From: Fred Heinecke Date: Fri, 15 Nov 2024 18:27:55 +0000 Subject: [PATCH] osd: add warning when duplicate node topology values are detected When node topology labels with duplicate values are detected, rook silently discards all but one label. This adds a warning informing administrators of this, allowing for easier identification of labeling issues. Signed-off-by: Fred Heinecke (cherry picked from commit f54ecaaff10687b90495783d1a3003918778666c) --- .../ceph/cluster/osd/topology/topology.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/operator/ceph/cluster/osd/topology/topology.go b/pkg/operator/ceph/cluster/osd/topology/topology.go index a69552b14..ce4022e16 100644 --- a/pkg/operator/ceph/cluster/osd/topology/topology.go +++ b/pkg/operator/ceph/cluster/osd/topology/topology.go @@ -23,6 +23,7 @@ import ( "fmt" "strings" + "github.com/coreos/pkg/capnslog" "github.com/rook/rook/pkg/daemon/ceph/client" corev1 "k8s.io/api/core/v1" ) @@ -39,6 +40,8 @@ var ( // The list of supported failure domains in the CRUSH map, ordered from lowest to highest CRUSHMapLevelsOrdered = append([]string{"host"}, append(CRUSHTopologyLabels, KubernetesTopologyLabels...)...) + + logger = capnslog.NewPackageLogger("github.com/rook/rook", "osd-topology") ) const ( @@ -107,18 +110,27 @@ func extractTopologyFromLabels(labels map[string]string) (map[string]string, str } // iterate in lowest to highest order as the lowest level should be sustained and higher level duplicate // should be removed - duplicateTopology := make(map[string]int) + duplicateTopology := make(map[string][]string) for i := len(allKubernetesTopologyLabels) - 1; i >= 0; i-- { topologyLabel := allKubernetesTopologyLabels[i] if value, ok := labels[topologyLabel]; ok { if _, ok := duplicateTopology[value]; ok { delete(topology, kubernetesTopologyLabelToCRUSHLabel(topologyLabel)) - } else { - duplicateTopology[value] = 1 } + duplicateTopology[value] = append(duplicateTopology[value], topologyLabel) } } + // remove non-duplicate entries, and report if any duplicate entries were found + for value, duplicateKeys := range duplicateTopology { + if len(duplicateKeys) <= 1 { + delete(duplicateTopology, value) + } + } + if len(duplicateTopology) != 0 { + logger.Warningf("Found duplicate location values with labels: %v", duplicateTopology) + } + return topology, topologyAffinity }