Skip to content

Commit

Permalink
fix golangci-lint errors (#733)
Browse files Browse the repository at this point in the history
Signed-off-by: Bala.FA <[email protected]>
  • Loading branch information
balamurugana authored Mar 27, 2023
1 parent ae995d5 commit 259c482
Show file tree
Hide file tree
Showing 26 changed files with 55 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ jobs:
SHELLCHECK_OPTS: -e SC1091 -e SC2016
- uses: golangci/golangci-lint-action@v3
with:
version: v1.51.2
version: v1.52.1
args: --config ./.golangci.yml --timeout=60m
skip-go-installation: true
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ issues:
- exitAfterDefer

service:
golangci-lint-version: 1.51.2 # use the fixed version to not introduce new linters unexpectedly
golangci-lint-version: 1.52.1 # use the fixed version to not introduce new linters unexpectedly
4 changes: 2 additions & 2 deletions cmd/directpv/node-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ var nodeControllerCmd = &cobra.Command{
if err := node.Sync(c.Context(), nodeID); err != nil {
return err
}
return startNodeController(c.Context(), args)
return startNodeController(c.Context())
},
}

func startNodeController(ctx context.Context, args []string) error {
func startNodeController(ctx context.Context) error {
var cancel context.CancelFunc
ctx, cancel = context.WithCancel(ctx)
defer cancel()
Expand Down
8 changes: 4 additions & 4 deletions cmd/kubectl-directpv/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ func getLegacyFlag(ctx context.Context) bool {
if result.Err != nil {
utils.Eprintf(quietFlag, true, "unable to get volumes; %v", result.Err)
break
} else {
return true
}

return true
}

legacyclient.Init()
Expand All @@ -243,9 +243,9 @@ func getLegacyFlag(ctx context.Context) bool {
if result.Err != nil {
utils.Eprintf(quietFlag, true, "unable to get legacy volumes; %v", result.Err)
break
} else {
return true
}

return true
}

return false
Expand Down
6 changes: 2 additions & 4 deletions cmd/kubectl-directpv/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ func validateLabelCmd() error {
if err := validateNodeArgs(); err != nil {
return err
}
if err := validateDriveNameArgs(); err != nil {
return err
}
return nil

return validateDriveNameArgs()
}

func parseLabel(kv string) (labelKey types.LabelKey, labelValue types.LabelValue, err error) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-directpv/list_drives.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var listDrivesCmd = &cobra.Command{
os.Exit(-1)
}

listDrivesMain(c.Context(), args)
listDrivesMain(c.Context())
},
}

Expand Down Expand Up @@ -121,7 +121,7 @@ func validateListDrivesArgs() error {
return nil
}

func listDrivesMain(ctx context.Context, args []string) {
func listDrivesMain(ctx context.Context) {
drives, err := drive.NewLister().
NodeSelector(toLabelValues(nodesArgs)).
DriveNameSelector(toLabelValues(drivesArgs)).
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-directpv/list_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var listVolumesCmd = &cobra.Command{
os.Exit(-1)
}

listVolumesMain(c.Context(), args)
listVolumesMain(c.Context())
},
}

Expand Down Expand Up @@ -159,7 +159,7 @@ func getPVCName(ctx context.Context, volume types.Volume) string {
return "-"
}

