Skip to content

Commit

Permalink
Merge pull request #730 from sp98/BZ-2297454
Browse files Browse the repository at this point in the history
Bug 2297454: core: check for duplicate ceph fs pool names
  • Loading branch information
sp98 authored Sep 17, 2024
2 parents e6141b3 + 765f763 commit 5ca0491
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/operator/ceph/file/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ func validateFilesystem(context *clusterd.Context, clusterInfo *cephclient.Clust
if len(f.Spec.DataPools) == 0 {
return nil
}

// Ensure duplicate pool names are not present in the spec.
if len(f.Spec.DataPools) > 1 {
if hasDuplicatePoolNames(f.Spec.DataPools) {
return errors.New("duplicate pool names in the data pool spec")
}
}

if err := cephpool.ValidatePoolSpec(context, clusterInfo, clusterSpec, &f.Spec.MetadataPool); err != nil {
return errors.Wrap(err, "invalid metadata pool")
}
Expand All @@ -157,6 +165,21 @@ func validateFilesystem(context *clusterd.Context, clusterInfo *cephclient.Clust
return nil
}

func hasDuplicatePoolNames(poolSpecList []cephv1.NamedPoolSpec) bool {
poolNames := make(map[string]struct{})
for _, poolSpec := range poolSpecList {
if poolSpec.Name != "" {
if _, has := poolNames[poolSpec.Name]; has {
logger.Errorf("duplicate pool name %q in the data pool spec", poolSpec.Name)
return true
}
poolNames[poolSpec.Name] = struct{}{}
}
}

return false
}

// newFS creates a new instance of the file (MDS) service
func newFS(name, namespace string) *Filesystem {
return &Filesystem{
Expand Down
20 changes: 20 additions & 0 deletions pkg/operator/ceph/file/filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ func TestValidateSpec(t *testing.T) {
assert.Nil(t, validateFilesystem(context, clusterInfo, clusterSpec, fs))
}

func TestHasDuplicatePoolNames(t *testing.T) {
// PoolSpec with no duplicates
fs := &cephv1.CephFilesystem{
Spec: cephv1.FilesystemSpec{
DataPools: []cephv1.NamedPoolSpec{
{Name: "pool1"},
{Name: "pool2"},
},
},
}

result := hasDuplicatePoolNames(fs.Spec.DataPools)
assert.False(t, result)

// add duplicate pool name in the spec.
fs.Spec.DataPools = append(fs.Spec.DataPools, cephv1.NamedPoolSpec{Name: "pool1"})
result = hasDuplicatePoolNames(fs.Spec.DataPools)
assert.True(t, result)
}

func TestGenerateDataPoolNames(t *testing.T) {
fs := &Filesystem{Name: "fake", Namespace: "fake"}
fsSpec := cephv1.FilesystemSpec{
Expand Down

0 comments on commit 5ca0491

Please sign in to comment.