Merge pull request #11221 from zhucan/bugfix-11204
file: check if fs exists before checking dependencies
This commit is contained in:
4 files changed
+58
-9
No files matched your search
@@ -96,8 +96,10 @@ func ListFilesystems(context *clusterd.Context, clusterInfo *ClusterInfo) ([]Cep
|
||||
return filesystems, nil
|
||||
}
|
||||
|
||||
// GetFilesystem gets detailed status information about a Ceph filesystem.
|
||||
func GetFilesystem(context *clusterd.Context, clusterInfo *ClusterInfo, fsName string) (*CephFilesystemDetails, error) {
|
||||
var GetFilesystem = getFilesystem
|
||||
|
||||
// getFilesystem gets detailed status information about a Ceph filesystem.
|
||||
func getFilesystem(context *clusterd.Context, clusterInfo *ClusterInfo, fsName string) (*CephFilesystemDetails, error) {
|
||||
args := []string{"fs", "get", fsName}
|
||||
buf, err := NewCephCommand(context, clusterInfo, args).Run()
|
||||
if err != nil {
|
||||
@@ -183,7 +185,7 @@ func SetNumMDSRanks(context *clusterd.Context, clusterInfo *ClusterInfo, fsName
|
||||
|
||||
// FailAllStandbyReplayMDS: fail all mds in up:standby-replay state
|
||||
func FailAllStandbyReplayMDS(context *clusterd.Context, clusterInfo *ClusterInfo, fsName string) error {
|
||||
fs, err := GetFilesystem(context, clusterInfo, fsName)
|
||||
fs, err := getFilesystem(context, clusterInfo, fsName)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to fail standby-replay MDSes for fs %q", fsName)
|
||||
}
|
||||
@@ -199,7 +201,7 @@ func FailAllStandbyReplayMDS(context *clusterd.Context, clusterInfo *ClusterInfo
|
||||
|
||||
// GetMdsIdByRank get mds ID from the given rank
|
||||
func GetMdsIdByRank(context *clusterd.Context, clusterInfo *ClusterInfo, fsName string, rank int32) (string, error) {
|
||||
fs, err := GetFilesystem(context, clusterInfo, fsName)
|
||||
fs, err := getFilesystem(context, clusterInfo, fsName)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to get ceph fs dump")
|
||||
}
|
||||
@@ -230,7 +232,7 @@ func WaitForActiveRanks(
|
||||
logger.Infof("waiting %.2f second(s) for number of active mds daemons for fs %s to become %s",
|
||||
float64(timeout/time.Second), fsName, countText)
|
||||
err := wait.Poll(3*time.Second, timeout, func() (bool, error) {
|
||||
fs, err := GetFilesystem(context, clusterInfo, fsName)
|
||||
fs, err := getFilesystem(context, clusterInfo, fsName)
|
||||
if err != nil {
|
||||
logger.Errorf(
|
||||
"Error getting filesystem %q details while waiting for num mds ranks to become %d. %v",
|
||||
@@ -295,7 +297,7 @@ func FailFilesystem(context *clusterd.Context, clusterInfo *ClusterInfo, fsName
|
||||
// RemoveFilesystem performs software configuration steps to remove a Ceph filesystem and its
|
||||
// backing pools.
|
||||
func RemoveFilesystem(context *clusterd.Context, clusterInfo *ClusterInfo, fsName string, preservePoolsOnDelete bool) error {
|
||||
fs, err := GetFilesystem(context, clusterInfo, fsName)
|
||||
fs, err := getFilesystem(context, clusterInfo, fsName)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "filesystem %s not found", fsName)
|
||||
}
|
||||
|
||||
@@ -18,13 +18,16 @@ package file
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
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"
|
||||
"github.com/rook/rook/pkg/util"
|
||||
"github.com/rook/rook/pkg/util/dependents"
|
||||
kexec "github.com/rook/rook/pkg/util/exec"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
@@ -50,15 +53,36 @@ var ignoredDependentSubvolumeGroups = []string{"_nogroup", "_index", "_legacy",
|
||||
// groups with no subvolumes don't block deletion.
|
||||
var CephFilesystemDependents = cephFilesystemDependents
|
||||
|
||||
// check filesystem whether it exists
|
||||
func filesystemExists(clusterdCtx *clusterd.Context, clusterInfo *client.ClusterInfo, name, nsName string) (bool, error) {
|
||||
_, err := cephclient.GetFilesystem(clusterdCtx, clusterInfo, name)
|
||||
if err != nil {
|
||||
if code, ok := kexec.ExitStatus(err); ok && code == int(syscall.ENOENT) {
|
||||
logger.Infof("filesystem %q deletion will continue without checking for dependencies since the the filesystem does not exist within Ceph", nsName)
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrapf(err, "failed to check for existence of CephFilesystem %q", nsName)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// with above, allow this to be overridden for unit testing
|
||||
func cephFilesystemDependents(clusterdCtx *clusterd.Context, clusterInfo *client.ClusterInfo, filesystem *v1.CephFilesystem) (*dependents.DependentList, error) {
|
||||
nsName := fmt.Sprintf("%s/%s", filesystem.Namespace, filesystem.Name)
|
||||
baseErrMsg := fmt.Sprintf("failed to get dependents of CephFilesystem %q", nsName)
|
||||
|
||||
// subvolume groups that contain subvolumes
|
||||
deps, err := subvolumeGroupDependents(clusterdCtx, clusterInfo, filesystem)
|
||||
deps := dependents.NewDependentList()
|
||||
fsExists, err := filesystemExists(clusterdCtx, clusterInfo, filesystem.Name, nsName)
|
||||
if err != nil {
|
||||
return deps, errors.Wrapf(err, baseErrMsg)
|
||||
return deps, nil
|
||||
}
|
||||
|
||||
// subvolume groups that contain subvolumes
|
||||
if fsExists {
|
||||
deps, err = subvolumeGroupDependents(clusterdCtx, clusterInfo, filesystem)
|
||||
if err != nil {
|
||||
return deps, errors.Wrapf(err, baseErrMsg)
|
||||
}
|
||||
}
|
||||
|
||||
// CephFilesystemSubVolumeGroups
|
||||
|
||||
@@ -19,6 +19,7 @@ package file
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -75,8 +76,27 @@ func TestCephFilesystemDependents(t *testing.T) {
|
||||
) (client.SubvolumeList, error) {
|
||||
return client.SubvolumeList{}, nil
|
||||
}
|
||||
noCephFilesystem := func(
|
||||
context *clusterd.Context, clusterInfo *client.ClusterInfo, fsName string,
|
||||
) (*client.CephFilesystemDetails, error) {
|
||||
return nil, syscall.Errno(2)
|
||||
}
|
||||
existsCephFilesystem := func(
|
||||
context *clusterd.Context, clusterInfo *client.ClusterInfo, fsName string,
|
||||
) (*client.CephFilesystemDetails, error) {
|
||||
return &client.CephFilesystemDetails{}, nil
|
||||
}
|
||||
|
||||
t.Run("no CephFilesystem found", func(t *testing.T) {
|
||||
client.GetFilesystem = noCephFilesystem
|
||||
c := newClusterdCtx()
|
||||
deps, err := CephFilesystemDependents(c, clusterInfo, fs)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, deps.Empty())
|
||||
})
|
||||
|
||||
t.Run("no blocking dependents", func(t *testing.T) {
|
||||
client.GetFilesystem = existsCephFilesystem
|
||||
client.ListSubvolumeGroups = noSubvolumeGroups
|
||||
client.ListSubvolumesInGroup = noSubvolumes
|
||||
|
||||
|
||||
@@ -44,6 +44,9 @@ func ExitStatus(err error) (int, bool) {
|
||||
|
||||
case *CephCLIError:
|
||||
return ExitStatus(e.err)
|
||||
case syscall.Errno:
|
||||
return int(e), true
|
||||
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
Reference in new issue
Block a user