Merge pull request #10056 from rook/mergify/bp/release-1.9/pr-10053
pool: built-in pools must be replicated (backport #10053)
This commit is contained in:
3 files changed
+34
-8
No files matched your search
@@ -53,34 +53,46 @@ func (p *ReplicatedSpec) IsTargetRatioEnabled() bool {
|
||||
func (p *CephBlockPool) ValidateCreate() error {
|
||||
logger.Infof("validate create cephblockpool %v", p)
|
||||
|
||||
err := validatePoolSpec(p.Spec.ToNamedPoolSpec())
|
||||
err := ValidateCephBlockPool(&p.Spec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateCephBlockPool validates specifically a CephBlockPool's spec (not just any NamedPoolSpec)
|
||||
func ValidateCephBlockPool(s *NamedBlockPoolSpec) error {
|
||||
if s.Name == "device_health_metrics" || s.Name == ".mgr" || s.Name == ".nfs" {
|
||||
if s.IsErasureCoded() {
|
||||
return errors.Errorf("invalid CephBlockPool spec: ceph built-in pool %q cannot be erasure coded", s.Name)
|
||||
}
|
||||
}
|
||||
|
||||
return validatePoolSpec(s.ToNamedPoolSpec())
|
||||
}
|
||||
|
||||
// validate any NamedPoolSpec
|
||||
func validatePoolSpec(ps NamedPoolSpec) error {
|
||||
// Checks if either ErasureCoded or Replicated fields are set
|
||||
if ps.ErasureCoded.CodingChunks <= 0 && ps.ErasureCoded.DataChunks <= 0 && ps.Replicated.TargetSizeRatio <= 0 && ps.Replicated.Size <= 0 {
|
||||
return errors.New("invalid create: either of erasurecoded or replicated fields should be set")
|
||||
return errors.New("invalid pool spec: either of erasurecoded or replicated fields should be set")
|
||||
}
|
||||
// Check if any of the ErasureCoded fields are populated. Then check if replicated is populated. Both can't be populated at same time.
|
||||
if ps.ErasureCoded.CodingChunks > 0 || ps.ErasureCoded.DataChunks > 0 || ps.ErasureCoded.Algorithm != "" {
|
||||
if ps.Replicated.Size > 0 || ps.Replicated.TargetSizeRatio > 0 {
|
||||
return errors.New("invalid create: both erasurecoded and replicated fields cannot be set at the same time")
|
||||
return errors.New("invalid pool spec: both erasurecoded and replicated fields cannot be set at the same time")
|
||||
}
|
||||
}
|
||||
|
||||
if ps.Replicated.Size == 0 && ps.Replicated.TargetSizeRatio == 0 {
|
||||
// Check if datachunks is set and has value less than 2.
|
||||
if ps.ErasureCoded.DataChunks < 2 && ps.ErasureCoded.DataChunks != 0 {
|
||||
return errors.New("invalid create: erasurecoded.datachunks needs minimum value of 2")
|
||||
return errors.New("invalid pool spec: erasurecoded.datachunks needs minimum value of 2")
|
||||
}
|
||||
|
||||
// Check if codingchunks is set and has value less than 1.
|
||||
if ps.ErasureCoded.CodingChunks < 1 && ps.ErasureCoded.CodingChunks != 0 {
|
||||
return errors.New("invalid create: erasurecoded.codingchunks needs minimum value of 1")
|
||||
return errors.New("invalid pool spec: erasurecoded.codingchunks needs minimum value of 1")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -96,7 +108,7 @@ func (p *NamedBlockPoolSpec) ToNamedPoolSpec() NamedPoolSpec {
|
||||
func (p *CephBlockPool) ValidateUpdate(old runtime.Object) error {
|
||||
logger.Info("validate update cephblockpool")
|
||||
ocbp := old.(*CephBlockPool)
|
||||
err := validatePoolSpec(p.Spec.ToNamedPoolSpec())
|
||||
err := ValidateCephBlockPool(&p.Spec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package pool
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
v1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
"github.com/rook/rook/pkg/clusterd"
|
||||
"github.com/rook/rook/pkg/daemon/ceph/client"
|
||||
cephclient "github.com/rook/rook/pkg/daemon/ceph/client"
|
||||
@@ -33,6 +34,11 @@ func validatePool(context *clusterd.Context, clusterInfo *client.ClusterInfo, cl
|
||||
if p.Namespace == "" {
|
||||
return errors.New("missing namespace")
|
||||
}
|
||||
|
||||
if err := v1.ValidateCephBlockPool(&p.Spec); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := ValidatePoolSpec(context, clusterInfo, clusterSpec, &p.Spec.PoolSpec); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -34,20 +34,23 @@ func TestValidatePool(t *testing.T) {
|
||||
clusterInfo := &cephclient.ClusterInfo{Namespace: "myns"}
|
||||
clusterSpec := &cephv1.ClusterSpec{}
|
||||
|
||||
t.Run("not specifying some replication or EC settings is fine", func(t *testing.T) {
|
||||
t.Run("not specifying replication or EC settings is invalid", func(t *testing.T) {
|
||||
p := cephv1.CephBlockPool{ObjectMeta: metav1.ObjectMeta{Name: "mypool", Namespace: clusterInfo.Namespace}}
|
||||
err := validatePool(context, clusterInfo, clusterSpec, &p)
|
||||
assert.NoError(t, err)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "either of erasurecoded or replicated fields should be set")
|
||||
})
|
||||
|
||||
t.Run("must specify name", func(t *testing.T) {
|
||||
p := cephv1.CephBlockPool{ObjectMeta: metav1.ObjectMeta{Namespace: clusterInfo.Namespace}}
|
||||
p.Spec.Replicated.Size = 3
|
||||
err := validatePool(context, clusterInfo, clusterSpec, &p)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("must specify namespace", func(t *testing.T) {
|
||||
p := cephv1.CephBlockPool{ObjectMeta: metav1.ObjectMeta{Name: "mypool"}}
|
||||
p.Spec.Replicated.Size = 3
|
||||
err := validatePool(context, clusterInfo, clusterSpec, &p)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
@@ -156,6 +159,7 @@ func TestValidatePool(t *testing.T) {
|
||||
|
||||
t.Run("fail unrecognized mirroring mode", func(t *testing.T) {
|
||||
p := cephv1.CephBlockPool{ObjectMeta: metav1.ObjectMeta{Name: "mypool", Namespace: clusterInfo.Namespace}}
|
||||
p.Spec.Replicated.Size = 3
|
||||
p.Spec.Mirroring.Enabled = true
|
||||
p.Spec.Mirroring.Mode = "foo"
|
||||
err := validatePool(context, clusterInfo, clusterSpec, &p)
|
||||
@@ -165,6 +169,7 @@ func TestValidatePool(t *testing.T) {
|
||||
|
||||
t.Run("success known mirroring mode", func(t *testing.T) {
|
||||
p := cephv1.CephBlockPool{ObjectMeta: metav1.ObjectMeta{Name: "mypool", Namespace: clusterInfo.Namespace}}
|
||||
p.Spec.Replicated.Size = 3
|
||||
p.Spec.Mirroring.Enabled = true
|
||||
p.Spec.Mirroring.Mode = "pool"
|
||||
err := validatePool(context, clusterInfo, clusterSpec, &p)
|
||||
@@ -173,6 +178,7 @@ func TestValidatePool(t *testing.T) {
|
||||
|
||||
t.Run("fail mirroring mode no interval specified", func(t *testing.T) {
|
||||
p := cephv1.CephBlockPool{ObjectMeta: metav1.ObjectMeta{Name: "mypool", Namespace: clusterInfo.Namespace}}
|
||||
p.Spec.Replicated.Size = 3
|
||||
p.Spec.Mirroring.Enabled = true
|
||||
p.Spec.Mirroring.Mode = "pool"
|
||||
p.Spec.Mirroring.SnapshotSchedules = []cephv1.SnapshotScheduleSpec{{StartTime: "14:00:00-05:00"}}
|
||||
@@ -183,6 +189,7 @@ func TestValidatePool(t *testing.T) {
|
||||
|
||||
t.Run("fail mirroring mode we have a snap interval", func(t *testing.T) {
|
||||
p := cephv1.CephBlockPool{ObjectMeta: metav1.ObjectMeta{Name: "mypool", Namespace: clusterInfo.Namespace}}
|
||||
p.Spec.Replicated.Size = 3
|
||||
p.Spec.Mirroring.Enabled = true
|
||||
p.Spec.Mirroring.Mode = "pool"
|
||||
p.Spec.Mirroring.SnapshotSchedules = []cephv1.SnapshotScheduleSpec{{Interval: "24h"}}
|
||||
@@ -192,6 +199,7 @@ func TestValidatePool(t *testing.T) {
|
||||
|
||||
t.Run("failure and subfailure domains", func(t *testing.T) {
|
||||
p := cephv1.CephBlockPool{ObjectMeta: metav1.ObjectMeta{Name: "mypool", Namespace: clusterInfo.Namespace}}
|
||||
p.Spec.Replicated.Size = 3
|
||||
p.Spec.FailureDomain = "host"
|
||||
p.Spec.Replicated.SubFailureDomain = "host"
|
||||
err := validatePool(context, clusterInfo, clusterSpec, &p)
|
||||
|
||||
Reference in new issue
Block a user