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>
  • Loading branch information
leseb committed Nov 23, 2021
1 parent c3accdc commit 0e93cc8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
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
15 changes: 11 additions & 4 deletions pkg/operator/ceph/nfs/controller_test.go
Expand Up @@ -19,10 +19,11 @@ package nfs

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

"github.com/pkg/errors"

"github.com/coreos/pkg/capnslog"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
rookclient "github.com/rook/rook/pkg/client/clientset/versioned/fake"
Expand Down Expand Up @@ -202,10 +203,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
}
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.New("unknown command")
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
}

0 comments on commit 0e93cc8

Please sign in to comment.