Merge pull request #15024 from rook/mergify/bp/release-1.15/pr-15016

rook: add warning when duplicate node topology values are detected (backport #15016)
This commit is contained in:
Travis Nielsen authored and GitHub committed 2024-11-20 10:07:36 -07:00
commit f13aedaaee
1 file changed
+15 -3
@@ -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
}