func listVolumesMain(ctx context.Context, args []string) {
func listVolumesMain(ctx context.Context) {
volumes, err := volume.NewLister().
NodeSelector(toLabelValues(nodesArgs)).
DriveNameSelector(toLabelValues(drivesArgs)).
Expand Down
5 changes: 0 additions & 5 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ const (
// MountRootDir is mount root directory.
MountRootDir = AppRootDir + "/mnt"

CredentialsSecretName = AppName + "-creds"

PrivateKeyFileName = "key.pem"
PublicCertFileName = "cert.pem"

NodeServerName = "node-server"
ControllerServerName = "controller"
NodeControllerName = "node-controller"
Expand Down
5 changes: 0 additions & 5 deletions pkg/consts/consts.go.in
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ const (
// MountRootDir is mount root directory.
MountRootDir = AppRootDir + "/mnt"

CredentialsSecretName = AppName + "-creds"

PrivateKeyFileName = "key.pem"
PublicCertFileName = "cert.pem"

NodeServerName = "node-server"
ControllerServerName = "controller"
NodeControllerName = "node-controller"
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type Controller struct {
}

// New creates a new controller for the provided handler
func New(ctx context.Context, name string, handler EventHandler, workers int, resyncPeriod time.Duration) *Controller {
func New(name string, handler EventHandler, workers int, resyncPeriod time.Duration) *Controller {
informer := cache.NewSharedIndexInformer(
handler.ListerWatcher(),
handler.ObjectType(),
Expand Down Expand Up @@ -153,9 +153,11 @@ func (c *Controller) HasSynced() bool {
}

func (c *Controller) runWorker(ctx context.Context) {
//revive:disable:empty-block
for c.processNextItem(ctx) {
// continue looping
}
//revive:enable:empty-block
}

func (c *Controller) processNextItem(ctx context.Context) bool {
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func (handler *testEventHandler) ObjectType() runtime.Object {
return &pkgtypes.Volume{}
}

func (handler *testEventHandler) Handle(ctx context.Context, eventType EventType, object runtime.Object) error {
func (handler *testEventHandler) Handle(_ context.Context, eventType EventType, object runtime.Object) error {
return handler.handleFunc(eventType, object)
}

func startTestController(ctx context.Context, t *testing.T, handler *testEventHandler, threadiness int) {
controller := New(ctx, "test-volume-controller", handler, 1, 10*time.Second)
func startTestController(ctx context.Context, handler *testEventHandler) {
controller := New("test-volume-controller", handler, 1, 10*time.Second)
go controller.Run(ctx)
}

Expand Down Expand Up @@ -147,7 +147,7 @@ func TestController(t *testing.T) {

doneCh, handleFunc := getHandleFunc(t, AddEvent, volumesMap)
testHandler.handleFunc = handleFunc
startTestController(ctx, t, testHandler, 1)
startTestController(ctx, testHandler)
<-doneCh

volumes = []*pkgtypes.Volume{
Expand Down
5 changes: 1 addition & 4 deletions pkg/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ func MigrateList(fromList, toList *unstructured.UnstructuredList, groupVersion s
fromList.DeepCopyInto(toList)
fn := func(obj runtime.Object) error {
cpObj := obj.DeepCopyObject()
if err := Migrate(cpObj.(*unstructured.Unstructured), obj.(*unstructured.Unstructured), groupVersion); err != nil {
return err
}
return nil
return Migrate(cpObj.(*unstructured.Unstructured), obj.(*unstructured.Unstructured), groupVersion)
}
toList.SetAPIVersion(groupVersion.Group + "/" + groupVersion.Version)
return toList.EachListItem(fn)
Expand Down
2 changes: 1 addition & 1 deletion pkg/csi/controller/legacy_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewLegacyServer() *LegacyServer {

// CreateVolume - Creates a volume
// reference: https://github.com/container-storage-interface/spec/blob/master/spec.md#createvolume
func (c *LegacyServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
func (c *LegacyServer) CreateVolume(_ context.Context, _ *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
return nil, status.Errorf(
codes.InvalidArgument,
fmt.Sprintf("legacy volume creation not supported; use %v storage class", consts.Identity),
Expand Down
20 changes: 10 additions & 10 deletions pkg/csi/controller/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func NewServer() *Server {

// ControllerGetCapabilities constructs ControllerGetCapabilitiesResponse
// reference: https://github.com/container-storage-interface/spec/blob/master/spec.md#controllergetcapabilities
func (c *Server) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
func (c *Server) ControllerGetCapabilities(_ context.Context, _ *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
return &csi.ControllerGetCapabilitiesResponse{
Capabilities: []*csi.ControllerServiceCapability{
{
Expand All @@ -100,7 +100,7 @@ func (c *Server) ControllerGetCapabilities(ctx context.Context, req *csi.Control

// ValidateVolumeCapabilities validates volume capabilities
// reference: https://github.com/container-storage-interface/spec/blob/master/spec.md#validatevolumecapabilities
func (c *Server) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
func (c *Server) ValidateVolumeCapabilities(_ context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
var message string
for _, vcap := range req.GetVolumeCapabilities() {
if vcap.GetAccessMode() != nil && vcap.GetAccessMode().GetMode() != csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER {
Expand Down Expand Up @@ -347,48 +347,48 @@ func (c *Server) ControllerExpandVolume(ctx context.Context, req *csi.Controller

// ListVolumes implements ListVolumes controller RPC
// reference: https://github.com/container-storage-interface/spec/blob/master/spec.md#listvolumes
func (c *Server) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) {
func (c *Server) ListVolumes(_ context.Context, _ *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) {
return nil, status.Error(codes.Unimplemented, "unimplemented")
}

// ControllerPublishVolume - controller RPC to publish volumes
// reference: https://github.com/container-storage-interface/spec/blob/master/spec.md#controllerpublishvolume
func (c *Server) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) {
func (c *Server) ControllerPublishVolume(_ context.Context, _ *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) {
return nil, status.Error(codes.Unimplemented, "unimplemented")
}

// ControllerUnpublishVolume - controller RPC to unpublish volumes
// reference: https://github.com/container-storage-interface/spec/blob/master/spec.md#controllerunpublishvolume
func (c *Server) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) {
func (c *Server) ControllerUnpublishVolume(_ context.Context, _ *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) {
return nil, status.Error(codes.Unimplemented, "unimplemented")
}

// ControllerGetVolume - controller RPC for get volume
// reference: https://github.com/container-storage-interface/spec/blob/master/spec.md#controllergetvolume
func (c *Server) ControllerGetVolume(ctx context.Context, req *csi.ControllerGetVolumeRequest) (*csi.ControllerGetVolumeResponse, error) {
func (c *Server) ControllerGetVolume(_ context.Context, _ *csi.ControllerGetVolumeRequest) (*csi.ControllerGetVolumeResponse, error) {
return nil, status.Error(codes.Unimplemented, "unimplemented")
}

// ListSnapshots - controller RPC for listing snapshots
// reference: https://github.com/container-storage-interface/spec/blob/master/spec.md#listsnapshots
func (c *Server) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) {
func (c *Server) ListSnapshots(_ context.Context, _ *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) {
return nil, status.Error(codes.Unimplemented, "unimplemented")
}

// CreateSnapshot controller RPC for creating snapshots
// reference: https://github.com/container-storage-interface/spec/blob/master/spec.md#createsnapshot
func (c *Server) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) {
func (c *Server) CreateSnapshot(_ context.Context, _ *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) {
return nil, status.Error(codes.Unimplemented, "unimplemented")
}

// DeleteSnapshot - controller RPC for deleting snapshots
// reference: https://github.com/container-storage-interface/spec/blob/master/spec.md#deletesnapshot
func (c *Server) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {
func (c *Server) DeleteSnapshot(_ context.Context, _ *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {
return nil, status.Error(codes.Unimplemented, "unimplemented")
}

// GetCapacity - controller RPC to get capacity
// reference: https://github.com/container-storage-interface/spec/blob/master/spec.md#getcapacity
func (c *Server) GetCapacity(ctx context.Context, req *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) {
func (c *Server) GetCapacity(_ context.Context, _ *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) {
return nil, status.Error(codes.Unimplemented, "unimplemented")
}
6 changes: 3 additions & 3 deletions pkg/csi/identity/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewServer(identity, version string, capabilities []*csi.PluginCapability) (
}, nil
}

func (i *identityServer) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
func (i *identityServer) GetPluginInfo(_ context.Context, _ *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
if i.identity == "" {
return nil, status.Error(codes.Unavailable, "Driver name not configured")
}
Expand All @@ -74,10 +74,10 @@ func (i *identityServer) GetPluginInfo(ctx context.Context, req *csi.GetPluginIn
}, nil
}

func (i *identityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*csi.ProbeResponse, error) {
func (i *identityServer) Probe(_ context.Context, _ *csi.ProbeRequest) (*csi.ProbeResponse, error) {
return &csi.ProbeResponse{}, nil
}

func (i *identityServer) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
func (i *identityServer) GetPluginCapabilities(_ context.Context, _ *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
return &csi.GetPluginCapabilitiesResponse{Capabilities: i.capabilities}, nil
}
2 changes: 1 addition & 1 deletion pkg/csi/node/legacy_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewLegacyServer(nodeID directpvtypes.NodeID, rack, zone, region string) *Le

// NodeGetInfo gets node information.
// reference: https://github.com/container-storage-interface/spec/blob/master/spec.md#nodegetinfo
func (server *LegacyServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
func (server *LegacyServer) NodeGetInfo(_ context.Context, _ *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
topology := &csi.Topology{
Segments: map[string]string{
"direct.csi.min.io/identity": server.identity,
Expand Down
4 changes: 2 additions & 2 deletions pkg/csi/node/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func NewServer(ctx context.Context,

// NodeGetInfo gets node information.
// reference: https://github.com/container-storage-interface/spec/blob/master/spec.md#nodegetinfo
func (server *Server) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
func (server *Server) NodeGetInfo(_ context.Context, _ *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
topology := &csi.Topology{
Segments: map[string]string{
string(directpvtypes.TopologyDriverIdentity): server.identity,
Expand All @@ -105,7 +105,7 @@ func (server *Server) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoReque

// NodeGetCapabilities gets node capabilities.
// reference: https://github.com/container-storage-interface/spec/blob/master/spec.md#nodegetcapabilities
func (server *Server) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
func (server *Server) NodeGetCapabilities(_ context.Context, _ *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
nodeCap := func(cap csi.NodeServiceCapability_RPC_Type) *csi.NodeServiceCapability {
klog.V(5).InfoS("Using node capability", "NodeServiceCapability", cap)

Expand Down
12 changes: 5 additions & 7 deletions pkg/drive/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ func SetIOError(ctx context.Context, driveID directpvtypes.DriveID) error {
_, err = client.DriveClient().Update(ctx, drive, metav1.UpdateOptions{TypeMeta: types.NewDriveTypeMeta()})
return err
}
if err := retry.RetryOnConflict(retry.DefaultRetry, updateFunc); err != nil {
return err
}
return nil

return retry.RetryOnConflict(retry.DefaultRetry, updateFunc)
}

// StageVolume creates and mounts staging target path of the volume to the drive.
Expand Down Expand Up @@ -190,7 +188,7 @@ func (handler *driveEventHandler) ObjectType() runtime.Object {
return &types.Drive{}
}

func (handler *driveEventHandler) unmountDrive(ctx context.Context, drive *types.Drive, skipDriveMount bool) error {
func (handler *driveEventHandler) unmountDrive(drive *types.Drive, skipDriveMount bool) error {
mountPointMap, deviceMap, err := handler.getMounts()
if err != nil {
return err
Expand Down Expand Up @@ -225,7 +223,7 @@ func (handler *driveEventHandler) remove(ctx context.Context, drive *types.Drive
if volumeCount > 0 {
return fmt.Errorf("drive %v still contains %v volumes", drive.GetDriveID(), volumeCount)
}
if err := handler.unmountDrive(ctx, drive, false); err != nil {
if err := handler.unmountDrive(drive, false); err != nil {
return err
}
drive.RemoveFinalizers()
Expand Down Expand Up @@ -335,6 +333,6 @@ func (handler *driveEventHandler) Handle(ctx context.Context, eventType controll

// StartController starts drive controller.
func StartController(ctx context.Context, nodeID directpvtypes.NodeID) {
ctrl := controller.New(ctx, "drive", newDriveEventHandler(nodeID), workerThreads, resyncPeriod)
ctrl := controller.New("drive", newDriveEventHandler(nodeID), workerThreads, resyncPeriod)
ctrl.Run(ctx)
}
6 changes: 3 additions & 3 deletions pkg/initrequest/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (handler *initRequestEventHandler) initDevices(ctx context.Context, req *ty
wg.Add(1)
go func(i int, device pkgdevice.Device, force bool) {
defer wg.Done()
if err := handler.initDevice(ctx, device, force); err != nil {
if err := handler.initDevice(device, force); err != nil {
results[i].Error = err.Error()
}
}(i, device, req.Spec.Devices[i].Force)
Expand All @@ -223,7 +223,7 @@ func updateInitRequest(ctx context.Context, name string, results []types.InitDev
return retry.RetryOnConflict(retry.DefaultRetry, updateFunc)
}

func (handler *initRequestEventHandler) initDevice(ctx context.Context, device pkgdevice.Device, force bool) error {
func (handler *initRequestEventHandler) initDevice(device pkgdevice.Device, force bool) error {
devPath := utils.AddDevPrefix(device.Name)

deviceMap, majorMinorMap, err := handler.getMounts()
Expand Down Expand Up @@ -310,6 +310,6 @@ func StartController(ctx context.Context, nodeID directpvtypes.NodeID, identity,
klog.ErrorS(err, "unable to create initrequest event handler")
return
}
ctrl := controller.New(ctx, "initrequest", initRequestHandler, workerThreads, resyncPeriod)
ctrl := controller.New("initrequest", initRequestHandler, workerThreads, resyncPeriod)
ctrl.Run(ctx)
}
1 change: 0 additions & 1 deletion pkg/installer/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const (
UnixCSIEndpoint = "unix:///csi/csi.sock"

namespace = consts.AppName
caCertFileName = "ca.crt"
healthZContainerPortName = "healthz"
healthZContainerPort = 9898
volumePathSysDir = "/sys"
Expand Down
Loading

0 comments on commit 259c482

Please sign in to comment.