Enhancement of Ceph volume manager kmod detection
Current Ceph volume manager code doesn't take the builtin kernel module into the account, so the `modinfo` will fail in this case. Also, we need to add error handling code to make sure the volume manager does work when proceeding to continue, otherwise we will encounter the `rbd` related issue in the following step even we have an artificial `agent` pod in running state. Signed-off-by: Dennis Chen <dennis.chen@arm.com>
This commit is contained in:
1 parent
5e4fba2aec
commit
9cfafaa0a7
3 files changed
+50
-8
No files matched your search
@@ -53,7 +53,10 @@ func (a *Agent) Run() error {
|
||||
return fmt.Errorf("failed to create volume attachment controller: %+v", err)
|
||||
}
|
||||
|
||||
volumeManager := ceph.NewVolumeManager(a.context)
|
||||
volumeManager, err := ceph.NewVolumeManager(a.context)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create volume manager: %+v", err)
|
||||
}
|
||||
|
||||
flexvolumeController := flexvolume.NewController(a.context, volumeAttachmentController, volumeManager)
|
||||
|
||||
|
||||
@@ -52,17 +52,26 @@ type pathFinder interface {
|
||||
}
|
||||
|
||||
// NewVolumeManager create attacher for ceph volumes
|
||||
func NewVolumeManager(context *clusterd.Context) *VolumeManager {
|
||||
func NewVolumeManager(context *clusterd.Context) (*VolumeManager, error) {
|
||||
vm := &VolumeManager{
|
||||
context: context,
|
||||
devicePathFinder: &devicePathFinder{},
|
||||
}
|
||||
vm.Init()
|
||||
return vm
|
||||
err := vm.Init()
|
||||
return vm, err
|
||||
}
|
||||
|
||||
// Init the ceph volume manager
|
||||
func (vm *VolumeManager) Init() error {
|
||||
// check if the rbd is a builtin kernel module, if it is then we don't need to load it manually
|
||||
in, err := sys.IsBuiltinKernelModule(rbdKernelModuleName, vm.context.Executor)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if in == true {
|
||||
logger.Noticef("volume manager is a builtin kernel module, don't load it manually")
|
||||
return nil
|
||||
}
|
||||
|
||||
// check to see if the rbd kernel module has single_major support
|
||||
hasSingleMajor, err := sys.CheckKernelModuleParam(rbdKernelModuleName, "single_major", vm.context.Executor)
|
||||
@@ -77,9 +86,9 @@ func (vm *VolumeManager) Init() error {
|
||||
}
|
||||
|
||||
// load the rbd kernel module with options
|
||||
// TODO: should this fail if modprobe fails?
|
||||
if err := sys.LoadKernelModule(rbdKernelModuleName, opts, vm.context.Executor); err != nil {
|
||||
logger.Noticef("failed to load kernel module %s: %+v", rbdKernelModuleName, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
+33
-3
@@ -17,11 +17,41 @@ package sys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/rook/rook/pkg/util/exec"
|
||||
pkgexec "github.com/rook/rook/pkg/util/exec"
|
||||
)
|
||||
|
||||
func LoadKernelModule(name string, options []string, executor exec.Executor) error {
|
||||
func getKernelVersion() (string, error) {
|
||||
var output []byte
|
||||
cmd := exec.Command("uname", "-r")
|
||||
output, err := cmd.Output()
|
||||
out := strings.TrimSpace(string(output))
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func IsBuiltinKernelModule(name string, executor pkgexec.Executor) (bool, error) {
|
||||
kv, err := getKernelVersion()
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to get kernel version: %+v", err)
|
||||
}
|
||||
|
||||
kv = fmt.Sprintf("/lib/modules/%s/modules.builtin", kv)
|
||||
out, err := executor.ExecuteCommandWithCombinedOutput(false, "check builtin kmod", "cat", kv)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to cat %s: %+v", kv, err)
|
||||
}
|
||||
|
||||
result := Grep(out, name)
|
||||
return result != "", nil
|
||||
}
|
||||
|
||||
func LoadKernelModule(name string, options []string, executor pkgexec.Executor) error {
|
||||
if options == nil {
|
||||
options = []string{}
|
||||
}
|
||||
@@ -35,7 +65,7 @@ func LoadKernelModule(name string, options []string, executor exec.Executor) err
|
||||
return nil
|
||||
}
|
||||
|
||||
func CheckKernelModuleParam(name, param string, executor exec.Executor) (bool, error) {
|
||||
func CheckKernelModuleParam(name, param string, executor pkgexec.Executor) (bool, error) {
|
||||
out, err := executor.ExecuteCommandWithOutput(false, "check kmod param", "modinfo", "-F", "parm", name)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to check for %s module %s param: %+v", name, param, err)
|
||||
|
||||
Reference in new issue
Block a user