diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index f4bc3be..d2fb1bb 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -58,10 +58,10 @@ jobs: name: Image Scanner runs-on: ubuntu-latest steps: - - name: Set up Go 1.20+ + - name: Set up Go 1.21+ uses: actions/setup-go@v2 with: - go-version: ^1.20 + go-version: ^1.21 id: go - name: Checkout the code uses: actions/checkout@v2 @@ -70,11 +70,8 @@ jobs: - name: Get dependencies run: go mod download - name: Build csm-metrics-powerflex Docker Image - run: make clean build docker - - name: Image scanner - uses: Azure/container-scan@v0 + run: make clean build docker + - name: Run Trivy action + uses: aquasecurity/trivy-action@master with: - image-name: csm-metrics-powerflex - severity-threshold: HIGH - env: - DOCKLE_HOST: "unix:///var/run/docker.sock" + image-ref: csm-metrics-powerflex diff --git a/Dockerfile b/Dockerfile index 370afda..ed607cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM registry.access.redhat.com/ubi9/ubi-micro +FROM registry.access.redhat.com/ubi9/ubi-micro@sha256:630cf7bdef807f048cadfe7180d6c27eb3aaa99323ffc3628811da230ed3322a LABEL vendor="Dell Inc." \ name="csm-metrics-powerflex" \ summary="Dell Container Storage Modules (CSM) for Observability - Metrics for PowerFlex" \ diff --git a/cmd/metrics-powerflex/main.go b/cmd/metrics-powerflex/main.go index 95ecb00..8f4be89 100644 --- a/cmd/metrics-powerflex/main.go +++ b/cmd/metrics-powerflex/main.go @@ -20,6 +20,7 @@ import ( "context" "fmt" "math" + "os" "strconv" "strings" "time" @@ -34,8 +35,6 @@ import ( sio "github.com/dell/goscaleio" "go.opentelemetry.io/otel/metric/global" - "os" - "github.com/fsnotify/fsnotify" "github.com/spf13/viper" ) @@ -47,7 +46,6 @@ const ( ) func main() { - logger := logrus.New() viper.SetConfigFile(defaultConfigFile) @@ -188,7 +186,7 @@ func updatePowerFlexConnection(config *entrypoint.Config, sdcFinder *k8s.SDCFind if powerFlexSystemID == "" { logger.WithError(err).Fatal("powerflex system ID was empty") } - var storageID = k8s.StorageSystemID{ + storageID := k8s.StorageSystemID{ ID: powerFlexSystemID, IsDefault: storageSystem.IsDefault, } diff --git a/go.mod b/go.mod index 08eee2a..7408fee 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/dell/karavi-metrics-powerflex go 1.21 require ( - github.com/dell/goscaleio v1.10.0 + github.com/dell/goscaleio v1.11.1-0.20230816075825-380ffbcbcd75 github.com/fsnotify/fsnotify v1.5.3 github.com/golang/mock v1.6.0 github.com/sirupsen/logrus v1.8.1 diff --git a/go.sum b/go.sum index 9854454..58e978a 100644 --- a/go.sum +++ b/go.sum @@ -78,8 +78,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dell/goscaleio v1.10.0 h1:XCEI9j+IlbqNPY7uvBjNNlT0Nt2PMXlnyxUavmennVY= -github.com/dell/goscaleio v1.10.0/go.mod h1:Zh2iQ44Jd8FMqU2h+rT5x1K6mdPMKQ15lkFxojU4z3w= +github.com/dell/goscaleio v1.11.1-0.20230816075825-380ffbcbcd75 h1:2bCpRCPqfzueF+ASLyjc1ZH7SN7GH8+rB6jbBcxeCck= +github.com/dell/goscaleio v1.11.1-0.20230816075825-380ffbcbcd75/go.mod h1:dMTrHnXSsPus+Kd9mrs0JuyrCndoKvFP/bbEdc21Bi8= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= diff --git a/internal/entrypoint/run.go b/internal/entrypoint/run.go index 5edaf3a..5675ab1 100644 --- a/internal/entrypoint/run.go +++ b/internal/entrypoint/run.go @@ -43,15 +43,13 @@ const ( // MinimumVolTickInterval is the minimum allowed interval when querying volume metrics MinimumVolTickInterval = 5 * time.Second // DefaultEndPoint for leader election path - DefaultEndPoint = "karavi-metrics-powerflex" + DefaultEndPoint = "karavi-metrics-powerflex" // #nosec G101 // DefaultNameSpace for powerflex pod running metrics collection DefaultNameSpace = "karavi" ) -var ( - // ConfigValidatorFunc is used to override config validation in testing - ConfigValidatorFunc func(*Config) error = ValidateConfig -) +// ConfigValidatorFunc is used to override config validation in testing +var ConfigValidatorFunc = ValidateConfig // Config holds data that will be used by the service type Config struct { @@ -116,7 +114,7 @@ func Run(ctx context.Context, config *Config, exporter otlexporters.Otlexporter, runtime.GOMAXPROCS(runtime.NumCPU()) - //set initial tick intervals + // set initial tick intervals SDCTickInterval := config.SDCTickInterval VolumeTickInterval := config.VolumeTickInterval StoragePoolTickInterval := config.StoragePoolTickInterval @@ -248,7 +246,7 @@ func Run(ctx context.Context, config *Config, exporter otlexporters.Otlexporter, return nil } - //check if tick interval config settings have changed + // check if tick interval config settings have changed if SDCTickInterval != config.SDCTickInterval { SDCTickInterval = config.SDCTickInterval sdcTicker = time.NewTicker(SDCTickInterval) diff --git a/internal/entrypoint/run_test.go b/internal/entrypoint/run_test.go index 0c5123b..c0d5736 100644 --- a/internal/entrypoint/run_test.go +++ b/internal/entrypoint/run_test.go @@ -44,7 +44,6 @@ func Test_Run(t *testing.T) { validVolumeTickInterval := entrypoint.MinimumSDCTickInterval tests := map[string]func(t *testing.T) (expectError bool, config *entrypoint.Config, exporter otlexporters.Otlexporter, pflexSvc pflexServices.Service, prevConfigValidationFunc func(*entrypoint.Config) error, ctrl *gomock.Controller, validatingConfig bool){ - "success": func(*testing.T) (bool, *entrypoint.Config, otlexporters.Otlexporter, pflexServices.Service, func(*entrypoint.Config) error, *gomock.Controller, bool) { ctrl := gomock.NewController(t) pfClient := metrics.NewMockPowerFlexClient(ctrl) diff --git a/internal/k8s/k8sapi_test.go b/internal/k8s/k8sapi_test.go index 5bbe2d1..e8a9a67 100644 --- a/internal/k8s/k8sapi_test.go +++ b/internal/k8s/k8sapi_test.go @@ -59,7 +59,6 @@ func Test_GetCSINodes(t *testing.T) { tests := map[string]func(t *testing.T) (connectFn, configFn, []checkFn){ "success": func(*testing.T) (connectFn, configFn, []checkFn) { - nodes := &v1.CSINodeList{ Items: []v1.CSINode{ { @@ -118,7 +117,6 @@ func Test_GetCSINodes(t *testing.T) { } }) } - } func Test_GetPersistentVolumes(t *testing.T) { @@ -147,7 +145,6 @@ func Test_GetPersistentVolumes(t *testing.T) { tests := map[string]func(t *testing.T) (connectFn, configFn, []checkFn){ "success": func(*testing.T) (connectFn, configFn, []checkFn) { - volumes := &corev1.PersistentVolumeList{ Items: []corev1.PersistentVolume{ { @@ -196,7 +193,6 @@ func Test_GetPersistentVolumes(t *testing.T) { } }) } - } func Test_GetStorageClasses(t *testing.T) { diff --git a/internal/k8s/leader_elector.go b/internal/k8s/leader_elector.go index d1d6f81..7cb0a8f 100644 --- a/internal/k8s/leader_elector.go +++ b/internal/k8s/leader_elector.go @@ -46,7 +46,6 @@ type LeaderElector struct { // InitLeaderElection will run algorithm for leader election, call during service initialzation process func (elect *LeaderElector) InitLeaderElection(endpoint string, namespace string) error { - k8sconfig, err := InClusterConfigFn() if err != nil { return err diff --git a/internal/k8s/node_finder_test.go b/internal/k8s/node_finder_test.go index 3415861..23de2f2 100644 --- a/internal/k8s/node_finder_test.go +++ b/internal/k8s/node_finder_test.go @@ -53,7 +53,6 @@ func Test_K8sNodeFinder(t *testing.T) { tests := map[string]func(t *testing.T) (k8s.NodeFinder, []checkFn, *gomock.Controller){ "success finding nodes": func(*testing.T) (k8s.NodeFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) api := mocks.NewMockNodeGetter(ctrl) diff --git a/internal/k8s/sdc_finder.go b/internal/k8s/sdc_finder.go index ffc0a84..fa8a2f9 100644 --- a/internal/k8s/sdc_finder.go +++ b/internal/k8s/sdc_finder.go @@ -63,7 +63,6 @@ func (f *SDCFinder) isMatch(driver v1.CSINodeDriver) bool { return true } } - } } return false diff --git a/internal/k8s/sdc_finder_test.go b/internal/k8s/sdc_finder_test.go index 090bfa1..b256cd1 100644 --- a/internal/k8s/sdc_finder_test.go +++ b/internal/k8s/sdc_finder_test.go @@ -53,7 +53,6 @@ func Test_K8sSDCFinder(t *testing.T) { tests := map[string]func(t *testing.T) (k8s.SDCFinder, []checkFn, *gomock.Controller){ "success": func(*testing.T) (k8s.SDCFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) api := mocks.NewMockKubernetesAPI(ctrl) @@ -113,7 +112,6 @@ func Test_K8sSDCFinder(t *testing.T) { return finder, check(hasNoError, checkExpectedOutput([]string{"node-1", "node-3"})), ctrl }, "success with multiple driver names": func(*testing.T) (k8s.SDCFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) api := mocks.NewMockKubernetesAPI(ctrl) @@ -181,5 +179,4 @@ func Test_K8sSDCFinder(t *testing.T) { ctrl.Finish() }) } - } diff --git a/internal/k8s/storageclass_finder.go b/internal/k8s/storageclass_finder.go index 3486023..4fc2957 100644 --- a/internal/k8s/storageclass_finder.go +++ b/internal/k8s/storageclass_finder.go @@ -58,7 +58,6 @@ func (f *StorageClassFinder) GetStorageClasses() ([]v1.StorageClass, error) { } func (f *StorageClassFinder) isMatch(class v1.StorageClass) bool { - for _, storage := range f.StorageSystemID { if !Contains(storage.DriverNames, class.Provisioner) { continue diff --git a/internal/k8s/storageclass_finder_test.go b/internal/k8s/storageclass_finder_test.go index fb21383..bfc6edc 100644 --- a/internal/k8s/storageclass_finder_test.go +++ b/internal/k8s/storageclass_finder_test.go @@ -53,7 +53,6 @@ func Test_K8sStorageClassFinder(t *testing.T) { tests := map[string]func(t *testing.T) (k8s.StorageClassFinder, []checkFn, *gomock.Controller){ "success not selecting storageclass that is not in config": func(*testing.T) (k8s.StorageClassFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) api := mocks.NewMockStorageClassGetter(ctrl) @@ -96,7 +95,6 @@ func Test_K8sStorageClassFinder(t *testing.T) { return finder, check(hasNoError, checkExpectedOutput(expected.Items)), ctrl }, "success selecting the matching driver name with storage classes": func(*testing.T) (k8s.StorageClassFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) api := mocks.NewMockStorageClassGetter(ctrl) @@ -133,7 +131,6 @@ func Test_K8sStorageClassFinder(t *testing.T) { return finder, check(hasNoError, checkExpectedOutput(storageClasses.Items)), ctrl }, "success selecting storage classes matching multiple driver names": func(*testing.T) (k8s.StorageClassFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) api := mocks.NewMockStorageClassGetter(ctrl) @@ -191,7 +188,6 @@ func Test_K8sStorageClassFinder(t *testing.T) { return finder, check(hasNoError, checkExpectedOutput(storageClasses.Items)), ctrl }, "success matching storage classes without systemID based on a default system being used": func(*testing.T) (k8s.StorageClassFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) api := mocks.NewMockStorageClassGetter(ctrl) @@ -260,7 +256,6 @@ func Test_K8sStorageClassFinder(t *testing.T) { )), ctrl }, "success selecting storage classes matching one of two driver names": func(*testing.T) (k8s.StorageClassFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) api := mocks.NewMockStorageClassGetter(ctrl) @@ -358,7 +353,6 @@ func Test_K8sStorageClassFinder(t *testing.T) { ctrl.Finish() }) } - } func Test_GetStoragePools(t *testing.T) { diff --git a/internal/k8s/volume_finder_test.go b/internal/k8s/volume_finder_test.go index ce30d23..faf7922 100644 --- a/internal/k8s/volume_finder_test.go +++ b/internal/k8s/volume_finder_test.go @@ -57,7 +57,6 @@ func Test_K8sPersistentVolumeFinder(t *testing.T) { tests := map[string]func(t *testing.T) (k8s.VolumeFinder, []checkFn, *gomock.Controller){ "success selecting the matching driver name with multiple volumes": func(*testing.T) (k8s.VolumeFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) api := mocks.NewMockVolumeGetter(ctrl) @@ -152,7 +151,6 @@ func Test_K8sPersistentVolumeFinder(t *testing.T) { })), ctrl }, "success selecting multiple volumes matching multiple driver names": func(*testing.T) (k8s.VolumeFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) api := mocks.NewMockVolumeGetter(ctrl) @@ -399,5 +397,4 @@ func Test_K8sPersistentVolumeFinder(t *testing.T) { ctrl.Finish() }) } - } diff --git a/internal/service/configuration_reader.go b/internal/service/configuration_reader.go index dbe12a2..c7d48f4 100644 --- a/internal/service/configuration_reader.go +++ b/internal/service/configuration_reader.go @@ -52,7 +52,6 @@ func (c *ConfigurationReader) GetStorageSystemConfiguration(file string) ([]Arra if string(config) == "" { return nil, fmt.Errorf("arrays details are not provided in vxflexos-config secret") - } connectionData := make([]ArrayConnectionData, 0) diff --git a/internal/service/metrics.go b/internal/service/metrics.go index 4653e54..7ac5833 100644 --- a/internal/service/metrics.go +++ b/internal/service/metrics.go @@ -116,7 +116,7 @@ func (mw *MetricsWrapper) initMetrics(prefix, metaID string, labels []attribute. return metrics, nil } -func (mw *MetricsWrapper) initCapacityMetrics(prefix, metaID string, labels []attribute.KeyValue) (*CapacityMetrics, error) { +func (mw *MetricsWrapper) initCapacityMetrics(prefix, metaID string, _ []attribute.KeyValue) (*CapacityMetrics, error) { totalLogicalCapacity, err := mw.Meter.AsyncFloat64().UpDownCounter(prefix + "total_logical_capacity_gigabytes") if err != nil { return nil, err @@ -155,7 +155,6 @@ func (mw *MetricsWrapper) Record(ctx context.Context, meta interface{}, readIOPS, writeIOPS, readLatency, writeLatency float64, ) error { - var prefix string var metaID string var labels []attribute.KeyValue @@ -246,8 +245,8 @@ func (mw *MetricsWrapper) Record(ctx context.Context, meta interface{}, // RecordCapacity will publish capacity metrics for a given instance func (mw *MetricsWrapper) RecordCapacity(ctx context.Context, meta interface{}, - totalLogicalCapacity, logicalCapacityAvailable, logicalCapacityInUse, logicalProvisioned float64) error { - + totalLogicalCapacity, logicalCapacityAvailable, logicalCapacityInUse, logicalProvisioned float64, +) error { switch v := meta.(type) { case StorageClassMeta: switch v.Driver { diff --git a/internal/service/service.go b/internal/service/service.go index f241043..00a2198 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -134,7 +134,7 @@ type LeaderElector interface { } // GetSDCs returns a slice of SDCs -func (s *PowerFlexService) GetSDCs(ctx context.Context, client PowerFlexClient, sdcFinder SDCFinder) ([]StatisticsGetter, error) { +func (s *PowerFlexService) GetSDCs(_ context.Context, client PowerFlexClient, sdcFinder SDCFinder) ([]StatisticsGetter, error) { var sdcs []StatisticsGetter sdcGUIDs, err := sdcFinder.GetSDCGuids() if err != nil { @@ -233,7 +233,7 @@ func (s *PowerFlexService) GetSDCStatistics(ctx context.Context, nodes []corev1. for range s.pushSDCMetrics(ctx, s.gatherSDCMetrics(ctx, nodes, s.sdcServer(sdcs))) { // consume the channel until it is empty and closed - } + } // revive:disable-line:empty-block } func (s *PowerFlexService) sdcServer(sdcs []StatisticsGetter) <-chan StatisticsGetter { @@ -248,7 +248,7 @@ func (s *PowerFlexService) sdcServer(sdcs []StatisticsGetter) <-chan StatisticsG } // gatherSDCMetrics will collect, in parallel, stats against each SDC referenced by 'statGetters' -func (s *PowerFlexService) gatherSDCMetrics(ctx context.Context, nodes []corev1.Node, sdcs <-chan StatisticsGetter) <-chan *SDCMetricsRecord { +func (s *PowerFlexService) gatherSDCMetrics(_ context.Context, nodes []corev1.Node, sdcs <-chan StatisticsGetter) <-chan *SDCMetricsRecord { start := time.Now() defer s.timeSince(start, "gatherMetrics") @@ -365,7 +365,7 @@ func getVolumeMeta(volume interface{}) *VolumeMeta { } // GetVolumes returns all unique, mapped volumes in sdcs -func (s *PowerFlexService) GetVolumes(ctx context.Context, sdcs []StatisticsGetter) ([]VolumeStatisticsGetter, error) { +func (s *PowerFlexService) GetVolumes(_ context.Context, sdcs []StatisticsGetter) ([]VolumeStatisticsGetter, error) { var uniqueVolumes []VolumeStatisticsGetter visited := make(map[string]bool) @@ -404,7 +404,7 @@ func (s *PowerFlexService) ExportVolumeStatistics(ctx context.Context, volumes [ for range s.pushVolumeMetrics(ctx, s.gatherVolumeMetrics(ctx, volumeFinder, s.volumeServer(volumes))) { // consume the channel until it is empty and closed - } + } // revive:disable-line:empty-block } // volumeServer will return a channel of volumes that can provide statistics about each volume @@ -420,7 +420,7 @@ func (s *PowerFlexService) volumeServer(volumes []VolumeStatisticsGetter) <-chan } // gatherVolumeMetrics will return a channel of volume metrics based on the input of volumes -func (s *PowerFlexService) gatherVolumeMetrics(ctx context.Context, volumeFinder VolumeFinder, volumes <-chan VolumeStatisticsGetter) <-chan *VolumeMetricsRecord { +func (s *PowerFlexService) gatherVolumeMetrics(_ context.Context, volumeFinder VolumeFinder, volumes <-chan VolumeStatisticsGetter) <-chan *VolumeMetricsRecord { start := time.Now() defer s.timeSince(start, "gatherVolumeMetrics") @@ -484,7 +484,6 @@ func (s *PowerFlexService) gatherVolumeMetrics(ctx context.Context, volumeFinder readIOPS: readIOPS, writeIOPS: writeIOPS, readLatency: readLatency, writeLatency: writeLatency, } - }(volume) } @@ -538,7 +537,7 @@ func (s *PowerFlexService) pushVolumeMetrics(ctx context.Context, volumeMetrics } // GetStorageClasses returns a list of StorageClassMeta -func (s *PowerFlexService) GetStorageClasses(ctx context.Context, client PowerFlexClient, storageClassFinder StorageClassFinder) ([]StorageClassMeta, error) { +func (s *PowerFlexService) GetStorageClasses(_ context.Context, client PowerFlexClient, storageClassFinder StorageClassFinder) ([]StorageClassMeta, error) { var c *sio.Client switch underlyingClient := client.(type) { case *sio.Client: @@ -645,7 +644,7 @@ func (s *PowerFlexService) GetStoragePoolStatistics(ctx context.Context, storage for i, storageClassMeta := range storageClassMetas { for range s.pushPoolStatistics(ctx, s.gatherPoolStatistics(ctx, &storageClassMetas[i], s.storagePoolServer(storageClassMeta.StoragePools))) { // consume the channel until empty and closed - } + } // revive:disable-line:empty-block } } @@ -660,7 +659,7 @@ func (s *PowerFlexService) storagePoolServer(pools map[string]StoragePoolStatist return poolChannel } -func (s *PowerFlexService) gatherPoolStatistics(ctx context.Context, scMeta *StorageClassMeta, pool <-chan IDedPoolStatisticGetter) <-chan *storagePoolMetricsRecord { +func (s *PowerFlexService) gatherPoolStatistics(_ context.Context, scMeta *StorageClassMeta, pool <-chan IDedPoolStatisticGetter) <-chan *storagePoolMetricsRecord { start := time.Now() defer s.timeSince(start, "gatherPoolStatistics") @@ -705,7 +704,6 @@ func (s *PowerFlexService) gatherPoolStatistics(ctx context.Context, scMeta *Sto LogicalCapacityInUse: logicalCapacityInUse, LogicalProvisioned: logicalProvisioned, } - }(pl) } wg.Wait() diff --git a/internal/service/service_test.go b/internal/service/service_test.go index fa843d9..4382332 100644 --- a/internal/service/service_test.go +++ b/internal/service/service_test.go @@ -314,7 +314,6 @@ func Test_GetSDCLatency(t *testing.T) { assert.InDelta(t, tc.ExpectedWriteLatency, writeLatency, 0.001) }) } - } func Test_GetSDCs(t *testing.T) { @@ -341,7 +340,6 @@ func Test_GetSDCs(t *testing.T) { tests := map[string]func(t *testing.T) (service.PowerFlexClient, service.SDCFinder, []checkFn, *gomock.Controller){ "success": func(*testing.T) (service.PowerFlexClient, service.SDCFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) powerflexClient := mocks.NewMockPowerFlexClient(ctrl) powerflexSystem := mocks.NewMockPowerFlexSystem(ctrl) @@ -357,7 +355,6 @@ func Test_GetSDCs(t *testing.T) { return powerflexClient, sdcFinder, check(hasNoError, checkSdcLength(2)), ctrl }, "error calling GetSDCGuids": func(*testing.T) (service.PowerFlexClient, service.SDCFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) powerflexClient := mocks.NewMockPowerFlexClient(ctrl) powerflexSystem := mocks.NewMockPowerFlexSystem(ctrl) @@ -436,7 +433,6 @@ func Test_GetSDCMeta(t *testing.T) { tests := map[string]func(t *testing.T) (*sio.Sdc, []corev1.Node, []checkFn){ "success": func(*testing.T) (*sio.Sdc, []corev1.Node, []checkFn) { - sdc := &sio.Sdc{ Sdc: &types.Sdc{ SdcIP: "1.2.3.4", @@ -512,7 +508,6 @@ func Test_GetStorageClasses(t *testing.T) { tests := map[string]func(t *testing.T) (service.PowerFlexClient, service.StorageClassFinder, []checkFn, *gomock.Controller){ "success one storage class one pool": func(*testing.T) (service.PowerFlexClient, service.StorageClassFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) powerflexClient := mocks.NewMockPowerFlexClient(ctrl) storageClassFinder := mocks.NewMockStorageClassFinder(ctrl) @@ -550,7 +545,6 @@ func Test_GetStorageClasses(t *testing.T) { return powerflexClient, storageClassFinder, check(hasNoError, checkPoolLength("class-1", 1)), ctrl }, "success two storage classes one pool": func(*testing.T) (service.PowerFlexClient, service.StorageClassFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) powerflexClient := mocks.NewMockPowerFlexClient(ctrl) storageClassFinder := mocks.NewMockStorageClassFinder(ctrl) @@ -600,7 +594,6 @@ func Test_GetStorageClasses(t *testing.T) { return powerflexClient, storageClassFinder, check(hasNoError, checkPoolLength("class-1", 1), checkPoolLength("class-1-xfs", 1)), ctrl }, "error calling GetStorageClasses": func(*testing.T) (service.PowerFlexClient, service.StorageClassFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) powerflexClient := mocks.NewMockPowerFlexClient(ctrl) storageClassFinder := mocks.NewMockStorageClassFinder(ctrl) @@ -610,7 +603,6 @@ func Test_GetStorageClasses(t *testing.T) { return powerflexClient, storageClassFinder, check(hasError), ctrl }, "error calling GetInstances": func(*testing.T) (service.PowerFlexClient, service.StorageClassFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) powerflexClient := mocks.NewMockPowerFlexClient(ctrl) storageClassFinder := mocks.NewMockStorageClassFinder(ctrl) @@ -683,7 +675,6 @@ func Test_GetStorageClasses(t *testing.T) { return powerflexClient, storageClassFinder, check(hasError), ctrl }, "calling GetInstances returns 0 systems": func(*testing.T) (service.PowerFlexClient, service.StorageClassFinder, []checkFn, *gomock.Controller) { - ctrl := gomock.NewController(t) powerflexClient := mocks.NewMockPowerFlexClient(ctrl) storageClassFinder := mocks.NewMockStorageClassFinder(ctrl) @@ -888,13 +879,13 @@ func Benchmark_GetStoragePoolStatistics(b *testing.B) { for i := 0; i < numOfPools; i++ { i := i - tmp_sp := mocks.NewMockStoragePoolStatisticsGetter(ctrl) - tmp_sp.EXPECT().GetStatistics().DoAndReturn(func() (*types.Statistics, error) { + tmpSp := mocks.NewMockStoragePoolStatisticsGetter(ctrl) + tmpSp.EXPECT().GetStatistics().DoAndReturn(func() (*types.Statistics, error) { dur, _ := time.ParseDuration(poolQueryTime) time.Sleep(dur) return &types.Statistics{}, nil }) - storagePools["poolID-"+strconv.Itoa(i)] = tmp_sp + storagePools["poolID-"+strconv.Itoa(i)] = tmpSp } scMetas := []service.StorageClassMeta{ @@ -943,13 +934,13 @@ func Test_GetVolumes(t *testing.T) { "success": func(*testing.T) (setup, []service.StatisticsGetter, []checkFn, *gomock.Controller) { ctrl := gomock.NewController(t) - mapped_infos := []*types.MappedSdcInfo{ + mappedInfos := []*types.MappedSdcInfo{ {SdcID: "60001", SdcIP: "10.234"}, {SdcID: "60002", SdcIP: "10.235"}, } volumes := []*types.Volume{ - {ID: "1", Name: "name_testing1", MappedSdcInfo: mapped_infos}, - {ID: "2", Name: "name_testing2", MappedSdcInfo: mapped_infos[:1]}, + {ID: "1", Name: "name_testing1", MappedSdcInfo: mappedInfos}, + {ID: "2", Name: "name_testing2", MappedSdcInfo: mappedInfos[:1]}, } volumeClient := []*sio.Volume{ @@ -1145,13 +1136,13 @@ func Benchmark_ExportVolumeStatistics(b *testing.B) { volFinder := mocks.NewMockVolumeFinder(ctrl) for i := 0; i < numOfVolumes; i++ { - tmp_vol := mocks.NewMockVolumeStatisticsGetter(ctrl) - tmp_vol.EXPECT().GetVolumeStatistics().DoAndReturn(func() (*types.VolumeStatistics, error) { + tmpVol := mocks.NewMockVolumeStatisticsGetter(ctrl) + tmpVol.EXPECT().GetVolumeStatistics().DoAndReturn(func() (*types.VolumeStatistics, error) { dur, _ := time.ParseDuration(volumeQueryTime) time.Sleep(dur) return &types.VolumeStatistics{}, nil }) - volumes = append(volumes, tmp_vol) + volumes = append(volumes, tmpVol) } service := service.PowerFlexService{MetricsWrapper: metrics, Logger: logrus.New()} @@ -1327,7 +1318,6 @@ func Test_GetVolumeLatency(t *testing.T) { assert.InDelta(t, tc.ExpectedWriteLatency, writeLatency, 0.001) }) } - } func Test_GetTotalLogicalCapacity(t *testing.T) {