From 9f0281a40e434d50527e1161d9bf0afdf89d3adf Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Tue, 19 Apr 2022 10:19:52 +0530 Subject: [PATCH] block: validate updating name in BlockPool CR Currently we are allowing users to change the name of the pool to be created in the BlockPool CR. with this we have a bug of leaving stale resources in the cluster. With new changes we are blocking the update of the pool name in the BlockPool CR. Signed-off-by: Madhu Rajanna (cherry picked from commit 99224ad1029becce42aa2dc5573630e8ce11867d) --- pkg/apis/ceph.rook.io/v1/pool.go | 3 +++ pkg/apis/ceph.rook.io/v1/pool_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/pkg/apis/ceph.rook.io/v1/pool.go b/pkg/apis/ceph.rook.io/v1/pool.go index b4343a0cd..bd00b7dc6 100644 --- a/pkg/apis/ceph.rook.io/v1/pool.go +++ b/pkg/apis/ceph.rook.io/v1/pool.go @@ -112,6 +112,9 @@ func (p *CephBlockPool) ValidateUpdate(old runtime.Object) error { if err != nil { return err } + if ocbp.Spec.Name != p.Spec.Name { + return errors.New("invalid update: pool name cannot be changed") + } if p.Spec.ErasureCoded.CodingChunks > 0 || p.Spec.ErasureCoded.DataChunks > 0 || p.Spec.ErasureCoded.Algorithm != "" { if ocbp.Spec.Replicated.Size > 0 || ocbp.Spec.Replicated.TargetSizeRatio > 0 { return errors.New("invalid update: replicated field is set already in previous object. cannot be changed to use erasurecoded") diff --git a/pkg/apis/ceph.rook.io/v1/pool_test.go b/pkg/apis/ceph.rook.io/v1/pool_test.go index f9ba6a0fd..95de4d917 100644 --- a/pkg/apis/ceph.rook.io/v1/pool_test.go +++ b/pkg/apis/ceph.rook.io/v1/pool_test.go @@ -61,6 +61,12 @@ func TestCephBlockPoolValidateUpdate(t *testing.T) { up.Spec.ErasureCoded.CodingChunks = 1 err := up.ValidateUpdate(p) assert.Error(t, err) + + // validate with different name in Spec.Name + ip := p.DeepCopy() + ip.Spec.Name = "new-ec-pool" + err = ip.ValidateUpdate(p) + assert.Error(t, err) } func TestMirroringSpec_SnapshotSchedulesEnabled(t *testing.T) {