mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-10 00:10:20 +00:00
Fix golint issues
Signed-off-by: Madhu Rajanna <mrajanna@redhat.com>
This commit is contained in:
parent
9ddc265c10
commit
20af5afcab
@ -82,7 +82,7 @@ func getCephUser(adminCr *credentials, volId volumeID) (*cephEntity, error) {
|
||||
|
||||
func createCephUser(volOptions *volumeOptions, adminCr *credentials, volId volumeID) (*cephEntity, error) {
|
||||
caps := cephEntityCaps{
|
||||
Mds: fmt.Sprintf("allow rw path=%s", getVolumeRootPath_ceph(volId)),
|
||||
Mds: fmt.Sprintf("allow rw path=%s", getVolumeRootPathCeph(volId)),
|
||||
Mon: "allow r",
|
||||
Osd: fmt.Sprintf("allow rw pool=%s namespace=%s", volOptions.Pool, getVolumeNamespace(volId)),
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ type nodeServer struct {
|
||||
|
||||
func getCredentialsForVolume(volOptions *volumeOptions, volId volumeID, req *csi.NodeStageVolumeRequest) (*credentials, error) {
|
||||
var (
|
||||
userCr = &credentials{}
|
||||
userCr *credentials
|
||||
err error
|
||||
)
|
||||
|
||||
@ -95,7 +95,7 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
|
||||
|
||||
if volOptions.ProvisionVolume {
|
||||
// Dynamically provisioned volumes don't have their root path set, do it here
|
||||
volOptions.RootPath = getVolumeRootPath_ceph(volId)
|
||||
volOptions.RootPath = getVolumeRootPathCeph(volId)
|
||||
}
|
||||
|
||||
if err = createMountPoint(stagingTargetPath); err != nil {
|
||||
|
@ -29,15 +29,15 @@ const (
|
||||
namespacePrefix = "ns-"
|
||||
)
|
||||
|
||||
func getCephRootPath_local(volId volumeID) string {
|
||||
func getCephRootPathLocal(volId volumeID) string {
|
||||
return cephRootPrefix + string(volId)
|
||||
}
|
||||
|
||||
func getCephRootVolumePath_local(volId volumeID) string {
|
||||
return path.Join(getCephRootPath_local(volId), cephVolumesRoot, string(volId))
|
||||
func getCephRootVolumePathLocal(volId volumeID) string {
|
||||
return path.Join(getCephRootPathLocal(volId), cephVolumesRoot, string(volId))
|
||||
}
|
||||
|
||||
func getVolumeRootPath_ceph(volId volumeID) string {
|
||||
func getVolumeRootPathCeph(volId volumeID) string {
|
||||
return path.Join("/", cephVolumesRoot, string(volId))
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ func setVolumeAttribute(root, attrName, attrValue string) error {
|
||||
}
|
||||
|
||||
func createVolume(volOptions *volumeOptions, adminCr *credentials, volId volumeID, bytesQuota int64) error {
|
||||
cephRoot := getCephRootPath_local(volId)
|
||||
cephRoot := getCephRootPathLocal(volId)
|
||||
|
||||
if err := createMountPoint(cephRoot); err != nil {
|
||||
return err
|
||||
@ -74,8 +74,8 @@ func createVolume(volOptions *volumeOptions, adminCr *credentials, volId volumeI
|
||||
os.Remove(cephRoot)
|
||||
}()
|
||||
|
||||
volOptions.RootPath = getVolumeRootPath_ceph(volId)
|
||||
localVolRoot := getCephRootVolumePath_local(volId)
|
||||
volOptions.RootPath = getVolumeRootPathCeph(volId)
|
||||
localVolRoot := getCephRootVolumePathLocal(volId)
|
||||
|
||||
if err := createMountPoint(localVolRoot); err != nil {
|
||||
return err
|
||||
@ -100,8 +100,8 @@ func createVolume(volOptions *volumeOptions, adminCr *credentials, volId volumeI
|
||||
|
||||
func purgeVolume(volId volumeID, adminCr *credentials, volOptions *volumeOptions) error {
|
||||
var (
|
||||
cephRoot = getCephRootPath_local(volId)
|
||||
volRoot = getCephRootVolumePath_local(volId)
|
||||
cephRoot = getCephRootPathLocal(volId)
|
||||
volRoot = getCephRootVolumePathLocal(volId)
|
||||
volRootDeleting = volRoot + "-deleting"
|
||||
)
|
||||
|
||||
|
@ -24,8 +24,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
volumeMounter_fuse = "fuse"
|
||||
volumeMounter_kernel = "kernel"
|
||||
volumeMounterFuse = "fuse"
|
||||
volumeMounterKernel = "kernel"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -39,11 +39,11 @@ func loadAvailableMounters() error {
|
||||
kernelMounterProbe := exec.Command("mount.ceph")
|
||||
|
||||
if fuseMounterProbe.Run() == nil {
|
||||
availableMounters = append(availableMounters, volumeMounter_fuse)
|
||||
availableMounters = append(availableMounters, volumeMounterFuse)
|
||||
}
|
||||
|
||||
if kernelMounterProbe.Run() == nil {
|
||||
availableMounters = append(availableMounters, volumeMounter_kernel)
|
||||
availableMounters = append(availableMounters, volumeMounterKernel)
|
||||
}
|
||||
|
||||
if len(availableMounters) == 0 {
|
||||
@ -87,9 +87,9 @@ func newMounter(volOptions *volumeOptions) (volumeMounter, error) {
|
||||
// Create the mounter
|
||||
|
||||
switch chosenMounter {
|
||||
case volumeMounter_fuse:
|
||||
case volumeMounterFuse:
|
||||
return &fuseMounter{}, nil
|
||||
case volumeMounter_kernel:
|
||||
case volumeMounterKernel:
|
||||
return &kernelMounter{}, nil
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
||||
package cephfs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
@ -70,18 +69,19 @@ func (o *volumeOptions) validate() error {
|
||||
}
|
||||
|
||||
func extractOption(dest *string, optionLabel string, options map[string]string) error {
|
||||
if opt, ok := options[optionLabel]; !ok {
|
||||
return errors.New("Missing required field " + optionLabel)
|
||||
} else {
|
||||
opt, ok := options[optionLabel]
|
||||
if !ok {
|
||||
return fmt.Errorf("Missing required field %s", optionLabel)
|
||||
}
|
||||
|
||||
*dest = opt
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func validateMounter(m string) error {
|
||||
switch m {
|
||||
case volumeMounter_fuse:
|
||||
case volumeMounter_kernel:
|
||||
case volumeMounterFuse:
|
||||
case volumeMounterKernel:
|
||||
default:
|
||||
return fmt.Errorf("Unknown mounter '%s'. Valid options are 'fuse' and 'kernel'", m)
|
||||
}
|
||||
|
@ -433,9 +433,9 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
} else {
|
||||
return nil, status.Error(codes.NotFound, fmt.Sprintf("Snapshot ID %s cannot found", snapshotID))
|
||||
}
|
||||
return nil, status.Error(codes.NotFound, fmt.Sprintf("Snapshot ID %s cannot found", snapshotID))
|
||||
|
||||
}
|
||||
|
||||
entries := []*csi.ListSnapshotsResponse_Entry{}
|
||||
|
@ -61,15 +61,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 := path.Join(sys_path, name, "pool")
|
||||
poolFile := path.Join(sysPath, name, "pool")
|
||||
poolBytes, err := ioutil.ReadFile(poolFile)
|
||||
if err != nil {
|
||||
glog.V(4).Infof("error reading %s: %v", poolFile, err)
|
||||
@ -79,7 +79,7 @@ func getRbdDevFromImageAndPool(pool string, image string) (string, bool) {
|
||||
glog.V(4).Infof("device %s is not %q: %q", name, pool, string(poolBytes))
|
||||
continue
|
||||
}
|
||||
imgFile := path.Join(sys_path, name, "name")
|
||||
imgFile := path.Join(sysPath, name, "name")
|
||||
imgBytes, err := ioutil.ReadFile(imgFile)
|
||||
if err != nil {
|
||||
glog.V(4).Infof("error reading %s: %v", imgFile, err)
|
||||
|
@ -104,11 +104,12 @@ func getMon(pOpts *rbdVolume, credentials map[string]string) (string, error) {
|
||||
// yet another sanity check
|
||||
return "", fmt.Errorf("either monitors or monValueFromSecret must be set")
|
||||
}
|
||||
if val, ok := credentials[pOpts.MonValueFromSecret]; !ok {
|
||||
val, ok := credentials[pOpts.MonValueFromSecret]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("mon data %s is not set in secret", pOpts.MonValueFromSecret)
|
||||
} else {
|
||||
mon = val
|
||||
}
|
||||
mon = val
|
||||
|
||||
}
|
||||
return mon, nil
|
||||
}
|
||||
@ -187,10 +188,9 @@ func rbdStatus(pOpts *rbdVolume, userId string, credentials map[string]string) (
|
||||
if strings.Contains(output, imageWatcherStr) {
|
||||
glog.V(4).Infof("rbd: watchers on %s: %s", image, output)
|
||||
return true, output, nil
|
||||
} else {
|
||||
}
|
||||
glog.Warningf("rbd: no watchers on %s", image)
|
||||
return false, output, nil
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteImage deletes a ceph image with provision and volume options.
|
||||
@ -346,11 +346,11 @@ func getSnapMon(pOpts *rbdSnapshot, credentials map[string]string) (string, erro
|
||||
// yet another sanity check
|
||||
return "", fmt.Errorf("either monitors or monValueFromSecret must be set")
|
||||
}
|
||||
if val, ok := credentials[pOpts.MonValueFromSecret]; !ok {
|
||||
val, ok := credentials[pOpts.MonValueFromSecret]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("mon data %s is not set in secret", pOpts.MonValueFromSecret)
|
||||
} else {
|
||||
mon = val
|
||||
}
|
||||
mon = val
|
||||
}
|
||||
return mon, nil
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ func (nc *NodeCache) ForAll(pattern string, destObj interface{}, f ForAllFunc) e
|
||||
}
|
||||
fp, err := os.Open(path.Join(nc.BasePath, cacheDir, file.Name()))
|
||||
if err != nil {
|
||||
glog.Infof("node-cache: open file: %s err %%v", file.Name(), err)
|
||||
glog.Infof("node-cache: open file: %s err %v", file.Name(), err)
|
||||
continue
|
||||
}
|
||||
decoder := json.NewDecoder(fp)
|
||||
|
Loading…
Reference in New Issue
Block a user