From 8a16f740d68b3f31b1955f81f1a4994aa72fd68b Mon Sep 17 00:00:00 2001 From: Woohyung Han Date: Thu, 12 Dec 2019 12:22:55 +0900 Subject: [PATCH] Update golangci-lint version to v1.21.0 Signed-off-by: Woohyung Han --- .travis.yml | 2 +- cmd/cephcsi.go | 1 - e2e/utils.go | 4 ---- pkg/cephfs/controllerserver.go | 2 -- pkg/cephfs/driver.go | 1 - pkg/cephfs/nodeserver.go | 1 - pkg/csi-common/driver.go | 1 - pkg/csi-common/nodeserver-default.go | 3 --- pkg/csi-common/server.go | 2 -- pkg/csi-common/utils.go | 1 - pkg/liveness/liveness.go | 1 - pkg/rbd/controllerserver.go | 1 - pkg/rbd/nodeserver.go | 2 -- pkg/util/nodecache.go | 4 ---- pkg/util/voljournal.go | 1 - scripts/golangci.yml | 7 +++++++ 16 files changed, 8 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index b74ec331f..44ea77f78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ go: 1.12.x env: global: - - GOLANGCI_VERSION=v1.17.0 + - GOLANGCI_VERSION=v1.21.0 - GOSEC_VERSION=2.0.0 - TEST_COVERAGE=stdout - GO_METALINTER_THREADS=1 diff --git a/cmd/cephcsi.go b/cmd/cephcsi.go index 817200c7c..ba42edc3e 100644 --- a/cmd/cephcsi.go +++ b/cmd/cephcsi.go @@ -46,7 +46,6 @@ var ( ) func init() { - // common flags flag.StringVar(&conf.Vtype, "type", "", "driver type [rbd|cephfs|liveness]") flag.StringVar(&conf.Endpoint, "endpoint", "unix://tmp/csi.sock", "CSI endpoint") diff --git a/e2e/utils.go b/e2e/utils.go index acd0c188f..3e255ef5a 100644 --- a/e2e/utils.go +++ b/e2e/utils.go @@ -136,7 +136,6 @@ func waitForDeploymentComplete(name, ns string, c clientset.Interface, t int) er } func execCommandInPod(f *framework.Framework, c, ns string, opt *metav1.ListOptions) (string, string) { - cmd := []string{"/bin/sh", "-c", c} podList, err := f.PodClientNS(ns).List(*opt) framework.ExpectNoError(err) @@ -523,7 +522,6 @@ func unmarshal(fileName string, obj interface{}) error { // createPVCAndApp creates pvc and pod // if name is not empty same will be set as pvc and app name func createPVCAndApp(name string, f *framework.Framework, pvc *v1.PersistentVolumeClaim, app *v1.Pod) error { - if name != "" { pvc.Name = name app.Name = name @@ -540,7 +538,6 @@ func createPVCAndApp(name string, f *framework.Framework, pvc *v1.PersistentVolu // deletePVCAndApp delete pvc and pod // if name is not empty same will be set as pvc and app name func deletePVCAndApp(name string, f *framework.Framework, pvc *v1.PersistentVolumeClaim, app *v1.Pod) error { - if name != "" { pvc.Name = name app.Name = name @@ -731,7 +728,6 @@ func validateNormalUserPVCAccess(pvcPath string, f *framework.Framework) { // } func listRBDImages(f *framework.Framework) []string { - opt := metav1.ListOptions{ LabelSelector: "app=rook-ceph-tools", } diff --git a/pkg/cephfs/controllerserver.go b/pkg/cephfs/controllerserver.go index 3bd00607b..64132b66d 100644 --- a/pkg/cephfs/controllerserver.go +++ b/pkg/cephfs/controllerserver.go @@ -295,7 +295,6 @@ func (cs *ControllerServer) ValidateVolumeCapabilities( // ExpandVolume expand CephFS Volumes on demand based on resizer request func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) { - if err := cs.validateExpandVolumeRequest(req); err != nil { klog.Errorf("ControllerExpandVolumeRequest validation failed: %v", err) return nil, err @@ -335,5 +334,4 @@ func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi CapacityBytes: RoundOffSize, NodeExpansionRequired: false, }, nil - } diff --git a/pkg/cephfs/driver.go b/pkg/cephfs/driver.go index e16d7013e..7d7c87927 100644 --- a/pkg/cephfs/driver.go +++ b/pkg/cephfs/driver.go @@ -91,7 +91,6 @@ func NewNodeServer(d *csicommon.CSIDriver, t string) *NodeServer { // Run start a non-blocking grpc controller,node and identityserver for // ceph CSI driver which can serve multiple parallel requests func (fs *Driver) Run(conf *util.Config, cachePersister util.CachePersister) { - // Configuration PluginFolder = conf.PluginPath diff --git a/pkg/cephfs/nodeserver.go b/pkg/cephfs/nodeserver.go index dab49a335..78c3e1bbb 100644 --- a/pkg/cephfs/nodeserver.go +++ b/pkg/cephfs/nodeserver.go @@ -163,7 +163,6 @@ func (*NodeServer) mount(ctx context.Context, volOptions *volumeOptions, req *cs // NodePublishVolume mounts the volume mounted to the staging path to the target // path func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) { - mountOptions := []string{"bind"} if err := util.ValidateNodePublishVolumeRequest(req); err != nil { return nil, err diff --git a/pkg/csi-common/driver.go b/pkg/csi-common/driver.go index b5bcd4863..650a2135c 100644 --- a/pkg/csi-common/driver.go +++ b/pkg/csi-common/driver.go @@ -88,7 +88,6 @@ func (d *CSIDriver) AddControllerServiceCapabilities(cl []csi.ControllerServiceC } d.cap = csc - } // AddVolumeCapabilityAccessModes stores volume access modes diff --git a/pkg/csi-common/nodeserver-default.go b/pkg/csi-common/nodeserver-default.go index 67e792c59..1680d6a7a 100644 --- a/pkg/csi-common/nodeserver-default.go +++ b/pkg/csi-common/nodeserver-default.go @@ -81,7 +81,6 @@ func (ns *DefaultNodeServer) NodeGetCapabilities(ctx context.Context, req *csi.N // NodeGetVolumeStats returns volume stats func (ns *DefaultNodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) { - var err error targetPath := req.GetVolumePath() if targetPath == "" { @@ -144,7 +143,6 @@ func (ns *DefaultNodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.No if !ok { klog.Errorf(util.Log(ctx, "failed to fetch available inodes")) return nil, status.Error(codes.Unknown, "failed to fetch available inodes") - } inodesFree, ok := (*(volMetrics.InodesFree)).AsInt64() if !ok { @@ -171,5 +169,4 @@ func (ns *DefaultNodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.No }, }, }, nil - } diff --git a/pkg/csi-common/server.go b/pkg/csi-common/server.go index d6ef6d953..64bee456a 100644 --- a/pkg/csi-common/server.go +++ b/pkg/csi-common/server.go @@ -56,7 +56,6 @@ type nonBlockingGRPCServer struct { // Start start service on endpoint func (s *nonBlockingGRPCServer) Start(endpoint, hstOptions string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer, metrics bool) { - s.wg.Add(1) go s.serve(endpoint, hstOptions, ids, cs, ns, metrics) } @@ -77,7 +76,6 @@ func (s *nonBlockingGRPCServer) ForceStop() { } func (s *nonBlockingGRPCServer) serve(endpoint, hstOptions string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer, metrics bool) { - proto, addr, err := parseEndpoint(endpoint) if err != nil { klog.Fatal(err.Error()) diff --git a/pkg/csi-common/utils.go b/pkg/csi-common/utils.go index b0b8fa6e1..510eafb5e 100644 --- a/pkg/csi-common/utils.go +++ b/pkg/csi-common/utils.go @@ -171,7 +171,6 @@ func panicHandler(ctx context.Context, req interface{}, info *grpc.UnaryServerIn klog.Errorf("panic occurred: %v", r) debug.PrintStack() err = status.Errorf(codes.Internal, "panic %v", r) - } }() return handler(ctx, req) diff --git a/pkg/liveness/liveness.go b/pkg/liveness/liveness.go index 9bc2fad58..e081f6596 100644 --- a/pkg/liveness/liveness.go +++ b/pkg/liveness/liveness.go @@ -38,7 +38,6 @@ var ( ) func getLiveness(timeout time.Duration, csiConn *grpc.ClientConn) { - ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() diff --git a/pkg/rbd/controllerserver.go b/pkg/rbd/controllerserver.go index 76ce80b42..004b6e79f 100644 --- a/pkg/rbd/controllerserver.go +++ b/pkg/rbd/controllerserver.go @@ -118,7 +118,6 @@ func (cs *ControllerServer) parseVolCreateRequest(ctx context.Context, req *csi. // CreateVolume creates the volume in backend func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) { - if err := cs.validateVolumeReq(ctx, req); err != nil { return nil, err } diff --git a/pkg/rbd/nodeserver.go b/pkg/rbd/nodeserver.go index 8732e322b..3e6406f91 100644 --- a/pkg/rbd/nodeserver.go +++ b/pkg/rbd/nodeserver.go @@ -236,7 +236,6 @@ func (ns *NodeServer) createStageMountPoint(ctx context.Context, mountPath strin // NodePublishVolume mounts the volume mounted to the device path to the target // path func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) { - err := util.ValidateNodePublishVolumeRequest(req) if err != nil { return nil, err @@ -408,7 +407,6 @@ func (ns *NodeServer) createTargetMountPath(ctx context.Context, mountPath strin } } return notMnt, err - } // NodeUnpublishVolume unmounts the volume from the target path diff --git a/pkg/util/nodecache.go b/pkg/util/nodecache.go index 7b139d466..364dc607c 100644 --- a/pkg/util/nodecache.go +++ b/pkg/util/nodecache.go @@ -70,7 +70,6 @@ func (nc *NodeCache) ForAll(pattern string, destObj interface{}, f ForAllFunc) e } } return err - } return nil } @@ -93,12 +92,10 @@ func decodeObj(fpath, pattern string, file os.FileInfo, destObj interface{}) err if err = decoder.Decode(destObj); err != nil { if err = fp.Close(); err != nil { return errors.Wrapf(err, "failed to close file %s", file.Name()) - } return errors.Wrapf(err, "node-cache: couldn't decode file %s", file.Name()) } return nil - } // Create creates the metadata file in cache directory with identifier name @@ -161,7 +158,6 @@ func (nc *NodeCache) Delete(identifier string) error { } return errors.Wrapf(err, "node-cache: error removing file %s", file) - } klog.V(4).Infof("node-cache: successfully deleted metadata storage file at: %+v\n", file) return nil diff --git a/pkg/util/voljournal.go b/pkg/util/voljournal.go index 81f15dadb..93bd06695 100644 --- a/pkg/util/voljournal.go +++ b/pkg/util/voljournal.go @@ -296,7 +296,6 @@ func reserveOMapName(ctx context.Context, monitors string, cr *Credentials, pool } return "", errors.New("uuid conflicts exceeds retry threshold") - } /* diff --git a/scripts/golangci.yml b/scripts/golangci.yml index 2101721d3..ed54b0ed3 100644 --- a/scripts/golangci.yml +++ b/scripts/golangci.yml @@ -141,6 +141,10 @@ linters-settings: # make an issue if func has more lines of code than this setting and # it has naked returns; default is 30 max-func-lines: 30 + gocognit: + # minimal code complexity to report, 30 by default (but we recommend 10-20) + # TODO: decrease complexity with refacoring the code + min-complexity: 40 linters: enable-all: true @@ -149,3 +153,6 @@ linters: - dupl - gochecknoinits - gochecknoglobals + - godox + - wsl + - funlen