Skip to content

Commit

Permalink
Updating if check for a failover failure
Browse files Browse the repository at this point in the history
  • Loading branch information
delldubey committed Jan 31, 2024
1 parent 9b3ee3d commit 336f64a
Show file tree
Hide file tree
Showing 35 changed files with 321 additions and 295 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/dell/gofsutil v1.14.0
github.com/dell/goiscsi v1.8.0
github.com/dell/gonvme v1.6.0
github.com/dell/gopowerstore v1.14.1
github.com/dell/gopowerstore v1.14.2
github.com/fsnotify/fsnotify v1.7.0
github.com/go-openapi/strfmt v0.21.3
github.com/golang/mock v1.6.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ github.com/dell/gonvme v1.6.0 h1:Y/g0Ml8E3oSB+bqGJN1/U+V621h9t0KJeYAF5aQ7NVU=
github.com/dell/gonvme v1.6.0/go.mod h1:/UgJAlR03LbPSDIK2BfhiYUlzyY7lAMJ6ao8eYab2Eg=
github.com/dell/gopowerstore v1.14.1 h1:xn9FFMLDRg42+L9OR8wOnIQfG+YGNauX9qT0vPeEfyw=
github.com/dell/gopowerstore v1.14.1/go.mod h1:YH3SpMX2dr3ouYWWPhk5lzjip3aaVVksFOSoenRDY5w=
github.com/dell/gopowerstore v1.14.2 h1:1mtQBDbMEaVtLKYj1R1z6q5TBKlI2KnGHmWOcZCvcfA=
github.com/dell/gopowerstore v1.14.2/go.mod h1:YH3SpMX2dr3ouYWWPhk5lzjip3aaVVksFOSoenRDY5w=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
Expand Down
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
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
1 change: 0 additions & 1 deletion pkg/common/common_test.go
Original file line number Diff line number Diff line change
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")
})

}
2 changes: 1 addition & 1 deletion 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
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

0 comments on commit 336f64a

Please sign in to comment.