Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nfs: only set the pool size when it exists and always run default pool creation #9224

Merged
merged 2 commits into from Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/daemon/ceph/client/pool.go
Expand Up @@ -408,8 +408,11 @@ func CreateReplicatedPoolForApp(context *clusterd.Context, clusterInfo *ClusterI

if !clusterSpec.IsStretchCluster() {
// the pool is type replicated, set the size for the pool now that it's been created
if err := SetPoolReplicatedSizeProperty(context, clusterInfo, poolName, strconv.FormatUint(uint64(pool.Replicated.Size), 10)); err != nil {
return errors.Wrapf(err, "failed to set size property to replicated pool %q to %d", poolName, pool.Replicated.Size)
// Only set the size if not 0, otherwise ceph will fail to set size to 0
if pool.Replicated.Size > 0 {
if err := SetPoolReplicatedSizeProperty(context, clusterInfo, poolName, strconv.FormatUint(uint64(pool.Replicated.Size), 10)); err != nil {
return errors.Wrapf(err, "failed to set size property to replicated pool %q to %d", poolName, pool.Replicated.Size)
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/operator/ceph/nfs/controller.go
Expand Up @@ -278,8 +278,11 @@ func (r *ReconcileCephNFS) reconcile(request reconcile.Request) (reconcile.Resul
if err := validateGanesha(r.context, r.clusterInfo, cephNFS); err != nil {
return reconcile.Result{}, errors.Wrapf(err, "invalid ceph nfs %q arguments", cephNFS.Name)
}
if err := r.fetchOrCreatePool(cephNFS); err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to fetch or create RADOS pool")

// Always create the default pool
err = r.createDefaultNFSRADOSPool(cephNFS)
if err != nil {
return reconcile.Result{}, errors.Wrapf(err, "failed to create default pool %q", cephNFS.Spec.RADOS.Pool)
}

// CREATE/UPDATE
Expand Down
33 changes: 10 additions & 23 deletions pkg/operator/ceph/nfs/controller_test.go
Expand Up @@ -19,11 +19,11 @@ package nfs

import (
"context"
"errors"
"os"
"testing"

"github.com/coreos/pkg/capnslog"
"github.com/pkg/errors"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
rookclient "github.com/rook/rook/pkg/client/clientset/versioned/fake"
"github.com/rook/rook/pkg/client/clientset/versioned/scheme"
Expand All @@ -46,25 +46,6 @@ var (
name = "my-nfs"
namespace = "rook-ceph"
nfsCephAuthGetOrCreateKey = `{"key":"AQCvzWBeIV9lFRAAninzm+8XFxbSfTiPwoX50g=="}`
poolDetails = `{
"pool": "foo",
"pool_id": 1,
"size": 3,
"min_size": 2,
"pg_num": 8,
"pgp_num": 8,
"crush_rule": "replicated_rule",
"hashpspool": true,
"nodelete": false,
"nopgchange": false,
"nosizechange": false,
"write_fadvise_dontneed": false,
"noscrub": false,
"nodeep-scrub": false,
"use_gmt_hitset": true,
"fast_read": 0,
"pg_autoscale_mode": "on"
}`
)

func TestCephNFSController(t *testing.T) {
Expand Down Expand Up @@ -202,10 +183,16 @@ func TestCephNFSController(t *testing.T) {
if args[0] == "auth" && args[1] == "get-or-create-key" {
return nfsCephAuthGetOrCreateKey, nil
}
if args[0] == "osd" && args[1] == "pool" && args[2] == "get" {
return poolDetails, nil
if args[0] == "osd" && args[1] == "pool" && args[2] == "create" {
return "", nil
}
return "", errors.New("unknown command")
if args[0] == "osd" && args[1] == "crush" && args[2] == "rule" {
return "", nil
}
if args[0] == "osd" && args[1] == "pool" && args[2] == "application" {
return "", nil
}
return "", errors.Errorf("unknown command %q %v", command, args)
},
MockExecuteCommand: func(command string, args ...string) error {
if command == "rados" {
Expand Down
17 changes: 0 additions & 17 deletions pkg/operator/ceph/nfs/nfs.go
Expand Up @@ -19,7 +19,6 @@ package nfs

import (
"fmt"
"strings"

"github.com/banzaicloud/k8s-objectmatcher/patch"
"github.com/pkg/errors"
Expand Down Expand Up @@ -296,19 +295,3 @@ func (r *ReconcileCephNFS) createDefaultNFSRADOSPool(n *cephv1.CephNFS) error {

return nil
}

func (r *ReconcileCephNFS) fetchOrCreatePool(n *cephv1.CephNFS) error {
// The existence of the pool provided in n.Spec.RADOS.Pool is necessary otherwise addRADOSConfigFile() will fail
_, err := cephclient.GetPoolDetails(r.context, r.clusterInfo, n.Spec.RADOS.Pool)
if err != nil {
if strings.Contains(err.Error(), "unrecognized pool") && r.clusterInfo.CephVersion.IsAtLeastPacific() {
err := r.createDefaultNFSRADOSPool(n)
if err != nil {
return errors.Wrapf(err, "failed to find %q pool and unable to create it", n.Spec.RADOS.Pool)
}
return nil
}
return errors.Wrapf(err, "pool %q not found", n.Spec.RADOS.Pool)
}
return nil
}