If the cluster is external, users might still want to take advantage of the ceph-csi configmap configuration for ceph filesystem subvolume group. This configuration is handled by the controller whenever a cephFilesystemSubVolumeGroup CR is created or deleted. If the present cluster CephCluster is external, the controller (cephFilesystemSubVolumeGroup) won't handle creation nor deletion of sub volume groups. It just assumes that the given name is correct and the controller goes ahead with the ceph-csi configuration. Closes: #9551 Signed-off-by: Sébastien Han <seb@redhat.com>
58 lines
2.1 KiB
Go
58 lines
2.1 KiB
Go
/*
|
|
Copyright 2021 The Rook Authors. All rights reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package client
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/rook/rook/pkg/clusterd"
|
|
)
|
|
|
|
// CreateCephFSSubVolumeGroup create a CephFS subvolume group.
|
|
// volName is the name of the Ceph FS volume, the same as the CephFilesystem CR name.
|
|
func CreateCephFSSubVolumeGroup(context *clusterd.Context, clusterInfo *ClusterInfo, volName, groupName string) error {
|
|
logger.Infof("creating cephfs subvolume group %q", volName)
|
|
// [--pool_layout <data_pool_name>] [--uid <uid>] [--gid <gid>] [--mode <octal_mode>]
|
|
args := []string{"fs", "subvolumegroup", "create", volName, groupName}
|
|
cmd := NewCephCommand(context, clusterInfo, args)
|
|
cmd.JsonOutput = false
|
|
output, err := cmd.Run()
|
|
if err != nil {
|
|
return errors.Wrapf(err, "failed to create subvolume group %q. %s", volName, output)
|
|
}
|
|
|
|
logger.Infof("successfully created cephfs subvolume group %q", volName)
|
|
return nil
|
|
}
|
|
|
|
// DeleteCephFSSubVolumeGroup delete a CephFS subvolume group.
|
|
func DeleteCephFSSubVolumeGroup(context *clusterd.Context, clusterInfo *ClusterInfo, volName, groupName string) error {
|
|
logger.Infof("deleting cephfs subvolume group %q", volName)
|
|
// --force?
|
|
args := []string{"fs", "subvolumegroup", "rm", volName, groupName}
|
|
cmd := NewCephCommand(context, clusterInfo, args)
|
|
cmd.JsonOutput = false
|
|
output, err := cmd.Run()
|
|
if err != nil {
|
|
logger.Debugf("failed to delete subvolume group %q. %s. %v", volName, output, err)
|
|
// Intentionally don't wrap the error so the caller can inspect the return code
|
|
return err
|
|
}
|
|
|
|
logger.Infof("successfully deleted cephfs subvolume group %q", volName)
|
|
return nil
|
|
}
|