From a337dd41f506eb80cde435d0399a21698fb3308f Mon Sep 17 00:00:00 2001 From: Oded Viner Date: Wed, 4 Jun 2025 18:04:54 +0300 Subject: [PATCH] pool: support targetSizeRatio=0 and default compressionMode="" allow targetSizeRatio == 0 enforce targetSizeRatio >= 0 via +kubebuilder:validation set targetSizeRatio and compressionMode="" if unset remove IsTargetRatioEnabled() and IsCompressionEnabled() Signed-off-by: Oded Viner (cherry picked from commit dd65dc15d839e0f8a74025ffb007d59d110f3bb2) --- deploy/charts/rook-ceph/templates/resources.yaml | 7 +++++++ deploy/examples/crds.yaml | 7 +++++++ pkg/apis/ceph.rook.io/v1/pool.go | 8 -------- pkg/apis/ceph.rook.io/v1/types.go | 1 + pkg/daemon/ceph/client/pool.go | 4 ++-- pkg/operator/ceph/file/filesystem_test.go | 16 ++++++++++++++++ 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/deploy/charts/rook-ceph/templates/resources.yaml b/deploy/charts/rook-ceph/templates/resources.yaml index 2bbcaa6b0..752d4b95e 100644 --- a/deploy/charts/rook-ceph/templates/resources.yaml +++ b/deploy/charts/rook-ceph/templates/resources.yaml @@ -572,6 +572,7 @@ spec: type: string targetSizeRatio: description: TargetSizeRatio gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity + minimum: 0 type: number required: - size @@ -7372,6 +7373,7 @@ spec: type: string targetSizeRatio: description: TargetSizeRatio gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity + minimum: 0 type: number required: - size @@ -7560,6 +7562,7 @@ spec: type: string targetSizeRatio: description: TargetSizeRatio gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity + minimum: 0 type: number required: - size @@ -11224,6 +11227,7 @@ spec: type: string targetSizeRatio: description: TargetSizeRatio gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity + minimum: 0 type: number required: - size @@ -12824,6 +12828,7 @@ spec: type: string targetSizeRatio: description: TargetSizeRatio gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity + minimum: 0 type: number required: - size @@ -13758,6 +13763,7 @@ spec: type: string targetSizeRatio: description: TargetSizeRatio gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity + minimum: 0 type: number required: - size @@ -13941,6 +13947,7 @@ spec: type: string targetSizeRatio: description: TargetSizeRatio gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity + minimum: 0 type: number required: - size diff --git a/deploy/examples/crds.yaml b/deploy/examples/crds.yaml index 7ce5132f7..23bf659ba 100644 --- a/deploy/examples/crds.yaml +++ b/deploy/examples/crds.yaml @@ -574,6 +574,7 @@ spec: type: string targetSizeRatio: description: TargetSizeRatio gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity + minimum: 0 type: number required: - size @@ -7367,6 +7368,7 @@ spec: type: string targetSizeRatio: description: TargetSizeRatio gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity + minimum: 0 type: number required: - size @@ -7555,6 +7557,7 @@ spec: type: string targetSizeRatio: description: TargetSizeRatio gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity + minimum: 0 type: number required: - size @@ -11215,6 +11218,7 @@ spec: type: string targetSizeRatio: description: TargetSizeRatio gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity + minimum: 0 type: number required: - size @@ -12815,6 +12819,7 @@ spec: type: string targetSizeRatio: description: TargetSizeRatio gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity + minimum: 0 type: number required: - size @@ -13746,6 +13751,7 @@ spec: type: string targetSizeRatio: description: TargetSizeRatio gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity + minimum: 0 type: number required: - size @@ -13929,6 +13935,7 @@ spec: type: string targetSizeRatio: description: TargetSizeRatio gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity + minimum: 0 type: number required: - size diff --git a/pkg/apis/ceph.rook.io/v1/pool.go b/pkg/apis/ceph.rook.io/v1/pool.go index 2ebe92374..a3653f04d 100644 --- a/pkg/apis/ceph.rook.io/v1/pool.go +++ b/pkg/apis/ceph.rook.io/v1/pool.go @@ -32,14 +32,6 @@ func (p *PoolSpec) IsHybridStoragePool() bool { return p.Replicated.HybridStorage != nil } -func (p *PoolSpec) IsCompressionEnabled() bool { - return p.CompressionMode != "" -} - -func (p *ReplicatedSpec) IsTargetRatioEnabled() bool { - return p.TargetSizeRatio != 0 -} - // ValidateCephBlockPool validates specifically a CephBlockPool's spec (not just any NamedPoolSpec) func ValidateCephBlockPool(p *CephBlockPool) error { if p.Spec.Name == ".rgw.root" || p.Spec.Name == ".mgr" || p.Spec.Name == ".nfs" { diff --git a/pkg/apis/ceph.rook.io/v1/types.go b/pkg/apis/ceph.rook.io/v1/types.go index 0b2b31f5d..728fac373 100755 --- a/pkg/apis/ceph.rook.io/v1/types.go +++ b/pkg/apis/ceph.rook.io/v1/types.go @@ -1083,6 +1083,7 @@ type ReplicatedSpec struct { Size uint `json:"size"` // TargetSizeRatio gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity + // +kubebuilder:validation:Minimum=0 // +optional TargetSizeRatio float64 `json:"targetSizeRatio,omitempty"` diff --git a/pkg/daemon/ceph/client/pool.go b/pkg/daemon/ceph/client/pool.go index c60fa5965..3427b42e5 100644 --- a/pkg/daemon/ceph/client/pool.go +++ b/pkg/daemon/ceph/client/pool.go @@ -325,11 +325,11 @@ func setCommonPoolProperties(context *clusterd.Context, clusterInfo *ClusterInfo pool.Parameters = make(map[string]string) } - if pool.Replicated.IsTargetRatioEnabled() { + if _, ok := pool.Parameters[targetSizeRatioProperty]; !ok { pool.Parameters[targetSizeRatioProperty] = strconv.FormatFloat(pool.Replicated.TargetSizeRatio, 'f', -1, 32) } - if pool.IsCompressionEnabled() { + if _, ok := pool.Parameters[CompressionModeProperty]; !ok && pool.CompressionMode != "" { pool.Parameters[CompressionModeProperty] = pool.CompressionMode } diff --git a/pkg/operator/ceph/file/filesystem_test.go b/pkg/operator/ceph/file/filesystem_test.go index bd4661873..1e9d24c5b 100644 --- a/pkg/operator/ceph/file/filesystem_test.go +++ b/pkg/operator/ceph/file/filesystem_test.go @@ -308,6 +308,22 @@ func fsExecutor(t *testing.T, fsName, configDir string, multiFS bool, createData return "", nil } else if reflect.DeepEqual(args[0:6], []string{"osd", "pool", "set", fsName + "-data1", "size", "1"}) { return "", nil + } else if reflect.DeepEqual(args[0:6], []string{"osd", "pool", "set", fsName + "-metadata", "target_size_ratio", "0"}) { + return "", nil + } else if reflect.DeepEqual(args[0:6], []string{"osd", "pool", "set", fsName + "-data0", "target_size_ratio", "0"}) { + return "", nil + } else if reflect.DeepEqual(args[0:6], []string{"osd", "pool", "set", fsName + "-data1", "target_size_ratio", "0"}) { + return "", nil + } else if reflect.DeepEqual(args[0:6], []string{"osd", "pool", "set", fsName + "-named-pool", "target_size_ratio", "0"}) { + return "", nil + } else if reflect.DeepEqual(args[0:6], []string{"osd", "pool", "set", fsName + "-metadata", "compression_mode", ""}) { + return "", nil + } else if reflect.DeepEqual(args[0:6], []string{"osd", "pool", "set", fsName + "-data0", "compression_mode", ""}) { + return "", nil + } else if reflect.DeepEqual(args[0:6], []string{"osd", "pool", "set", fsName + "-data1", "compression_mode", ""}) { + return "", nil + } else if reflect.DeepEqual(args[0:6], []string{"osd", "pool", "set", fsName + "-named-pool", "compression_mode", ""}) { + return "", nil } else if reflect.DeepEqual(args[0:4], []string{"fs", "add_data_pool", fsName, fsName + "-data1"}) { *addDataPoolCount++ return "", nil