mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-26 08:10:20 +00:00
Merge pull request #416 from Madhu-1/update-golanglint
Enable all static-checks in golangci-lint
This commit is contained in:
commit
46b19a93f5
@ -21,7 +21,7 @@ go: 1.11.x
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- GOLANGCI_VERSION="v1.16.0"
|
- GOLANGCI_VERSION="v1.17.0"
|
||||||
- TEST_COVERAGE=stdout
|
- TEST_COVERAGE=stdout
|
||||||
- GO_METALINTER_THREADS=1
|
- GO_METALINTER_THREADS=1
|
||||||
- GO_COVER_DIR=_output
|
- GO_COVER_DIR=_output
|
||||||
|
@ -63,7 +63,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getType() string {
|
func getType() string {
|
||||||
if vtype == nil || len(*vtype) == 0 {
|
if vtype == nil || *vtype == "" {
|
||||||
a0 := path.Base(os.Args[0])
|
a0 := path.Base(os.Args[0])
|
||||||
if strings.Contains(a0, rbdType) {
|
if strings.Contains(a0, rbdType) {
|
||||||
return rbdType
|
return rbdType
|
||||||
@ -78,7 +78,7 @@ func getType() string {
|
|||||||
|
|
||||||
func getDriverName() string {
|
func getDriverName() string {
|
||||||
// was explicitly passed a driver name
|
// was explicitly passed a driver name
|
||||||
if driverName != nil && len(*driverName) != 0 {
|
if driverName != nil && *driverName != "" {
|
||||||
return *driverName
|
return *driverName
|
||||||
}
|
}
|
||||||
// select driver name based on volume type
|
// select driver name based on volume type
|
||||||
@ -96,7 +96,7 @@ func main() {
|
|||||||
var cp util.CachePersister
|
var cp util.CachePersister
|
||||||
|
|
||||||
driverType := getType()
|
driverType := getType()
|
||||||
if len(driverType) == 0 {
|
if driverType == "" {
|
||||||
klog.Fatalln("driver type not specified")
|
klog.Fatalln("driver type not specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,12 +108,12 @@ func main() {
|
|||||||
klog.Infof("Starting driver type: %v with name: %v", driverType, dname)
|
klog.Infof("Starting driver type: %v with name: %v", driverType, dname)
|
||||||
switch driverType {
|
switch driverType {
|
||||||
case rbdType:
|
case rbdType:
|
||||||
rbd.PluginFolder = rbd.PluginFolder + dname
|
rbd.PluginFolder += dname
|
||||||
driver := rbd.NewDriver()
|
driver := rbd.NewDriver()
|
||||||
driver.Run(dname, *nodeID, *endpoint, *instanceID, *containerized)
|
driver.Run(dname, *nodeID, *endpoint, *instanceID, *containerized)
|
||||||
|
|
||||||
case cephfsType:
|
case cephfsType:
|
||||||
cephfs.PluginFolder = cephfs.PluginFolder + dname
|
cephfs.PluginFolder += dname
|
||||||
if *metadataStorage != "" {
|
if *metadataStorage != "" {
|
||||||
cp, err = util.CreatePersistanceStorage(
|
cp, err = util.CreatePersistanceStorage(
|
||||||
cephfs.PluginFolder, *metadataStorage, dname)
|
cephfs.PluginFolder, *metadataStorage, dname)
|
||||||
|
@ -18,17 +18,17 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func deployCephfsPlugin() {
|
func deployCephfsPlugin() {
|
||||||
//deploy provisioner
|
// deploy provisioner
|
||||||
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsProvisioner)
|
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsProvisioner)
|
||||||
framework.RunKubectlOrDie("apply", "-f", cephfsDirPath+cephfsProvisionerRBAC)
|
framework.RunKubectlOrDie("apply", "-f", cephfsDirPath+cephfsProvisionerRBAC)
|
||||||
//deploy nodeplugin
|
// deploy nodeplugin
|
||||||
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsNodePlugin)
|
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsNodePlugin)
|
||||||
framework.RunKubectlOrDie("apply", "-f", cephfsDirPath+cephfsNodePluginRBAC)
|
framework.RunKubectlOrDie("apply", "-f", cephfsDirPath+cephfsNodePluginRBAC)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = Describe("cephfs", func() {
|
var _ = Describe("cephfs", func() {
|
||||||
f := framework.NewDefaultFramework("cephfs")
|
f := framework.NewDefaultFramework("cephfs")
|
||||||
//deploy cephfs CSI
|
// deploy cephfs CSI
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
createFileSystem(f.ClientSet)
|
createFileSystem(f.ClientSet)
|
||||||
createConfigMap(f.ClientSet, f)
|
createConfigMap(f.ClientSet, f)
|
||||||
|
@ -36,7 +36,7 @@ func deployCommon() {
|
|||||||
func createFileSystem(c kubernetes.Interface) {
|
func createFileSystem(c kubernetes.Interface) {
|
||||||
commonPath := fmt.Sprintf("%s/%s", rookURL, "filesystem-test.yaml")
|
commonPath := fmt.Sprintf("%s/%s", rookURL, "filesystem-test.yaml")
|
||||||
framework.RunKubectlOrDie("create", "-f", commonPath)
|
framework.RunKubectlOrDie("create", "-f", commonPath)
|
||||||
opt := metav1.ListOptions{
|
opt := &metav1.ListOptions{
|
||||||
LabelSelector: "app=rook-ceph-mds",
|
LabelSelector: "app=rook-ceph-mds",
|
||||||
}
|
}
|
||||||
err := checkCephPods(rookNS, c, 1, deployTimeout, opt)
|
err := checkCephPods(rookNS, c, 1, deployTimeout, opt)
|
||||||
@ -72,7 +72,7 @@ func deployOperator(c kubernetes.Interface) {
|
|||||||
func deployCluster(c kubernetes.Interface) {
|
func deployCluster(c kubernetes.Interface) {
|
||||||
opPath := fmt.Sprintf("%s/%s", rookURL, "cluster-test.yaml")
|
opPath := fmt.Sprintf("%s/%s", rookURL, "cluster-test.yaml")
|
||||||
framework.RunKubectlOrDie("create", "-f", opPath)
|
framework.RunKubectlOrDie("create", "-f", opPath)
|
||||||
opt := metav1.ListOptions{
|
opt := &metav1.ListOptions{
|
||||||
LabelSelector: "app=rook-ceph-mon",
|
LabelSelector: "app=rook-ceph-mon",
|
||||||
}
|
}
|
||||||
err := checkCephPods(rookNS, c, 1, deployTimeout, opt)
|
err := checkCephPods(rookNS, c, 1, deployTimeout, opt)
|
||||||
@ -82,7 +82,7 @@ func deployCluster(c kubernetes.Interface) {
|
|||||||
func deployToolBox(c kubernetes.Interface) {
|
func deployToolBox(c kubernetes.Interface) {
|
||||||
opPath := fmt.Sprintf("%s/%s", rookURL, "toolbox.yaml")
|
opPath := fmt.Sprintf("%s/%s", rookURL, "toolbox.yaml")
|
||||||
framework.RunKubectlOrDie("create", "-f", opPath)
|
framework.RunKubectlOrDie("create", "-f", opPath)
|
||||||
opt := metav1.ListOptions{
|
opt := &metav1.ListOptions{
|
||||||
LabelSelector: "app=rook-ceph-tools",
|
LabelSelector: "app=rook-ceph-tools",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ func tearDownRook() {
|
|||||||
framework.Cleanup(opPath, rookNS, "app=rook-ceph-tools")
|
framework.Cleanup(opPath, rookNS, "app=rook-ceph-tools")
|
||||||
|
|
||||||
opPath = fmt.Sprintf("%s/%s", rookURL, "operator.yaml")
|
opPath = fmt.Sprintf("%s/%s", rookURL, "operator.yaml")
|
||||||
//TODO need to add selector for cleanup validation
|
// TODO need to add selector for cleanup validation
|
||||||
framework.Cleanup(opPath, rookNS)
|
framework.Cleanup(opPath, rookNS)
|
||||||
commonPath := fmt.Sprintf("%s/%s", rookURL, "common.yaml")
|
commonPath := fmt.Sprintf("%s/%s", rookURL, "common.yaml")
|
||||||
framework.RunKubectlOrDie("delete", "-f", commonPath)
|
framework.RunKubectlOrDie("delete", "-f", commonPath)
|
||||||
|
@ -32,14 +32,14 @@ func init() {
|
|||||||
fmt.Println("timeout for deploytimeout ", deployTimeout)
|
fmt.Println("timeout for deploytimeout ", deployTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
//BeforeSuite deploys the rook-operator and ceph cluster
|
// BeforeSuite deploys the rook-operator and ceph cluster
|
||||||
var _ = BeforeSuite(func() {
|
var _ = BeforeSuite(func() {
|
||||||
if rookRequired {
|
if rookRequired {
|
||||||
deployRook()
|
deployRook()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
//AfterSuite removes the rook-operator and ceph cluster
|
// AfterSuite removes the rook-operator and ceph cluster
|
||||||
var _ = AfterSuite(func() {
|
var _ = AfterSuite(func() {
|
||||||
if rookRequired {
|
if rookRequired {
|
||||||
tearDownRook()
|
tearDownRook()
|
||||||
|
@ -23,14 +23,14 @@ func deployRBDPlugin() {
|
|||||||
// deploy provisioner
|
// deploy provisioner
|
||||||
framework.RunKubectlOrDie("create", "-f", rbdDirPath+rbdProvisioner)
|
framework.RunKubectlOrDie("create", "-f", rbdDirPath+rbdProvisioner)
|
||||||
framework.RunKubectlOrDie("apply", "-f", rbdDirPath+rbdProvisionerRBAC)
|
framework.RunKubectlOrDie("apply", "-f", rbdDirPath+rbdProvisionerRBAC)
|
||||||
//deploy nodeplugin
|
// deploy nodeplugin
|
||||||
framework.RunKubectlOrDie("create", "-f", rbdDirPath+rbdNodePlugin)
|
framework.RunKubectlOrDie("create", "-f", rbdDirPath+rbdNodePlugin)
|
||||||
framework.RunKubectlOrDie("apply", "-f", rbdDirPath+rbdNodePluginRBAC)
|
framework.RunKubectlOrDie("apply", "-f", rbdDirPath+rbdNodePluginRBAC)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = Describe("RBD", func() {
|
var _ = Describe("RBD", func() {
|
||||||
f := framework.NewDefaultFramework("rbd")
|
f := framework.NewDefaultFramework("rbd")
|
||||||
//deploy RBD CSI
|
// deploy RBD CSI
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
createRBDPool()
|
createRBDPool()
|
||||||
createConfigMap(f.ClientSet, f)
|
createConfigMap(f.ClientSet, f)
|
||||||
|
26
e2e/utils.go
26
e2e/utils.go
@ -80,7 +80,7 @@ func waitForDeploymentComplete(name, ns string, c clientset.Interface, t int) er
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO need to check rolling update
|
// TODO need to check rolling update
|
||||||
|
|
||||||
// When the deployment status and its underlying resources reach the
|
// When the deployment status and its underlying resources reach the
|
||||||
// desired state, we're done
|
// desired state, we're done
|
||||||
@ -137,8 +137,8 @@ func getMons(ns string, c kubernetes.Interface) []string {
|
|||||||
svcList, err := c.CoreV1().Services(ns).List(opt)
|
svcList, err := c.CoreV1().Services(ns).List(opt)
|
||||||
Expect(err).Should(BeNil())
|
Expect(err).Should(BeNil())
|
||||||
services := make([]string, 0)
|
services := make([]string, 0)
|
||||||
for _, svc := range svcList.Items {
|
for i := range svcList.Items {
|
||||||
s := fmt.Sprintf("%s.%s.svc.cluster.local:%d", svc.Name, svc.Namespace, svc.Spec.Ports[0].Port)
|
s := fmt.Sprintf("%s.%s.svc.cluster.local:%d", svcList.Items[i].Name, svcList.Items[i].Namespace, svcList.Items[i].Spec.Ports[0].Port)
|
||||||
services = append(services, s)
|
services = append(services, s)
|
||||||
}
|
}
|
||||||
return services
|
return services
|
||||||
@ -160,7 +160,7 @@ func createCephfsStorageClass(c kubernetes.Interface, f *framework.Framework) {
|
|||||||
sc.Parameters["pool"] = "myfs-data0"
|
sc.Parameters["pool"] = "myfs-data0"
|
||||||
sc.Parameters["fsName"] = "myfs"
|
sc.Parameters["fsName"] = "myfs"
|
||||||
fsID := execCommandInToolBox(f, "ceph fsid")
|
fsID := execCommandInToolBox(f, "ceph fsid")
|
||||||
//remove new line present in fsID
|
// remove new line present in fsID
|
||||||
fsID = strings.Trim(fsID, "\n")
|
fsID = strings.Trim(fsID, "\n")
|
||||||
|
|
||||||
sc.Parameters["clusterID"] = fsID
|
sc.Parameters["clusterID"] = fsID
|
||||||
@ -175,7 +175,7 @@ func createRBDStorageClass(c kubernetes.Interface, f *framework.Framework) {
|
|||||||
sc.Parameters["pool"] = "replicapool"
|
sc.Parameters["pool"] = "replicapool"
|
||||||
|
|
||||||
fsID := execCommandInToolBox(f, "ceph fsid")
|
fsID := execCommandInToolBox(f, "ceph fsid")
|
||||||
//remove new line present in fsID
|
// remove new line present in fsID
|
||||||
fsID = strings.Trim(fsID, "\n")
|
fsID = strings.Trim(fsID, "\n")
|
||||||
|
|
||||||
sc.Parameters["clusterID"] = fsID
|
sc.Parameters["clusterID"] = fsID
|
||||||
@ -190,9 +190,9 @@ func createConfigMap(c kubernetes.Interface, f *framework.Framework) {
|
|||||||
Expect(err).Should(BeNil())
|
Expect(err).Should(BeNil())
|
||||||
|
|
||||||
fsID := execCommandInToolBox(f, "ceph fsid")
|
fsID := execCommandInToolBox(f, "ceph fsid")
|
||||||
//remove new line present in fsID
|
// remove new line present in fsID
|
||||||
fsID = strings.Trim(fsID, "\n")
|
fsID = strings.Trim(fsID, "\n")
|
||||||
//get mon list
|
// get mon list
|
||||||
mons := getMons(rookNS, c)
|
mons := getMons(rookNS, c)
|
||||||
conmap := []struct {
|
conmap := []struct {
|
||||||
Clusterid string `json:"clusterID"`
|
Clusterid string `json:"clusterID"`
|
||||||
@ -213,7 +213,7 @@ func createConfigMap(c kubernetes.Interface, f *framework.Framework) {
|
|||||||
func getSecret(path string) v1.Secret {
|
func getSecret(path string) v1.Secret {
|
||||||
sc := v1.Secret{}
|
sc := v1.Secret{}
|
||||||
err := unmarshal(path, &sc)
|
err := unmarshal(path, &sc)
|
||||||
//discard corruptInputError
|
// discard corruptInputError
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(base64.CorruptInputError); !ok {
|
if _, ok := err.(base64.CorruptInputError); !ok {
|
||||||
Expect(err).Should(BeNil())
|
Expect(err).Should(BeNil())
|
||||||
@ -367,11 +367,11 @@ func createApp(c kubernetes.Interface, app *v1.Pod, timeout int) error {
|
|||||||
return waitForPodInRunningState(app.Name, app.Namespace, c, timeout)
|
return waitForPodInRunningState(app.Name, app.Namespace, c, timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPodName(ns string, c kubernetes.Interface, opt metav1.ListOptions) string {
|
func getPodName(ns string, c kubernetes.Interface, opt *metav1.ListOptions) string {
|
||||||
ticker := time.NewTicker(1 * time.Second)
|
ticker := time.NewTicker(1 * time.Second)
|
||||||
//TODO add stop logic
|
// TODO add stop logic
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
podList, err := c.CoreV1().Pods(ns).List(opt)
|
podList, err := c.CoreV1().Pods(ns).List(*opt)
|
||||||
framework.ExpectNoError(err)
|
framework.ExpectNoError(err)
|
||||||
Expect(podList.Items).NotTo(BeNil())
|
Expect(podList.Items).NotTo(BeNil())
|
||||||
Expect(err).Should(BeNil())
|
Expect(err).Should(BeNil())
|
||||||
@ -439,12 +439,12 @@ func unmarshal(fileName string, obj interface{}) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkCephPods(ns string, c kubernetes.Interface, count int, t int, opt metav1.ListOptions) error {
|
func checkCephPods(ns string, c kubernetes.Interface, count, t int, opt *metav1.ListOptions) error {
|
||||||
timeout := time.Duration(t) * time.Minute
|
timeout := time.Duration(t) * time.Minute
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
return wait.PollImmediate(poll, timeout, func() (bool, error) {
|
return wait.PollImmediate(poll, timeout, func() (bool, error) {
|
||||||
podList, err := c.CoreV1().Pods(ns).List(opt)
|
podList, err := c.CoreV1().Pods(ns).List(*opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ func (fs *Driver) Run(driverName, nodeID, endpoint, volumeMounter, mountCacheDir
|
|||||||
if mountCacheDir != "" {
|
if mountCacheDir != "" {
|
||||||
if err := remountCachedVolumes(); err != nil {
|
if err := remountCachedVolumes(); err != nil {
|
||||||
klog.Warningf("failed to remount cached volumes: %v", err)
|
klog.Warningf("failed to remount cached volumes: %v", err)
|
||||||
//ignore remount fail
|
// ignore remount fail
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Initialize default library driver
|
// Initialize default library driver
|
||||||
|
@ -34,7 +34,7 @@ var (
|
|||||||
volumeMountCacheMtx sync.Mutex
|
volumeMountCacheMtx sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
func initVolumeMountCache(driverName string, mountCacheDir string) {
|
func initVolumeMountCache(driverName, mountCacheDir string) {
|
||||||
volumeMountCache.volumes = make(map[string]volumeMountCacheEntry)
|
volumeMountCache.volumes = make(map[string]volumeMountCacheEntry)
|
||||||
|
|
||||||
volumeMountCache.nodeCacheStore.BasePath = mountCacheDir
|
volumeMountCache.nodeCacheStore.BasePath = mountCacheDir
|
||||||
@ -159,7 +159,7 @@ func cleanupMountPoint(mountPoint string) error {
|
|||||||
err := execCommandErr("umount", mountPoint)
|
err := execCommandErr("umount", mountPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Infof("mount-cache: failed to umount %s %v", mountPoint, err)
|
klog.Infof("mount-cache: failed to umount %s %v", mountPoint, err)
|
||||||
//ignore error return err
|
// ignore error return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,7 +201,7 @@ func genVolumeMountCacheFileName(volID string) string {
|
|||||||
return cachePath
|
return cachePath
|
||||||
}
|
}
|
||||||
func (mc *volumeMountCacheMap) isEnable() bool {
|
func (mc *volumeMountCacheMap) isEnable() bool {
|
||||||
//if mount cache dir unset, disable state
|
// if mount cache dir unset, disable state
|
||||||
return mc.nodeCacheStore.BasePath != ""
|
return mc.nodeCacheStore.BasePath != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,7 +246,7 @@ func (mc *volumeMountCacheMap) nodeUnStageVolume(volID string) error {
|
|||||||
return mc.nodeCacheStore.Delete(genVolumeMountCacheFileName(volID))
|
return mc.nodeCacheStore.Delete(genVolumeMountCacheFileName(volID))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *volumeMountCacheMap) nodePublishVolume(volID string, targetPath string, readOnly bool) error {
|
func (mc *volumeMountCacheMap) nodePublishVolume(volID, targetPath string, readOnly bool) error {
|
||||||
if !mc.isEnable() {
|
if !mc.isEnable() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -261,7 +261,7 @@ func (mc *volumeMountCacheMap) nodePublishVolume(volID string, targetPath string
|
|||||||
return mc.updateNodeCache(volID)
|
return mc.updateNodeCache(volID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *volumeMountCacheMap) nodeUnPublishVolume(volID string, targetPath string) error {
|
func (mc *volumeMountCacheMap) nodeUnPublishVolume(volID, targetPath string) error {
|
||||||
if !mc.isEnable() {
|
if !mc.isEnable() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ func mountKernel(mountPoint string, cr *credentials, volOptions *volumeOptions)
|
|||||||
}
|
}
|
||||||
optionsStr := fmt.Sprintf("name=%s,secret=%s", cr.id, cr.key)
|
optionsStr := fmt.Sprintf("name=%s,secret=%s", cr.id, cr.key)
|
||||||
if volOptions.FsName != "" {
|
if volOptions.FsName != "" {
|
||||||
optionsStr = optionsStr + fmt.Sprintf(",mds_namespace=%s", volOptions.FsName)
|
optionsStr += fmt.Sprintf(",mds_namespace=%s", volOptions.FsName)
|
||||||
}
|
}
|
||||||
args = append(args, "-o", optionsStr)
|
args = append(args, "-o", optionsStr)
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ func bindMount(from, to string, readOnly bool, mntOptions []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if readOnly {
|
if readOnly {
|
||||||
mntOptionSli = mntOptionSli + ",remount"
|
mntOptionSli += ",remount"
|
||||||
if err := execCommandErr("mount", "-o", mntOptionSli, to); err != nil {
|
if err := execCommandErr("mount", "-o", mntOptionSli, to); err != nil {
|
||||||
return fmt.Errorf("failed read-only remount of %s: %v", to, err)
|
return fmt.Errorf("failed read-only remount of %s: %v", to, err)
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ func (cs *DefaultControllerServer) ControllerUnpublishVolume(ctx context.Context
|
|||||||
return nil, status.Error(codes.Unimplemented, "")
|
return nil, status.Error(codes.Unimplemented, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
//ControllerExpandVolume expand volume
|
// ControllerExpandVolume expand volume
|
||||||
func (cs *DefaultControllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
|
func (cs *DefaultControllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
|
||||||
return nil, status.Error(codes.Unimplemented, "")
|
return nil, status.Error(codes.Unimplemented, "")
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ type CSIDriver struct {
|
|||||||
// NewCSIDriver Creates a NewCSIDriver object. Assumes vendor
|
// NewCSIDriver Creates a NewCSIDriver object. Assumes vendor
|
||||||
// version is equal to driver version & does not support optional
|
// version is equal to driver version & does not support optional
|
||||||
// driver plugin info manifest field. Refer to CSI spec for more details.
|
// driver plugin info manifest field. Refer to CSI spec for more details.
|
||||||
func NewCSIDriver(name string, v string, nodeID string) *CSIDriver {
|
func NewCSIDriver(name, v, nodeID string) *CSIDriver {
|
||||||
if name == "" {
|
if name == "" {
|
||||||
klog.Errorf("Driver name missing")
|
klog.Errorf("Driver name missing")
|
||||||
return nil
|
return nil
|
||||||
@ -48,7 +48,7 @@ func NewCSIDriver(name string, v string, nodeID string) *CSIDriver {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// TODO version format and validation
|
// TODO version format and validation
|
||||||
if len(v) == 0 {
|
if v == "" {
|
||||||
klog.Errorf("Version argument missing")
|
klog.Errorf("Version argument missing")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -64,11 +64,11 @@ func NewDefaultControllerServer(d *CSIDriver) *DefaultControllerServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewControllerServiceCapability returns controller capabilities
|
// NewControllerServiceCapability returns controller capabilities
|
||||||
func NewControllerServiceCapability(cap csi.ControllerServiceCapability_RPC_Type) *csi.ControllerServiceCapability {
|
func NewControllerServiceCapability(ctrlCap csi.ControllerServiceCapability_RPC_Type) *csi.ControllerServiceCapability {
|
||||||
return &csi.ControllerServiceCapability{
|
return &csi.ControllerServiceCapability{
|
||||||
Type: &csi.ControllerServiceCapability_Rpc{
|
Type: &csi.ControllerServiceCapability_Rpc{
|
||||||
Rpc: &csi.ControllerServiceCapability_RPC{
|
Rpc: &csi.ControllerServiceCapability_RPC{
|
||||||
Type: cap,
|
Type: ctrlCap,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -46,17 +46,17 @@ func (cs *ControllerServer) validateVolumeReq(req *csi.CreateVolumeRequest) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Check sanity of request Name, Volume Capabilities
|
// Check sanity of request Name, Volume Capabilities
|
||||||
if len(req.Name) == 0 {
|
if req.Name == "" {
|
||||||
return status.Error(codes.InvalidArgument, "volume Name cannot be empty")
|
return status.Error(codes.InvalidArgument, "volume Name cannot be empty")
|
||||||
}
|
}
|
||||||
if req.VolumeCapabilities == nil {
|
if req.VolumeCapabilities == nil {
|
||||||
return status.Error(codes.InvalidArgument, "volume Capabilities cannot be empty")
|
return status.Error(codes.InvalidArgument, "volume Capabilities cannot be empty")
|
||||||
}
|
}
|
||||||
options := req.GetParameters()
|
options := req.GetParameters()
|
||||||
if value, ok := options["clusterID"]; !ok || len(value) == 0 {
|
if value, ok := options["clusterID"]; !ok || value == "" {
|
||||||
return status.Error(codes.InvalidArgument, "missing or empty cluster ID to provision volume from")
|
return status.Error(codes.InvalidArgument, "missing or empty cluster ID to provision volume from")
|
||||||
}
|
}
|
||||||
if value, ok := options["pool"]; !ok || len(value) == 0 {
|
if value, ok := options["pool"]; !ok || value == "" {
|
||||||
return status.Error(codes.InvalidArgument, "missing or empty pool name to provision volume from")
|
return status.Error(codes.InvalidArgument, "missing or empty pool name to provision volume from")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -194,7 +194,7 @@ func (cs *ControllerServer) checkSnapshot(req *csi.CreateVolumeRequest, rbdVol *
|
|||||||
}
|
}
|
||||||
|
|
||||||
snapshotID := snapshot.GetSnapshotId()
|
snapshotID := snapshot.GetSnapshotId()
|
||||||
if len(snapshotID) == 0 {
|
if snapshotID == "" {
|
||||||
return status.Error(codes.InvalidArgument, "volume Snapshot ID cannot be empty")
|
return status.Error(codes.InvalidArgument, "volume Snapshot ID cannot be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,10 +401,10 @@ func (cs *ControllerServer) validateSnapshotReq(req *csi.CreateSnapshotRequest)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check sanity of request Snapshot Name, Source Volume Id
|
// Check sanity of request Snapshot Name, Source Volume Id
|
||||||
if len(req.Name) == 0 {
|
if req.Name == "" {
|
||||||
return status.Error(codes.InvalidArgument, "snapshot Name cannot be empty")
|
return status.Error(codes.InvalidArgument, "snapshot Name cannot be empty")
|
||||||
}
|
}
|
||||||
if len(req.SourceVolumeId) == 0 {
|
if req.SourceVolumeId == "" {
|
||||||
return status.Error(codes.InvalidArgument, "source Volume ID cannot be empty")
|
return status.Error(codes.InvalidArgument, "source Volume ID cannot be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,7 +458,7 @@ func (cs *ControllerServer) doSnapshot(rbdSnap *rbdSnapshot, secret map[string]s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteSnapshot deletes the snapshot in backend and removes the
|
// DeleteSnapshot deletes the snapshot in backend and removes the
|
||||||
//snapshot metadata from store
|
// snapshot metadata from store
|
||||||
func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {
|
func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {
|
||||||
if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT); err != nil {
|
if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT); err != nil {
|
||||||
klog.Warningf("invalid delete snapshot req: %v", protosanitizer.StripSecrets(req))
|
klog.Warningf("invalid delete snapshot req: %v", protosanitizer.StripSecrets(req))
|
||||||
@ -466,7 +466,7 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
|
|||||||
}
|
}
|
||||||
|
|
||||||
snapshotID := req.GetSnapshotId()
|
snapshotID := req.GetSnapshotId()
|
||||||
if len(snapshotID) == 0 {
|
if snapshotID == "" {
|
||||||
return nil, status.Error(codes.InvalidArgument, "snapshot ID cannot be empty")
|
return nil, status.Error(codes.InvalidArgument, "snapshot ID cannot be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Search /sys/bus for rbd device that matches given pool and image.
|
// Search /sys/bus for rbd device that matches given pool and image.
|
||||||
func getRbdDevFromImageAndPool(pool string, image string) (string, bool) {
|
func getRbdDevFromImageAndPool(pool, image string) (string, bool) {
|
||||||
// /sys/bus/rbd/devices/X/name and /sys/bus/rbd/devices/X/pool
|
// /sys/bus/rbd/devices/X/name and /sys/bus/rbd/devices/X/pool
|
||||||
sysPath := "/sys/bus/rbd/devices"
|
sysPath := "/sys/bus/rbd/devices"
|
||||||
if dirs, err := ioutil.ReadDir(sysPath); err == nil {
|
if dirs, err := ioutil.ReadDir(sysPath); err == nil {
|
||||||
@ -123,7 +123,7 @@ func getMaxNbds() (int, error) {
|
|||||||
// but older versions of list-mapped don't.
|
// but older versions of list-mapped don't.
|
||||||
// The implementation below peeks at the command line of nbd bound processes
|
// The implementation below peeks at the command line of nbd bound processes
|
||||||
// to figure out any mapped images.
|
// to figure out any mapped images.
|
||||||
func getNbdDevFromImageAndPool(pool string, image string) (string, bool) {
|
func getNbdDevFromImageAndPool(pool, image string) (string, bool) {
|
||||||
// nbd module exports the pid of serving process in sysfs
|
// nbd module exports the pid of serving process in sysfs
|
||||||
basePath := "/sys/block/nbd"
|
basePath := "/sys/block/nbd"
|
||||||
// Do not change imgPath format - some tools like rbd-nbd are strict about it.
|
// Do not change imgPath format - some tools like rbd-nbd are strict about it.
|
||||||
|
@ -55,7 +55,7 @@ type cephStoragePoolSummary struct {
|
|||||||
|
|
||||||
// GetPoolID searches a list of pools in a cluster and returns the ID of the pool that matches
|
// GetPoolID searches a list of pools in a cluster and returns the ID of the pool that matches
|
||||||
// the passed in poolName parameter
|
// the passed in poolName parameter
|
||||||
func GetPoolID(monitors string, adminID string, key string, poolName string) (int64, error) {
|
func GetPoolID(monitors, adminID, key, poolName string) (int64, error) {
|
||||||
// ceph <options> -f json osd lspools
|
// ceph <options> -f json osd lspools
|
||||||
// JSON out: [{"poolnum":<int64>,"poolname":<string>}]
|
// JSON out: [{"poolnum":<int64>,"poolname":<string>}]
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ func GetPoolID(monitors string, adminID string, key string, poolName string) (in
|
|||||||
|
|
||||||
// GetPoolName lists all pools in a ceph cluster, and matches the pool whose pool ID is equal to
|
// GetPoolName lists all pools in a ceph cluster, and matches the pool whose pool ID is equal to
|
||||||
// the requested poolID parameter
|
// the requested poolID parameter
|
||||||
func GetPoolName(monitors string, adminID string, key string, poolID int64) (string, error) {
|
func GetPoolName(monitors, adminID, key string, poolID int64) (string, error) {
|
||||||
// ceph <options> -f json osd lspools
|
// ceph <options> -f json osd lspools
|
||||||
// [{"poolnum":1,"poolname":"replicapool"}]
|
// [{"poolnum":1,"poolname":"replicapool"}]
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ func (k8scm *K8sCMCache) getMetadataCM(resourceID string) (*v1.ConfigMap, error)
|
|||||||
return cm, nil
|
return cm, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//ForAll list the metadata in configmaps and filters outs based on the pattern
|
// ForAll list the metadata in configmaps and filters outs based on the pattern
|
||||||
func (k8scm *K8sCMCache) ForAll(pattern string, destObj interface{}, f ForAllFunc) error {
|
func (k8scm *K8sCMCache) ForAll(pattern string, destObj interface{}, f ForAllFunc) error {
|
||||||
listOpts := metav1.ListOptions{LabelSelector: fmt.Sprintf("%s=%s", csiMetadataLabelAttr, cmLabel)}
|
listOpts := metav1.ListOptions{LabelSelector: fmt.Sprintf("%s=%s", csiMetadataLabelAttr, cmLabel)}
|
||||||
cms, err := k8scm.Client.CoreV1().ConfigMaps(k8scm.Namespace).List(listOpts)
|
cms, err := k8scm.Client.CoreV1().ConfigMaps(k8scm.Namespace).List(listOpts)
|
||||||
@ -100,9 +100,9 @@ func (k8scm *K8sCMCache) ForAll(pattern string, destObj interface{}, f ForAllFun
|
|||||||
return errors.Wrap(err, "k8s-cm-cache: failed to list metadata configmaps")
|
return errors.Wrap(err, "k8s-cm-cache: failed to list metadata configmaps")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cm := range cms.Items {
|
for i := range cms.Items {
|
||||||
data := cm.Data[cmDataKey]
|
data := cms.Items[i].Data[cmDataKey]
|
||||||
match, err := regexp.MatchString(pattern, cm.ObjectMeta.Name)
|
match, err := regexp.MatchString(pattern, cms.Items[i].ObjectMeta.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -110,9 +110,9 @@ func (k8scm *K8sCMCache) ForAll(pattern string, destObj interface{}, f ForAllFun
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal([]byte(data), destObj); err != nil {
|
if err = json.Unmarshal([]byte(data), destObj); err != nil {
|
||||||
return errors.Wrapf(err, "k8s-cm-cache: JSON unmarshaling failed for configmap %s", cm.ObjectMeta.Name)
|
return errors.Wrapf(err, "k8s-cm-cache: JSON unmarshaling failed for configmap %s", cms.Items[i].ObjectMeta.Name)
|
||||||
}
|
}
|
||||||
if err = f(cm.ObjectMeta.Name); err != nil {
|
if err = f(cms.Items[i].ObjectMeta.Name); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ func (nc *NodeCache) EnsureCacheDirectory(cacheDir string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//ForAll list the metadata in Nodecache and filters outs based on the pattern
|
// ForAll list the metadata in Nodecache and filters outs based on the pattern
|
||||||
func (nc *NodeCache) ForAll(pattern string, destObj interface{}, f ForAllFunc) error {
|
func (nc *NodeCache) ForAll(pattern string, destObj interface{}, f ForAllFunc) error {
|
||||||
err := nc.EnsureCacheDirectory(nc.CacheDir)
|
err := nc.EnsureCacheDirectory(nc.CacheDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -59,9 +59,9 @@ func (nc *NodeCache) ForAll(pattern string, destObj interface{}, f ForAllFunc) e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "node-cache: failed to read %s folder", nc.BasePath)
|
return errors.Wrapf(err, "node-cache: failed to read %s folder", nc.BasePath)
|
||||||
}
|
}
|
||||||
path := path.Join(nc.BasePath, nc.CacheDir)
|
cachePath := path.Join(nc.BasePath, nc.CacheDir)
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
err = decodeObj(path, pattern, file, destObj)
|
err = decodeObj(cachePath, pattern, file, destObj)
|
||||||
if err == errDec {
|
if err == errDec {
|
||||||
continue
|
continue
|
||||||
} else if err == nil {
|
} else if err == nil {
|
||||||
@ -75,7 +75,7 @@ func (nc *NodeCache) ForAll(pattern string, destObj interface{}, f ForAllFunc) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeObj(filepath, pattern string, file os.FileInfo, destObj interface{}) error {
|
func decodeObj(fpath, pattern string, file os.FileInfo, destObj interface{}) error {
|
||||||
match, err := regexp.MatchString(pattern, file.Name())
|
match, err := regexp.MatchString(pattern, file.Name())
|
||||||
if err != nil || !match {
|
if err != nil || !match {
|
||||||
return errDec
|
return errDec
|
||||||
@ -84,7 +84,7 @@ func decodeObj(filepath, pattern string, file os.FileInfo, destObj interface{})
|
|||||||
return errDec
|
return errDec
|
||||||
}
|
}
|
||||||
// #nosec
|
// #nosec
|
||||||
fp, err := os.Open(path.Join(filepath, file.Name()))
|
fp, err := os.Open(path.Join(fpath, file.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Infof("node-cache: open file: %s err %v", file.Name(), err)
|
klog.Infof("node-cache: open file: %s err %v", file.Name(), err)
|
||||||
return errDec
|
return errDec
|
||||||
|
@ -39,7 +39,7 @@ func RoundUpToMiB(size int64) int64 {
|
|||||||
return roundUpSize(requestBytes, MiB)
|
return roundUpSize(requestBytes, MiB)
|
||||||
}
|
}
|
||||||
|
|
||||||
func roundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64 {
|
func roundUpSize(volumeSizeBytes, allocationUnitBytes int64) int64 {
|
||||||
roundedUp := volumeSizeBytes / allocationUnitBytes
|
roundedUp := volumeSizeBytes / allocationUnitBytes
|
||||||
if volumeSizeBytes%allocationUnitBytes > 0 {
|
if volumeSizeBytes%allocationUnitBytes > 0 {
|
||||||
roundedUp++
|
roundedUp++
|
||||||
@ -74,7 +74,7 @@ func createPersistentStorage(persistentStoragePath string) error {
|
|||||||
|
|
||||||
// ValidateDriverName validates the driver name
|
// ValidateDriverName validates the driver name
|
||||||
func ValidateDriverName(driverName string) error {
|
func ValidateDriverName(driverName string) error {
|
||||||
if len(driverName) == 0 {
|
if driverName == "" {
|
||||||
return errors.New("driver name is empty")
|
return errors.New("driver name is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ func (ci *CSIIdentifier) DecomposeCSIID(composedCSIID string) (err error) {
|
|||||||
ci.LocationID = int64(binary.BigEndian.Uint64(buf64))
|
ci.LocationID = int64(binary.BigEndian.Uint64(buf64))
|
||||||
// 16 for poolID encoding and 1 for '-' separator
|
// 16 for poolID encoding and 1 for '-' separator
|
||||||
bytesToProcess -= 17
|
bytesToProcess -= 17
|
||||||
nextFieldStartIdx = nextFieldStartIdx + 17
|
nextFieldStartIdx += 17
|
||||||
|
|
||||||
// has to be an exact match
|
// has to be an exact match
|
||||||
if bytesToProcess != uuidSize {
|
if bytesToProcess != uuidSize {
|
||||||
|
@ -107,6 +107,18 @@ linters-settings:
|
|||||||
line-length: 180
|
line-length: 180
|
||||||
# tab width in spaces. Default to 1.
|
# tab width in spaces. Default to 1.
|
||||||
tab-width: 1
|
tab-width: 1
|
||||||
|
gocritic:
|
||||||
|
enabled-tags:
|
||||||
|
- performance
|
||||||
|
- style
|
||||||
|
- experimental
|
||||||
|
disabled-checks:
|
||||||
|
- sloppyReassign
|
||||||
|
- elseif
|
||||||
|
- unslice
|
||||||
|
- wrapperFunc
|
||||||
|
- unnamedResult
|
||||||
|
- dupImport # https://github.com/go-critic/go-critic/issues/845
|
||||||
unused:
|
unused:
|
||||||
# treat code as a program (not a library) and report unused exported
|
# treat code as a program (not a library) and report unused exported
|
||||||
# identifiers; default is false.
|
# identifiers; default is false.
|
||||||
@ -131,23 +143,9 @@ linters-settings:
|
|||||||
max-func-lines: 30
|
max-func-lines: 30
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
enable:
|
enable-all: true
|
||||||
- megacheck
|
|
||||||
- govet
|
|
||||||
- golint
|
|
||||||
- stylecheck
|
|
||||||
- interfacer
|
|
||||||
- unconvert
|
|
||||||
- gofmt
|
|
||||||
- gocyclo
|
|
||||||
- maligned
|
|
||||||
- lll
|
|
||||||
- nakedret
|
|
||||||
enable-all: false
|
|
||||||
disable:
|
disable:
|
||||||
- prealloc
|
- prealloc
|
||||||
disable-all: false
|
- dupl
|
||||||
presets:
|
- gochecknoinits
|
||||||
- bugs
|
- gochecknoglobals
|
||||||
- unused
|
|
||||||
fast: false
|
|
||||||
|
Loading…
Reference in New Issue
Block a user