Skip to content

Commit

Permalink
nfs: always run default pool creation
Browse files Browse the repository at this point in the history
Previously, if the pool was present we would not run the pool creation
again. This is a problem if the pool spec changes, the new settings will
never be applied.

Signed-off-by: Sébastien Han <seb@redhat.com>
(cherry picked from commit f314284)

# Conflicts:
#	pkg/operator/ceph/nfs/controller_test.go
  • Loading branch information
leseb authored and mergify-bot committed Nov 24, 2021
1 parent 760a8d3 commit e19de4c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 20 deletions.
7 changes: 5 additions & 2 deletions pkg/operator/ceph/nfs/controller.go
Expand Up @@ -252,8 +252,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
60 changes: 59 additions & 1 deletion 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 @@ -45,6 +45,7 @@ var (
name = "my-nfs"
namespace = "rook-ceph"
nfsCephAuthGetOrCreateKey = `{"key":"AQCvzWBeIV9lFRAAninzm+8XFxbSfTiPwoX50g=="}`
<<<<<<< HEAD
dummyVersionsRaw = `
{
"mon": {
Expand All @@ -70,6 +71,8 @@ var (
"fast_read": 0,
"pg_autoscale_mode": "on"
}`
=======
>>>>>>> f3142847d (nfs: always run default pool creation)
)

func TestCephNFSController(t *testing.T) {
Expand Down Expand Up @@ -246,6 +249,7 @@ func TestCephNFSController(t *testing.T) {
// Create a ReconcileCephNFS object with the scheme and fake client.
r = &ReconcileCephNFS{client: cl, scheme: s, context: c}

<<<<<<< HEAD
logger.Info("STARTING PHASE 3")
res, err = r.Reconcile(ctx, req)
assert.NoError(t, err)
Expand All @@ -254,6 +258,60 @@ func TestCephNFSController(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "Ready", cephNFS.Status.Phase, cephNFS)
logger.Info("PHASE 3 DONE")
=======
// Create a fake client to mock API calls.
cl = fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(object...).Build()

executor = &exectest.MockExecutor{
MockExecuteCommandWithOutput: func(command string, args ...string) (string, error) {
if args[0] == "status" {
return `{"fsid":"c47cac40-9bee-4d52-823b-ccd803ba5bfe","health":{"checks":{},"status":"HEALTH_OK"},"pgmap":{"num_pgs":100,"pgs_by_state":[{"state_name":"active+clean","count":100}]}}`, nil
}
if args[0] == "auth" && args[1] == "get-or-create-key" {
return nfsCephAuthGetOrCreateKey, nil
}
if args[0] == "osd" && args[1] == "pool" && args[2] == "create" {
return "", nil
}
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" {
logger.Infof("mock execute. %s. %s", command, args)
assert.Equal(t, "stat", args[6])
assert.Equal(t, "conf-nfs.my-nfs", args[7])
return nil
}
return errors.New("unknown command")
},
MockExecuteCommandWithEnv: func(env []string, command string, args ...string) error {
if command == "ganesha-rados-grace" {
logger.Infof("mock execute. %s. %s", command, args)
assert.Equal(t, "add", args[4])
assert.Len(t, env, 1)
return nil
}
return errors.New("unknown command")
},
}
c.Executor = executor

// Create a ReconcileCephNFS object with the scheme and fake client.
r = &ReconcileCephNFS{client: cl, scheme: s, context: c, opManagerContext: ctx}
res, err := r.Reconcile(ctx, req)
assert.NoError(t, err)
assert.False(t, res.Requeue)
err = r.client.Get(context.TODO(), req.NamespacedName, cephNFS)
assert.NoError(t, err)
assert.Equal(t, "Ready", cephNFS.Status.Phase, cephNFS)
})
>>>>>>> f3142847d (nfs: always run default pool creation)
}

func TestGetGaneshaConfigObject(t *testing.T) {
Expand Down
17 changes: 0 additions & 17 deletions pkg/operator/ceph/nfs/nfs.go
Expand Up @@ -20,7 +20,6 @@ package nfs
import (
"context"
"fmt"
"strings"

"github.com/banzaicloud/k8s-objectmatcher/patch"
"github.com/pkg/errors"
Expand Down Expand Up @@ -300,19 +299,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
}

0 comments on commit e19de4c

Please sign in to comment.