From 41116be9198f0ea6440d43f7783745dd81ac54a9 Mon Sep 17 00:00:00 2001 From: Deepika Upadhyay Date: Tue, 4 Jun 2024 01:11:30 +0530 Subject: [PATCH] pool: get the exact deviceClass name instead of crushroot+deviceClass this lead to creation of 2 crush rules because of difference in deviceClass names: eg: creating a new crush rule for changed deviceClass ("default~hdd"-->"hdd") on crush rule "test-crush-bug-az-ab-4" Signed-off-by: Deepika Upadhyay --- pkg/daemon/ceph/client/pool.go | 10 +++++++++- pkg/daemon/ceph/client/pool_test.go | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/daemon/ceph/client/pool.go b/pkg/daemon/ceph/client/pool.go index b7089f94baf7..7d26c323980a 100644 --- a/pkg/daemon/ceph/client/pool.go +++ b/pkg/daemon/ceph/client/pool.go @@ -529,7 +529,15 @@ func extractPoolDetails(rule ruleSpec) (string, string) { failureDomain = step.Type } if step.ItemName != "" { - deviceClass = step.ItemName + // we are not using crushRoot currently, remove it + // from crush rule + if strings.Contains(step.ItemName, "~") { + crushRootAndDeviceClass := step.ItemName + parts := strings.SplitN(crushRootAndDeviceClass, "~", 2) + deviceClass = parts[1] + } else { + deviceClass = step.ItemName + } } // We expect the rule to be found by the second step, or else it is a more // complex rule that would not be supported for updating the failure domain diff --git a/pkg/daemon/ceph/client/pool_test.go b/pkg/daemon/ceph/client/pool_test.go index b2fa1add2401..929e8b832047 100644 --- a/pkg/daemon/ceph/client/pool_test.go +++ b/pkg/daemon/ceph/client/pool_test.go @@ -339,6 +339,16 @@ func TestExtractPoolDetails(t *testing.T) { assert.Equal(t, "zone", failureDomain) assert.Equal(t, "ssd", deviceClass) }) + + t.Run("valid crush rule with crushroot combined", func(t *testing.T) { + rule := ruleSpec{Steps: []stepSpec{ + {Type: ""}, + {Type: "zone", ItemName: "default~ssd"}, + }} + failureDomain, deviceClass := extractPoolDetails(rule) + assert.Equal(t, "zone", failureDomain) + assert.Equal(t, "ssd", deviceClass) + }) } func TestGetPoolStatistics(t *testing.T) {