mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #85056 from pohsienshih/volume/golint
Fix golint issues for pkg/volume/rbd
This commit is contained in:
commit
ac55a51034
@ -210,7 +210,6 @@ pkg/volume/azure_file
|
||||
pkg/volume/csi/fake
|
||||
pkg/volume/git_repo
|
||||
pkg/volume/iscsi
|
||||
pkg/volume/rbd
|
||||
pkg/volume/testing
|
||||
pkg/volume/util/fs
|
||||
pkg/volume/util/volumepathhandler
|
||||
|
@ -32,7 +32,7 @@ import (
|
||||
|
||||
// NewAttacher implements AttachableVolumePlugin.NewAttacher.
|
||||
func (plugin *rbdPlugin) NewAttacher() (volume.Attacher, error) {
|
||||
return plugin.newAttacherInternal(&RBDUtil{})
|
||||
return plugin.newAttacherInternal(&rbdUtil{})
|
||||
}
|
||||
|
||||
// NewDeviceMounter implements DeviceMountableVolumePlugin.NewDeviceMounter
|
||||
@ -50,7 +50,7 @@ func (plugin *rbdPlugin) newAttacherInternal(manager diskManager) (volume.Attach
|
||||
|
||||
// NewDetacher implements AttachableVolumePlugin.NewDetacher.
|
||||
func (plugin *rbdPlugin) NewDetacher() (volume.Detacher, error) {
|
||||
return plugin.newDetacherInternal(&RBDUtil{})
|
||||
return plugin.newDetacherInternal(&rbdUtil{})
|
||||
}
|
||||
|
||||
// NewDeviceUnmounter implements DeviceMountableVolumePlugin.NewDeviceUnmounter
|
||||
|
@ -48,7 +48,7 @@ var (
|
||||
supportedFeatures = sets.NewString("layering")
|
||||
)
|
||||
|
||||
// This is the primary entrypoint for volume plugins.
|
||||
// ProbeVolumePlugins is the primary entrypoint for volume plugins.
|
||||
func ProbeVolumePlugins() []volume.VolumePlugin {
|
||||
return []volume.VolumePlugin{&rbdPlugin{}}
|
||||
}
|
||||
@ -72,7 +72,7 @@ const (
|
||||
secretKeyName = "key" // key name used in secret
|
||||
rbdImageFormat1 = "1"
|
||||
rbdImageFormat2 = "2"
|
||||
rbdDefaultAdminId = "admin"
|
||||
rbdDefaultAdminID = "admin"
|
||||
rbdDefaultAdminSecretNamespace = "default"
|
||||
rbdDefaultPool = "rbd"
|
||||
)
|
||||
@ -154,7 +154,7 @@ func (plugin *rbdPlugin) getAdminAndSecret(spec *volume.Spec) (string, string, e
|
||||
}
|
||||
|
||||
if admin == "" {
|
||||
admin = rbdDefaultAdminId
|
||||
admin = rbdDefaultAdminID
|
||||
}
|
||||
secret, err := parsePVSecret(adminSecretNamespace, adminSecretName, plugin.host.GetKubeClient())
|
||||
if err != nil {
|
||||
@ -182,12 +182,12 @@ func (plugin *rbdPlugin) ExpandVolumeDevice(spec *volume.Spec, newSize resource.
|
||||
Image: spec.PersistentVolume.Spec.RBD.RBDImage,
|
||||
Pool: spec.PersistentVolume.Spec.RBD.RBDPool,
|
||||
plugin: plugin,
|
||||
manager: &RBDUtil{},
|
||||
manager: &rbdUtil{},
|
||||
mounter: &mount.SafeFormatAndMount{Interface: plugin.host.GetMounter(plugin.GetPluginName())},
|
||||
exec: plugin.host.GetExec(plugin.GetPluginName()),
|
||||
},
|
||||
Mon: spec.PersistentVolume.Spec.RBD.CephMonitors,
|
||||
adminId: admin,
|
||||
adminID: admin,
|
||||
adminSecret: secret,
|
||||
},
|
||||
}
|
||||
@ -195,9 +195,9 @@ func (plugin *rbdPlugin) ExpandVolumeDevice(spec *volume.Spec, newSize resource.
|
||||
expandedSize, err := expander.ResizeImage(oldSize, newSize)
|
||||
if err != nil {
|
||||
return oldSize, err
|
||||
} else {
|
||||
return expandedSize, nil
|
||||
}
|
||||
return expandedSize, nil
|
||||
|
||||
}
|
||||
|
||||
func (plugin *rbdPlugin) NodeExpand(resizeOptions volume.NodeResizeOptions) (bool, error) {
|
||||
@ -283,9 +283,9 @@ func (plugin *rbdPlugin) createMounterFromVolumeSpecAndPod(spec *volume.Spec, po
|
||||
}
|
||||
|
||||
return &rbdMounter{
|
||||
rbd: newRBD("", spec.Name(), img, pool, ro, plugin, &RBDUtil{}),
|
||||
rbd: newRBD("", spec.Name(), img, pool, ro, plugin, &rbdUtil{}),
|
||||
Mon: mon,
|
||||
Id: id,
|
||||
ID: id,
|
||||
Keyring: keyring,
|
||||
Secret: secret,
|
||||
fsType: fstype,
|
||||
@ -316,7 +316,7 @@ func (plugin *rbdPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, _ volume.Vol
|
||||
}
|
||||
|
||||
// Inject real implementations here, test through the internal function.
|
||||
return plugin.newMounterInternal(spec, pod.UID, &RBDUtil{}, secret)
|
||||
return plugin.newMounterInternal(spec, pod.UID, &rbdUtil{}, secret)
|
||||
}
|
||||
|
||||
func (plugin *rbdPlugin) newMounterInternal(spec *volume.Spec, podUID types.UID, manager diskManager, secret string) (volume.Mounter, error) {
|
||||
@ -356,7 +356,7 @@ func (plugin *rbdPlugin) newMounterInternal(spec *volume.Spec, podUID types.UID,
|
||||
return &rbdMounter{
|
||||
rbd: newRBD(podUID, spec.Name(), img, pool, ro, plugin, manager),
|
||||
Mon: mon,
|
||||
Id: id,
|
||||
ID: id,
|
||||
Keyring: keyring,
|
||||
Secret: secret,
|
||||
fsType: fstype,
|
||||
@ -367,7 +367,7 @@ func (plugin *rbdPlugin) newMounterInternal(spec *volume.Spec, podUID types.UID,
|
||||
|
||||
func (plugin *rbdPlugin) NewUnmounter(volName string, podUID types.UID) (volume.Unmounter, error) {
|
||||
// Inject real implementations here, test through the internal function.
|
||||
return plugin.newUnmounterInternal(volName, podUID, &RBDUtil{})
|
||||
return plugin.newUnmounterInternal(volName, podUID, &rbdUtil{})
|
||||
}
|
||||
|
||||
func (plugin *rbdPlugin) newUnmounterInternal(volName string, podUID types.UID, manager diskManager) (volume.Unmounter, error) {
|
||||
@ -498,7 +498,7 @@ func (plugin *rbdPlugin) NewBlockVolumeMapper(spec *volume.Spec, pod *v1.Pod, _
|
||||
}
|
||||
}
|
||||
|
||||
return plugin.newBlockVolumeMapperInternal(spec, uid, &RBDUtil{}, secret, plugin.host.GetMounter(plugin.GetPluginName()), plugin.host.GetExec(plugin.GetPluginName()))
|
||||
return plugin.newBlockVolumeMapperInternal(spec, uid, &rbdUtil{}, secret, plugin.host.GetMounter(plugin.GetPluginName()), plugin.host.GetExec(plugin.GetPluginName()))
|
||||
}
|
||||
|
||||
func (plugin *rbdPlugin) newBlockVolumeMapperInternal(spec *volume.Spec, podUID types.UID, manager diskManager, secret string, mounter mount.Interface, exec utilexec.Interface) (volume.BlockVolumeMapper, error) {
|
||||
@ -537,7 +537,7 @@ func (plugin *rbdPlugin) newBlockVolumeMapperInternal(spec *volume.Spec, podUID
|
||||
}
|
||||
|
||||
func (plugin *rbdPlugin) NewBlockVolumeUnmapper(volName string, podUID types.UID) (volume.BlockVolumeUnmapper, error) {
|
||||
return plugin.newUnmapperInternal(volName, podUID, &RBDUtil{})
|
||||
return plugin.newUnmapperInternal(volName, podUID, &rbdUtil{})
|
||||
}
|
||||
|
||||
func (plugin *rbdPlugin) newUnmapperInternal(volName string, podUID types.UID, manager diskManager) (volume.BlockVolumeUnmapper, error) {
|
||||
@ -575,7 +575,7 @@ func (plugin *rbdPlugin) NewDeleter(spec *volume.Spec) (volume.Deleter, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return plugin.newDeleterInternal(spec, admin, secret, &RBDUtil{})
|
||||
return plugin.newDeleterInternal(spec, admin, secret, &rbdUtil{})
|
||||
}
|
||||
|
||||
func (plugin *rbdPlugin) newDeleterInternal(spec *volume.Spec, admin, secret string, manager diskManager) (volume.Deleter, error) {
|
||||
@ -583,13 +583,13 @@ func (plugin *rbdPlugin) newDeleterInternal(spec *volume.Spec, admin, secret str
|
||||
rbdMounter: &rbdMounter{
|
||||
rbd: newRBD("", spec.Name(), spec.PersistentVolume.Spec.RBD.RBDImage, spec.PersistentVolume.Spec.RBD.RBDPool, false, plugin, manager),
|
||||
Mon: spec.PersistentVolume.Spec.RBD.CephMonitors,
|
||||
adminId: admin,
|
||||
adminID: admin,
|
||||
adminSecret: secret,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func (plugin *rbdPlugin) NewProvisioner(options volume.VolumeOptions) (volume.Provisioner, error) {
|
||||
return plugin.newProvisionerInternal(options, &RBDUtil{})
|
||||
return plugin.newProvisionerInternal(options, &rbdUtil{})
|
||||
}
|
||||
|
||||
func (plugin *rbdPlugin) newProvisionerInternal(options volume.VolumeOptions, manager diskManager) (volume.Provisioner, error) {
|
||||
@ -633,13 +633,13 @@ func (r *rbdVolumeProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
|
||||
arr := dstrings.Split(v, ",")
|
||||
r.Mon = append(r.Mon, arr...)
|
||||
case "adminid":
|
||||
r.adminId = v
|
||||
r.adminID = v
|
||||
case "adminsecretname":
|
||||
adminSecretName = v
|
||||
case "adminsecretnamespace":
|
||||
adminSecretNamespace = v
|
||||
case "userid":
|
||||
r.Id = v
|
||||
r.ID = v
|
||||
case "pool":
|
||||
r.Pool = v
|
||||
case "usersecretname":
|
||||
@ -655,9 +655,8 @@ func (r *rbdVolumeProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
|
||||
for _, f := range arr {
|
||||
if !supportedFeatures.Has(f) {
|
||||
return nil, fmt.Errorf("invalid feature %q for volume plugin %s, supported features are: %v", f, r.plugin.GetPluginName(), supportedFeatures)
|
||||
} else {
|
||||
r.imageFeatures = append(r.imageFeatures, f)
|
||||
}
|
||||
r.imageFeatures = append(r.imageFeatures, f)
|
||||
}
|
||||
case volume.VolumeParameterFSType:
|
||||
fstype = v
|
||||
@ -684,14 +683,14 @@ func (r *rbdVolumeProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
|
||||
if secretName == "" && keyring == "" {
|
||||
return nil, fmt.Errorf("must specify either keyring or user secret name")
|
||||
}
|
||||
if r.adminId == "" {
|
||||
r.adminId = rbdDefaultAdminId
|
||||
if r.adminID == "" {
|
||||
r.adminID = rbdDefaultAdminID
|
||||
}
|
||||
if r.Pool == "" {
|
||||
r.Pool = rbdDefaultPool
|
||||
}
|
||||
if r.Id == "" {
|
||||
r.Id = r.adminId
|
||||
if r.ID == "" {
|
||||
r.ID = r.adminID
|
||||
}
|
||||
|
||||
// create random image name
|
||||
@ -727,7 +726,7 @@ func (r *rbdVolumeProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
|
||||
}
|
||||
}
|
||||
|
||||
rbd.RadosUser = r.Id
|
||||
rbd.RadosUser = r.ID
|
||||
rbd.FSType = fstype
|
||||
pv.Spec.PersistentVolumeSource.RBD = rbd
|
||||
pv.Spec.PersistentVolumeReclaimPolicy = r.options.PersistentVolumeReclaimPolicy
|
||||
@ -808,12 +807,12 @@ type rbdMounter struct {
|
||||
*rbd
|
||||
// capitalized so they can be exported in persistRBD()
|
||||
Mon []string
|
||||
Id string
|
||||
ID string
|
||||
Keyring string
|
||||
Secret string
|
||||
fsType string
|
||||
adminSecret string
|
||||
adminId string
|
||||
adminID string
|
||||
mountOptions []string
|
||||
imageFormat string
|
||||
imageFeatures []string
|
||||
@ -822,10 +821,10 @@ type rbdMounter struct {
|
||||
|
||||
var _ volume.Mounter = &rbdMounter{}
|
||||
|
||||
func (b *rbd) GetAttributes() volume.Attributes {
|
||||
func (rbd *rbd) GetAttributes() volume.Attributes {
|
||||
return volume.Attributes{
|
||||
ReadOnly: b.ReadOnly,
|
||||
Managed: !b.ReadOnly,
|
||||
ReadOnly: rbd.ReadOnly,
|
||||
Managed: !rbd.ReadOnly,
|
||||
SupportsSELinux: true,
|
||||
}
|
||||
}
|
||||
@ -890,7 +889,7 @@ type rbdDiskMapper struct {
|
||||
keyring string
|
||||
secret string
|
||||
adminSecret string
|
||||
adminId string
|
||||
adminID string
|
||||
imageFormat string
|
||||
imageFeatures []string
|
||||
}
|
||||
@ -930,7 +929,7 @@ func (rbd *rbd) rbdGlobalMapPath(spec *volume.Spec) (string, error) {
|
||||
}
|
||||
|
||||
mounter := &rbdMounter{
|
||||
rbd: newRBD("", spec.Name(), img, pool, ro, rbd.plugin, &RBDUtil{}),
|
||||
rbd: newRBD("", spec.Name(), img, pool, ro, rbd.plugin, &rbdUtil{}),
|
||||
Mon: mon,
|
||||
}
|
||||
return rbd.manager.MakeGlobalVDPDName(*mounter.rbd), nil
|
||||
@ -1082,9 +1081,8 @@ func getVolumeAccessModes(spec *volume.Spec) ([]v1.PersistentVolumeAccessMode, e
|
||||
if spec.PersistentVolume != nil {
|
||||
if spec.PersistentVolume.Spec.RBD != nil {
|
||||
return spec.PersistentVolume.Spec.AccessModes, nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("Spec does not reference a RBD volume type")
|
||||
}
|
||||
return nil, fmt.Errorf("Spec does not reference a RBD volume type")
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
|
@ -140,7 +140,7 @@ type fakeDiskManager struct {
|
||||
rbdDevices map[string]bool
|
||||
}
|
||||
|
||||
func NewFakeDiskManager() *fakeDiskManager {
|
||||
func newFakeDiskManager() *fakeDiskManager {
|
||||
return &fakeDiskManager{
|
||||
rbdImageLocks: make(map[string]bool),
|
||||
rbdMapIndex: 0,
|
||||
@ -256,7 +256,7 @@ func doTestPlugin(t *testing.T, c *testcase) {
|
||||
}
|
||||
fakeMounter := fakeVolumeHost.GetMounter(plug.GetPluginName()).(*mount.FakeMounter)
|
||||
fakeNodeName := types.NodeName("localhost")
|
||||
fdm := NewFakeDiskManager()
|
||||
fdm := newFakeDiskManager()
|
||||
|
||||
// attacher
|
||||
attacher, err := plug.(*rbdPlugin).newAttacherInternal(fdm)
|
||||
@ -539,7 +539,7 @@ func TestGetDeviceMountPath(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Can't find the plugin by name")
|
||||
}
|
||||
fdm := NewFakeDiskManager()
|
||||
fdm := newFakeDiskManager()
|
||||
|
||||
// attacher
|
||||
attacher, err := plug.(*rbdPlugin).newAttacherInternal(fdm)
|
||||
|
@ -79,15 +79,15 @@ func getDevFromImageAndPool(pool, image string) (string, bool) {
|
||||
// Search /sys/bus for rbd device that matches given pool and image.
|
||||
func getRbdDevFromImageAndPool(pool string, image string) (string, bool) {
|
||||
// /sys/bus/rbd/devices/X/name and /sys/bus/rbd/devices/X/pool
|
||||
sys_path := "/sys/bus/rbd/devices"
|
||||
if dirs, err := ioutil.ReadDir(sys_path); err == nil {
|
||||
sysPath := "/sys/bus/rbd/devices"
|
||||
if dirs, err := ioutil.ReadDir(sysPath); err == nil {
|
||||
for _, f := range dirs {
|
||||
// Pool and name format:
|
||||
// see rbd_pool_show() and rbd_name_show() at
|
||||
// https://github.com/torvalds/linux/blob/master/drivers/block/rbd.c
|
||||
name := f.Name()
|
||||
// First match pool, then match name.
|
||||
poolFile := filepath.Join(sys_path, name, "pool")
|
||||
poolFile := filepath.Join(sysPath, name, "pool")
|
||||
poolBytes, err := ioutil.ReadFile(poolFile)
|
||||
if err != nil {
|
||||
klog.V(4).Infof("error reading %s: %v", poolFile, err)
|
||||
@ -97,7 +97,7 @@ func getRbdDevFromImageAndPool(pool string, image string) (string, bool) {
|
||||
klog.V(4).Infof("device %s is not %q: %q", name, pool, string(poolBytes))
|
||||
continue
|
||||
}
|
||||
imgFile := filepath.Join(sys_path, name, "name")
|
||||
imgFile := filepath.Join(sysPath, name, "name")
|
||||
imgBytes, err := ioutil.ReadFile(imgFile)
|
||||
if err != nil {
|
||||
klog.V(4).Infof("error reading %s: %v", imgFile, err)
|
||||
@ -230,11 +230,10 @@ func execRbdMap(b rbdMounter, rbdCmd string, mon string) ([]byte, error) {
|
||||
imgPath := fmt.Sprintf("%s/%s", b.Pool, b.Image)
|
||||
if b.Secret != "" {
|
||||
return b.exec.Command(rbdCmd,
|
||||
"map", imgPath, "--id", b.Id, "-m", mon, "--key="+b.Secret).CombinedOutput()
|
||||
} else {
|
||||
return b.exec.Command(rbdCmd,
|
||||
"map", imgPath, "--id", b.Id, "-m", mon, "-k", b.Keyring).CombinedOutput()
|
||||
"map", imgPath, "--id", b.ID, "-m", mon, "--key="+b.Secret).CombinedOutput()
|
||||
}
|
||||
return b.exec.Command(rbdCmd,
|
||||
"map", imgPath, "--id", b.ID, "-m", mon, "-k", b.Keyring).CombinedOutput()
|
||||
}
|
||||
|
||||
// Check if rbd-nbd tools are installed.
|
||||
@ -271,16 +270,18 @@ func makeVDPDNameInternal(host volume.VolumeHost, pool string, image string) str
|
||||
return filepath.Join(host.GetVolumeDevicePluginDir(rbdPluginName), pool+"-image-"+image)
|
||||
}
|
||||
|
||||
// RBDUtil implements diskManager interface.
|
||||
type RBDUtil struct{}
|
||||
// rbdUtil implements diskManager interface.
|
||||
type rbdUtil struct{}
|
||||
|
||||
var _ diskManager = &RBDUtil{}
|
||||
var _ diskManager = &rbdUtil{}
|
||||
|
||||
func (util *RBDUtil) MakeGlobalPDName(rbd rbd) string {
|
||||
// MakeGlobalPDName makes a plugin directory.
|
||||
func (util *rbdUtil) MakeGlobalPDName(rbd rbd) string {
|
||||
return makePDNameInternal(rbd.plugin.host, rbd.Pool, rbd.Image)
|
||||
}
|
||||
|
||||
func (util *RBDUtil) MakeGlobalVDPDName(rbd rbd) string {
|
||||
// MakeGlobalVDPDName makes a volume device plugin directory.
|
||||
func (util *rbdUtil) MakeGlobalVDPDName(rbd rbd) string {
|
||||
return makeVDPDNameInternal(rbd.plugin.host, rbd.Pool, rbd.Image)
|
||||
}
|
||||
|
||||
@ -302,24 +303,24 @@ func rbdErrors(runErr, resultErr error) error {
|
||||
// Also, libceph module chooses monitor randomly, so we can simply pass all
|
||||
// addresses without randomization (see
|
||||
// https://github.com/torvalds/linux/blob/602adf400201636e95c3fed9f31fba54a3d7e844/net/ceph/mon_client.c#L132).
|
||||
func (util *RBDUtil) kernelRBDMonitorsOpt(mons []string) string {
|
||||
func (util *rbdUtil) kernelRBDMonitorsOpt(mons []string) string {
|
||||
return strings.Join(mons, ",")
|
||||
}
|
||||
|
||||
// rbdUnlock releases a lock on image if found.
|
||||
func (util *RBDUtil) rbdUnlock(b rbdMounter) error {
|
||||
func (util *rbdUtil) rbdUnlock(b rbdMounter) error {
|
||||
var err error
|
||||
var output, locker string
|
||||
var cmd []byte
|
||||
var secret_opt []string
|
||||
var secretOpt []string
|
||||
|
||||
if b.Secret != "" {
|
||||
secret_opt = []string{"--key=" + b.Secret}
|
||||
secretOpt = []string{"--key=" + b.Secret}
|
||||
} else {
|
||||
secret_opt = []string{"-k", b.Keyring}
|
||||
secretOpt = []string{"-k", b.Keyring}
|
||||
}
|
||||
if len(b.adminId) == 0 {
|
||||
b.adminId = b.Id
|
||||
if len(b.adminID) == 0 {
|
||||
b.adminID = b.ID
|
||||
}
|
||||
if len(b.adminSecret) == 0 {
|
||||
b.adminSecret = b.Secret
|
||||
@ -330,20 +331,20 @@ func (util *RBDUtil) rbdUnlock(b rbdMounter) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lock_id := kubeLockMagic + hostName
|
||||
lockID := kubeLockMagic + hostName
|
||||
|
||||
mon := util.kernelRBDMonitorsOpt(b.Mon)
|
||||
|
||||
// Get the locker name, something like "client.1234".
|
||||
args := []string{"lock", "list", b.Image, "--pool", b.Pool, "--id", b.Id, "-m", mon}
|
||||
args = append(args, secret_opt...)
|
||||
args := []string{"lock", "list", b.Image, "--pool", b.Pool, "--id", b.ID, "-m", mon}
|
||||
args = append(args, secretOpt...)
|
||||
cmd, err = b.exec.Command("rbd", args...).CombinedOutput()
|
||||
output = string(cmd)
|
||||
klog.V(4).Infof("lock list output %q", output)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ind := strings.LastIndex(output, lock_id) - 1
|
||||
ind := strings.LastIndex(output, lockID) - 1
|
||||
for i := ind; i >= 0; i-- {
|
||||
if output[i] == '\n' {
|
||||
locker = output[(i + 1):ind]
|
||||
@ -353,13 +354,13 @@ func (util *RBDUtil) rbdUnlock(b rbdMounter) error {
|
||||
|
||||
// Remove a lock if found: rbd lock remove.
|
||||
if len(locker) > 0 {
|
||||
args := []string{"lock", "remove", b.Image, lock_id, locker, "--pool", b.Pool, "--id", b.Id, "-m", mon}
|
||||
args = append(args, secret_opt...)
|
||||
args := []string{"lock", "remove", b.Image, lockID, locker, "--pool", b.Pool, "--id", b.ID, "-m", mon}
|
||||
args = append(args, secretOpt...)
|
||||
_, err = b.exec.Command("rbd", args...).CombinedOutput()
|
||||
if err == nil {
|
||||
klog.V(4).Infof("rbd: successfully remove lock (locker_id: %s) on image: %s/%s with id %s mon %s", lock_id, b.Pool, b.Image, b.Id, mon)
|
||||
klog.V(4).Infof("rbd: successfully remove lock (locker_id: %s) on image: %s/%s with id %s mon %s", lockID, b.Pool, b.Image, b.ID, mon)
|
||||
} else {
|
||||
klog.Warningf("rbd: failed to remove lock (lock_id: %s) on image: %s/%s with id %s mon %s: %v", lock_id, b.Pool, b.Image, b.Id, mon, err)
|
||||
klog.Warningf("rbd: failed to remove lock (lockID: %s) on image: %s/%s with id %s mon %s: %v", lockID, b.Pool, b.Image, b.ID, mon, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -367,7 +368,7 @@ func (util *RBDUtil) rbdUnlock(b rbdMounter) error {
|
||||
}
|
||||
|
||||
// AttachDisk attaches the disk on the node.
|
||||
func (util *RBDUtil) AttachDisk(b rbdMounter) (string, error) {
|
||||
func (util *rbdUtil) AttachDisk(b rbdMounter) (string, error) {
|
||||
var output []byte
|
||||
|
||||
globalPDPath := util.MakeGlobalPDName(*b.rbd)
|
||||
@ -467,7 +468,7 @@ func (util *RBDUtil) AttachDisk(b rbdMounter) (string, error) {
|
||||
// DetachDisk detaches the disk from the node.
|
||||
// It detaches device from the node if device is provided, and removes the lock
|
||||
// if there is persisted RBD info under deviceMountPath.
|
||||
func (util *RBDUtil) DetachDisk(plugin *rbdPlugin, deviceMountPath string, device string) error {
|
||||
func (util *rbdUtil) DetachDisk(plugin *rbdPlugin, deviceMountPath string, device string) error {
|
||||
if len(device) == 0 {
|
||||
return fmt.Errorf("DetachDisk failed , device is empty")
|
||||
}
|
||||
@ -511,7 +512,7 @@ func (util *RBDUtil) DetachDisk(plugin *rbdPlugin, deviceMountPath string, devic
|
||||
}
|
||||
|
||||
// DetachBlockDisk detaches the disk from the node.
|
||||
func (util *RBDUtil) DetachBlockDisk(disk rbdDiskUnmapper, mapPath string) error {
|
||||
func (util *rbdUtil) DetachBlockDisk(disk rbdDiskUnmapper, mapPath string) error {
|
||||
|
||||
if pathExists, pathErr := mount.PathExists(mapPath); pathErr != nil {
|
||||
return fmt.Errorf("Error checking if path exists: %v", pathErr)
|
||||
@ -555,7 +556,7 @@ func (util *RBDUtil) DetachBlockDisk(disk rbdDiskUnmapper, mapPath string) error
|
||||
|
||||
// cleanOldRBDFile read rbd info from rbd.json file and removes lock if found.
|
||||
// At last, it removes rbd.json file.
|
||||
func (util *RBDUtil) cleanOldRBDFile(plugin *rbdPlugin, rbdFile string) error {
|
||||
func (util *rbdUtil) cleanOldRBDFile(plugin *rbdPlugin, rbdFile string) error {
|
||||
mounter := &rbdMounter{
|
||||
// util.rbdUnlock needs it to run command.
|
||||
rbd: newRBD("", "", "", "", false, plugin, util),
|
||||
@ -568,7 +569,7 @@ func (util *RBDUtil) cleanOldRBDFile(plugin *rbdPlugin, rbdFile string) error {
|
||||
|
||||
decoder := json.NewDecoder(fp)
|
||||
if err = decoder.Decode(mounter); err != nil {
|
||||
return fmt.Errorf("rbd: decode err: %v.", err)
|
||||
return fmt.Errorf("rbd: decode err: %v", err)
|
||||
}
|
||||
|
||||
// Remove rbd lock if found.
|
||||
@ -581,7 +582,8 @@ func (util *RBDUtil) cleanOldRBDFile(plugin *rbdPlugin, rbdFile string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (util *RBDUtil) CreateImage(p *rbdVolumeProvisioner) (r *v1.RBDPersistentVolumeSource, size int, err error) {
|
||||
// CreateImage creates a RBD image.
|
||||
func (util *rbdUtil) CreateImage(p *rbdVolumeProvisioner) (r *v1.RBDPersistentVolumeSource, size int, err error) {
|
||||
var output []byte
|
||||
capacity := p.options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]
|
||||
// Convert to MB that rbd defaults on.
|
||||
@ -592,11 +594,11 @@ func (util *RBDUtil) CreateImage(p *rbdVolumeProvisioner) (r *v1.RBDPersistentVo
|
||||
volSz := fmt.Sprintf("%d", sz)
|
||||
mon := util.kernelRBDMonitorsOpt(p.Mon)
|
||||
if p.rbdMounter.imageFormat == rbdImageFormat2 {
|
||||
klog.V(4).Infof("rbd: create %s size %s format %s (features: %s) using mon %s, pool %s id %s key %s", p.rbdMounter.Image, volSz, p.rbdMounter.imageFormat, p.rbdMounter.imageFeatures, mon, p.rbdMounter.Pool, p.rbdMounter.adminId, p.rbdMounter.adminSecret)
|
||||
klog.V(4).Infof("rbd: create %s size %s format %s (features: %s) using mon %s, pool %s id %s key %s", p.rbdMounter.Image, volSz, p.rbdMounter.imageFormat, p.rbdMounter.imageFeatures, mon, p.rbdMounter.Pool, p.rbdMounter.adminID, p.rbdMounter.adminSecret)
|
||||
} else {
|
||||
klog.V(4).Infof("rbd: create %s size %s format %s using mon %s, pool %s id %s key %s", p.rbdMounter.Image, volSz, p.rbdMounter.imageFormat, mon, p.rbdMounter.Pool, p.rbdMounter.adminId, p.rbdMounter.adminSecret)
|
||||
klog.V(4).Infof("rbd: create %s size %s format %s using mon %s, pool %s id %s key %s", p.rbdMounter.Image, volSz, p.rbdMounter.imageFormat, mon, p.rbdMounter.Pool, p.rbdMounter.adminID, p.rbdMounter.adminSecret)
|
||||
}
|
||||
args := []string{"create", p.rbdMounter.Image, "--size", volSz, "--pool", p.rbdMounter.Pool, "--id", p.rbdMounter.adminId, "-m", mon, "--key=" + p.rbdMounter.adminSecret, "--image-format", p.rbdMounter.imageFormat}
|
||||
args := []string{"create", p.rbdMounter.Image, "--size", volSz, "--pool", p.rbdMounter.Pool, "--id", p.rbdMounter.adminID, "-m", mon, "--key=" + p.rbdMounter.adminSecret, "--image-format", p.rbdMounter.imageFormat}
|
||||
if p.rbdMounter.imageFormat == rbdImageFormat2 {
|
||||
// If no image features is provided, it results in empty string
|
||||
// which disable all RBD image format 2 features as expected.
|
||||
@ -617,7 +619,8 @@ func (util *RBDUtil) CreateImage(p *rbdVolumeProvisioner) (r *v1.RBDPersistentVo
|
||||
}, sz, nil
|
||||
}
|
||||
|
||||
func (util *RBDUtil) DeleteImage(p *rbdVolumeDeleter) error {
|
||||
// DeleteImage deletes a RBD image.
|
||||
func (util *rbdUtil) DeleteImage(p *rbdVolumeDeleter) error {
|
||||
var output []byte
|
||||
found, rbdOutput, err := util.rbdStatus(p.rbdMounter)
|
||||
if err != nil {
|
||||
@ -629,9 +632,9 @@ func (util *RBDUtil) DeleteImage(p *rbdVolumeDeleter) error {
|
||||
}
|
||||
// rbd rm.
|
||||
mon := util.kernelRBDMonitorsOpt(p.rbdMounter.Mon)
|
||||
klog.V(4).Infof("rbd: rm %s using mon %s, pool %s id %s key %s", p.rbdMounter.Image, mon, p.rbdMounter.Pool, p.rbdMounter.adminId, p.rbdMounter.adminSecret)
|
||||
klog.V(4).Infof("rbd: rm %s using mon %s, pool %s id %s key %s", p.rbdMounter.Image, mon, p.rbdMounter.Pool, p.rbdMounter.adminID, p.rbdMounter.adminSecret)
|
||||
output, err = p.exec.Command("rbd",
|
||||
"rm", p.rbdMounter.Image, "--pool", p.rbdMounter.Pool, "--id", p.rbdMounter.adminId, "-m", mon, "--key="+p.rbdMounter.adminSecret).CombinedOutput()
|
||||
"rm", p.rbdMounter.Image, "--pool", p.rbdMounter.Pool, "--id", p.rbdMounter.adminID, "-m", mon, "--key="+p.rbdMounter.adminSecret).CombinedOutput()
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
@ -641,7 +644,7 @@ func (util *RBDUtil) DeleteImage(p *rbdVolumeDeleter) error {
|
||||
}
|
||||
|
||||
// ExpandImage runs rbd resize command to resize the specified image.
|
||||
func (util *RBDUtil) ExpandImage(rbdExpander *rbdVolumeExpander, oldSize resource.Quantity, newSize resource.Quantity) (resource.Quantity, error) {
|
||||
func (util *rbdUtil) ExpandImage(rbdExpander *rbdVolumeExpander, oldSize resource.Quantity, newSize resource.Quantity) (resource.Quantity, error) {
|
||||
var output []byte
|
||||
var err error
|
||||
|
||||
@ -661,9 +664,9 @@ func (util *RBDUtil) ExpandImage(rbdExpander *rbdVolumeExpander, oldSize resourc
|
||||
|
||||
// rbd resize.
|
||||
mon := util.kernelRBDMonitorsOpt(rbdExpander.rbdMounter.Mon)
|
||||
klog.V(4).Infof("rbd: resize %s using mon %s, pool %s id %s key %s", rbdExpander.rbdMounter.Image, mon, rbdExpander.rbdMounter.Pool, rbdExpander.rbdMounter.adminId, rbdExpander.rbdMounter.adminSecret)
|
||||
klog.V(4).Infof("rbd: resize %s using mon %s, pool %s id %s key %s", rbdExpander.rbdMounter.Image, mon, rbdExpander.rbdMounter.Pool, rbdExpander.rbdMounter.adminID, rbdExpander.rbdMounter.adminSecret)
|
||||
output, err = rbdExpander.exec.Command("rbd",
|
||||
"resize", rbdExpander.rbdMounter.Image, "--size", newVolSz, "--pool", rbdExpander.rbdMounter.Pool, "--id", rbdExpander.rbdMounter.adminId, "-m", mon, "--key="+rbdExpander.rbdMounter.adminSecret).CombinedOutput()
|
||||
"resize", rbdExpander.rbdMounter.Image, "--size", newVolSz, "--pool", rbdExpander.rbdMounter.Pool, "--id", rbdExpander.rbdMounter.adminID, "-m", mon, "--key="+rbdExpander.rbdMounter.adminSecret).CombinedOutput()
|
||||
if err == nil {
|
||||
return newSizeQuant, nil
|
||||
}
|
||||
@ -673,15 +676,15 @@ func (util *RBDUtil) ExpandImage(rbdExpander *rbdVolumeExpander, oldSize resourc
|
||||
}
|
||||
|
||||
// rbdInfo runs `rbd info` command to get the current image size in MB.
|
||||
func (util *RBDUtil) rbdInfo(b *rbdMounter) (int, error) {
|
||||
func (util *rbdUtil) rbdInfo(b *rbdMounter) (int, error) {
|
||||
var err error
|
||||
var output []byte
|
||||
|
||||
// If we don't have admin id/secret (e.g. attaching), fallback to user id/secret.
|
||||
id := b.adminId
|
||||
id := b.adminID
|
||||
secret := b.adminSecret
|
||||
if id == "" {
|
||||
id = b.Id
|
||||
id = b.ID
|
||||
secret = b.Secret
|
||||
}
|
||||
|
||||
@ -738,16 +741,16 @@ func getRbdImageSize(output []byte) (int, error) {
|
||||
}
|
||||
|
||||
// rbdStatus runs `rbd status` command to check if there is watcher on the image.
|
||||
func (util *RBDUtil) rbdStatus(b *rbdMounter) (bool, string, error) {
|
||||
func (util *rbdUtil) rbdStatus(b *rbdMounter) (bool, string, error) {
|
||||
var err error
|
||||
var output string
|
||||
var cmd []byte
|
||||
|
||||
// If we don't have admin id/secret (e.g. attaching), fallback to user id/secret.
|
||||
id := b.adminId
|
||||
id := b.adminID
|
||||
secret := b.adminSecret
|
||||
if id == "" {
|
||||
id = b.Id
|
||||
id = b.ID
|
||||
secret = b.Secret
|
||||
}
|
||||
|
||||
@ -787,10 +790,9 @@ func (util *RBDUtil) rbdStatus(b *rbdMounter) (bool, string, error) {
|
||||
if strings.Contains(output, imageWatcherStr) {
|
||||
klog.V(4).Infof("rbd: watchers on %s: %s", b.Image, output)
|
||||
return true, output, nil
|
||||
} else {
|
||||
klog.Warningf("rbd: no watchers on %s", b.Image)
|
||||
return false, output, nil
|
||||
}
|
||||
klog.Warningf("rbd: no watchers on %s", b.Image)
|
||||
return false, output, nil
|
||||
}
|
||||
|
||||
// getRbdImageInfo try to get rbdImageInfo from deviceMountPath.
|
||||
|
Loading…
Reference in New Issue
Block a user