Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Golint errors fixes #297

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions pkg/array/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ import (
"gopkg.in/yaml.v3"
)

var (
// IPToArray - Store Array IPs
IPToArray map[string]string
)
// IPToArray - Store Array IPs
var IPToArray map[string]string

// Consumer provides methods for safe management of arrays
type Consumer interface {
Expand Down Expand Up @@ -216,7 +214,8 @@ func GetPowerStoreArrays(fs fs.Interface, filePath string) (map[string]*PowerSto
"unable to create PowerStore client: %s", err.Error())
}
c.SetCustomHTTPHeaders(http.Header{
"Application-Type": {fmt.Sprintf("%s/%s", common.VerboseName, core.SemVer)}})
"Application-Type": {fmt.Sprintf("%s/%s", common.VerboseName, core.SemVer)},
})

c.SetLogger(&common.CustomLogger{})
array.Client = c
Expand Down Expand Up @@ -338,7 +337,6 @@ func (s *Locker) RegisterK8sCluster(fs fs.Interface) error {
Port: cluster.Port,
Token: cluster.Token,
})

if err != nil {
log.Errorf("cannot register k8s cluster: %s with %s:%d to array: %s err: %s \n",
cluster.Name, cluster.IPAddress, cluster.Port, array.Endpoint, err.Error())
Expand Down
6 changes: 3 additions & 3 deletions pkg/array/array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ func TestParseVolumeID(t *testing.T) {
}

volCap := getVolCap()
gotId, gotIp, protocol, err := array.ParseVolumeID(context.Background(), id, &array.PowerStoreArray{IP: ip, GlobalID: "gid1"}, volCap)
gotID, gotIP, protocol, err := array.ParseVolumeID(context.Background(), id, &array.PowerStoreArray{IP: ip, GlobalID: "gid1"}, volCap)
assert.NoError(t, err)
assert.Equal(t, id, gotId)
assert.Equal(t, ip, gotIp)
assert.Equal(t, id, gotID)
assert.Equal(t, ip, gotIP)
assert.Equal(t, protocol, "nfs")
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func GetISCSITargetsInfoFromStorage(client gopowerstore.Client, volumeApplianceI
})
var result []gobrick.ISCSITargetInfo
for _, t := range addrInfo {
//volumeApplianceID will be empty in case the call is from NodeGetInfo
// volumeApplianceID will be empty in case the call is from NodeGetInfo
if t.ApplianceID == volumeApplianceID || volumeApplianceID == "" {
result = append(result, gobrick.ISCSITargetInfo{Target: t.IPPort.TargetIqn, Portal: fmt.Sprintf("%s:3260", t.Address)})
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestCustomLogger(t *testing.T) {
func TestCustomLogger(_ *testing.T) {
log.SetLevel(log.DebugLevel)
lg := &common.CustomLogger{}
ctx := context.Background()
Expand Down Expand Up @@ -87,7 +87,6 @@ func TestRmSockFile(t *testing.T) {

common.RmSockFile(fsMock)
})

}

func TestSetLogFields(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/common/envvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
// node name
EnvKubeNodeName = "X_CSI_POWERSTORE_KUBE_NODE_NAME"

//EnvKubeConfigPath indicates kubernetes configuration path that has to be used by CSI Driver
// EnvKubeConfigPath indicates kubernetes configuration path that has to be used by CSI Driver
EnvKubeConfigPath = "KUBECONFIG"

// EnvNodeNamePrefix is the name of the environment variable which stores prefix which will be
Expand Down Expand Up @@ -105,12 +105,12 @@ const (
// EnvAllowAutoRoundOffFilesystemSize specifies if auto round off minimum filesystem size is enabled
EnvAllowAutoRoundOffFilesystemSize = "CSI_AUTO_ROUND_OFF_FILESYSTEM_SIZE"

//EnvPodmonEnabled indicates that podmon is enabled
// EnvPodmonEnabled indicates that podmon is enabled
EnvPodmonEnabled = "X_CSI_PODMON_ENABLED"

//EnvPodmonAPIPORT indicates the port to be used for exposing podmon API health, ToDo: Rename to var EnvPodmonArrayConnectivityAPIPORT
// EnvPodmonAPIPORT indicates the port to be used for exposing podmon API health, ToDo: Rename to var EnvPodmonArrayConnectivityAPIPORT
EnvPodmonAPIPORT = "X_CSI_PODMON_API_PORT"

//EnvPodmonArrayConnectivityPollRate indicates the polling frequency to check array connectivity
// EnvPodmonArrayConnectivityPollRate indicates the polling frequency to check array connectivity
EnvPodmonArrayConnectivityPollRate = "X_CSI_PODMON_ARRAY_CONNECTIVITY_POLL_RATE"
)
7 changes: 4 additions & 3 deletions pkg/common/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type Interface interface {
// wrapper
ParseProcMounts(ctx context.Context, content io.Reader) ([]gofsutil.Info, error)
MkFileIdempotent(path string) (bool, error)
//Network
// Network
NetDial(endpoint string) (net.Conn, error)
}

Expand Down Expand Up @@ -188,7 +188,8 @@ func (fs *Fs) ExecCommandOutput(name string, args ...string) ([]byte, error) {
// ParseProcMounts is wrapper of gofsutil.ReadProcMountsFrom global function
func (fs *Fs) ParseProcMounts(
ctx context.Context,
content io.Reader) ([]gofsutil.Info, error) {
content io.Reader,
) ([]gofsutil.Info, error) {
r, _, err := gofsutil.ReadProcMountsFrom(ctx, content, false,
gofsutil.ProcMountsFields, gofsutil.DefaultEntryScanFunc())
return r, err
Expand All @@ -203,7 +204,7 @@ func (fs *Fs) NetDial(endpoint string) (net.Conn, error) {
func (fs *Fs) MkFileIdempotent(path string) (bool, error) {
st, err := fs.Stat(path)
if fs.IsNotExist(err) {
file, err := fs.OpenFile(path, os.O_CREATE, 0600)
file, err := fs.OpenFile(path, os.O_CREATE, 0o600)
if err != nil {
log.WithField("path", path).WithError(err).Error("Unable to create file")
return false, err
Expand Down
10 changes: 5 additions & 5 deletions pkg/common/fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type FsTestSuite struct {
func (suite *FsTestSuite) SetupSuite() {
suite.fs = &Fs{Util: &gofsutil.FS{}}
suite.tmp = "./tmp"
err := os.Mkdir(suite.tmp, 0750)
err := os.Mkdir(suite.tmp, 0o750)
if err != nil {
suite.T().Error("couldn't create the tmp folder")
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func (suite *FsTestSuite) TestCreate() {
func (suite *FsTestSuite) TestWriteFile() {
str := "random string \n hello"
data := []byte(str)
err := suite.fs.WriteFile(suite.tmp+"/create", data, 0640)
err := suite.fs.WriteFile(suite.tmp+"/create", data, 0o640)
suite.Assert().NoError(err)

bytes, err := suite.fs.ReadFile(suite.tmp + "/create")
Expand All @@ -83,11 +83,11 @@ func (suite *FsTestSuite) TestWriteFile() {
}

func (suite *FsTestSuite) TestMkDir() {
err := suite.fs.Mkdir(suite.tmp+"/dir", 0750)
err := suite.fs.Mkdir(suite.tmp+"/dir", 0o750)
suite.Assert().NoError(err)
suite.Assert().DirExists(suite.tmp + "/dir")

err = suite.fs.MkdirAll(suite.tmp+"/1/2/3", 0750)
err = suite.fs.MkdirAll(suite.tmp+"/1/2/3", 0o750)
suite.Assert().NoError(err)
suite.Assert().DirExists(suite.tmp + "/1/2")

Expand All @@ -101,7 +101,7 @@ func (suite *FsTestSuite) TestMkFileIdempotent() {
suite.Assert().NoError(err)
suite.Assert().Equal(true, created)

err = suite.fs.Mkdir(suite.tmp+"/mydir", 0750)
err = suite.fs.Mkdir(suite.tmp+"/mydir", 0o750)
suite.Assert().NoError(err)
_, err = suite.fs.MkFileIdempotent(suite.tmp + "/mydir")
suite.Assert().EqualError(err, "existing path is a directory")
Expand Down
1 change: 1 addition & 0 deletions pkg/common/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package common

import (
"context"

log "github.com/sirupsen/logrus"
)

Expand Down
14 changes: 8 additions & 6 deletions pkg/controller/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ package controller
import (
"context"
"errors"
"net/http"
"strings"
"testing"

"github.com/dell/gopowerstore"
"github.com/dell/gopowerstore/api"
"github.com/dell/gopowerstore/mocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"net/http"
"strings"
"testing"
)

func TestVolumeName(t *testing.T) {
Expand All @@ -40,8 +41,10 @@ func TestVolumeName(t *testing.T) {
}{
{"IsOkName", nil},
{"", status.Errorf(codes.InvalidArgument, "name cannot be empty")},
{strings.Repeat("N", MaxVolumeNameLength+1),
status.Errorf(codes.InvalidArgument, "name must contain %d or fewer printable Unicode characters", MaxVolumeNameLength)},
{
strings.Repeat("N", MaxVolumeNameLength+1),
status.Errorf(codes.InvalidArgument, "name must contain %d or fewer printable Unicode characters", MaxVolumeNameLength),
},
}

for _, test := range tests {
Expand Down Expand Up @@ -154,5 +157,4 @@ func TestDetachVolumeFromHost(t *testing.T) {
assert.Error(t, err)
assert.Contains(t, err.Error(), "unexpected api error when detaching volume from host")
})

}
6 changes: 3 additions & 3 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (s *Service) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest
}

// Fetch the service tag
var serviceTag = GetServiceTag(ctx, req, arr, resp.ID, protocol)
serviceTag := GetServiceTag(ctx, req, arr, resp.ID, protocol)

volumeResponse.VolumeContext = req.Parameters
volumeResponse.VolumeContext[common.KeyArrayID] = arr.GetGlobalID()
Expand Down Expand Up @@ -964,7 +964,7 @@ func cacheMaximumVolumeSize(key string, value int64) {
}

// ControllerGetCapabilities returns list of capabilities that are supported by the driver.
func (s *Service) ControllerGetCapabilities(ctx context.Context, request *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
func (s *Service) ControllerGetCapabilities(_ context.Context, _ *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
newCap := func(cap csi.ControllerServiceCapability_RPC_Type) *csi.ControllerServiceCapability {
return &csi.ControllerServiceCapability{
Type: &csi.ControllerServiceCapability_Rpc{
Expand Down Expand Up @@ -1327,7 +1327,7 @@ func (s *Service) RegisterAdditionalServers(server *grpc.Server) {
}

// ProbeController probes the controller service
func (s *Service) ProbeController(ctx context.Context, req *commonext.ProbeControllerRequest) (*commonext.ProbeControllerResponse, error) {
func (s *Service) ProbeController(_ context.Context, _ *commonext.ProbeControllerRequest) (*commonext.ProbeControllerResponse, error) {
ready := new(wrappers.BoolValue)
ready.Value = true
rep := new(commonext.ProbeControllerResponse)
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/controller_node_to_array_connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ func (s *Service) QueryArrayStatus(ctx context.Context, url string) (bool, error
return false, err
}
log.Infof("API Response received is %+v\n", statusResponse)
//responseObject has last success and last attempt timestamp in Unix format
// responseObject has last success and last attempt timestamp in Unix format
timeDiff := statusResponse.LastAttempt - statusResponse.LastSuccess
tolerance := common.SetPollingFrequency(ctx)
currTime := time.Now().Unix()
//checking if the status response is stale and connectivity test is still running
//since nodeProbe is run at frequency tolerance/2, ideally below check should never be true
// checking if the status response is stale and connectivity test is still running
// since nodeProbe is run at frequency tolerance/2, ideally below check should never be true
if (currTime - statusResponse.LastAttempt) > tolerance*2 {
log.Errorf("seems like connectivity test is not being run, current time is %d and last run was at %d", currTime, statusResponse.LastAttempt)
//considering connectivity is broken
// considering connectivity is broken
return false, nil
}
log.Debugf("last connectivity was %d sec back, tolerance is %d sec", timeDiff, tolerance)
//give 2s leeway for tolerance check
// give 2s leeway for tolerance check
if timeDiff <= tolerance+2 {
return true, nil
}
Expand Down
Loading
Loading