From f11fa815c874f8cbdea443943d52d80f3aa286f2 Mon Sep 17 00:00:00 2001 From: Praveen M Date: Thu, 11 Jul 2024 18:35:34 +0530 Subject: [PATCH] util: exclude empty label values for crushlocation map This commit resolves a bug where node labels with empty values are processed for the crush_location mount option, leading to invalid mount options and subsequent mount failures. Signed-off-by: Praveen M --- internal/util/crushlocation.go | 4 ++++ internal/util/crushlocation_test.go | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/internal/util/crushlocation.go b/internal/util/crushlocation.go index bc68bf4e6..69a302697 100644 --- a/internal/util/crushlocation.go +++ b/internal/util/crushlocation.go @@ -48,6 +48,10 @@ func getCrushLocationMap(crushLocationLabels string, nodeLabels map[string]strin // Determine values for requested labels from node labels crushLocationMap := make(map[string]string, len(labelsIn)) for key, value := range nodeLabels { + // label with empty value is not considered. + if value == "" { + continue + } if _, ok := labelsIn[key]; !ok { continue } diff --git a/internal/util/crushlocation_test.go b/internal/util/crushlocation_test.go index 6c4b00230..4eced910c 100644 --- a/internal/util/crushlocation_test.go +++ b/internal/util/crushlocation_test.go @@ -100,6 +100,17 @@ func Test_getCrushLocationMap(t *testing.T) { }, want: map[string]string{"host": "worker-1"}, }, + { + name: "matching crushlocation and node labels with empty value", + args: input{ + crushLocationLabels: "topology.io/region,topology.io/zone", + nodeLabels: map[string]string{ + "topology.io/region": "region1", + "topology.io/zone": "", + }, + }, + want: map[string]string{"region": "region1"}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {