From 5b8a79e637f28a642e8d964f66fa3d67c3a04ad5 Mon Sep 17 00:00:00 2001 From: Chiman Jain <36687396+chimanjain@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:56:22 +0530 Subject: [PATCH] fix lint warnings (#82) --- pkg/k8sclient/resources/pod/pod.go | 5 +- pkg/k8sclient/resources/pv/pv.go | 5 +- pkg/k8sclient/resources/sc/sc.go | 5 +- pkg/k8sclient/resources/statefulset/sts.go | 5 +- .../resources/volumegroupsnapshot/vgs.go | 5 +- .../resources/volumesnapshot/v1/snap.go | 5 +- .../resources/volumesnapshot/v1beta1/snap.go | 5 +- .../volumesnapshotcontent/v1/content.go | 5 +- .../volumesnapshotcontent/v1beta1/content.go | 5 +- pkg/observer/va.go | 2 +- pkg/observer/va_alt.go | 2 +- pkg/plotter/plotter.go | 72 +++++++++---------- pkg/store/store_test.go | 2 +- pkg/testcore/suites/functional-suites.go | 18 ++--- pkg/testcore/suites/perf-suites.go | 2 +- pkg/utils/k8s_utils.go | 10 +-- 16 files changed, 59 insertions(+), 94 deletions(-) diff --git a/pkg/k8sclient/resources/pod/pod.go b/pkg/k8sclient/resources/pod/pod.go index 48d0330..2eb3567 100644 --- a/pkg/k8sclient/resources/pod/pod.go +++ b/pkg/k8sclient/resources/pod/pod.go @@ -450,10 +450,7 @@ func (pod *Pod) Sync(ctx context.Context) *Pod { // HasError checks whether pod has any error func (pod *Pod) HasError() bool { - if pod.error != nil { - return true - } - return false + return pod.error != nil } // GetError returns pod error diff --git a/pkg/k8sclient/resources/pv/pv.go b/pkg/k8sclient/resources/pv/pv.go index d50c1d4..f38b6da 100644 --- a/pkg/k8sclient/resources/pv/pv.go +++ b/pkg/k8sclient/resources/pv/pv.go @@ -390,10 +390,7 @@ func (pv *PersistentVolume) Sync(ctx context.Context) *PersistentVolume { // HasError checks if PV contains error func (pv *PersistentVolume) HasError() bool { - if pv.error != nil { - return true - } - return false + return pv.error != nil } // GetError returns PV error diff --git a/pkg/k8sclient/resources/sc/sc.go b/pkg/k8sclient/resources/sc/sc.go index 0f4755b..990af75 100644 --- a/pkg/k8sclient/resources/sc/sc.go +++ b/pkg/k8sclient/resources/sc/sc.go @@ -113,10 +113,7 @@ func (c *Client) DuplicateStorageClass(name string, sourceSc *v1.StorageClass) * // HasError checks whether storage class has error func (sc *StorageClass) HasError() bool { - if sc.error != nil { - return true - } - return false + return sc.error != nil } // GetError returns storage class error diff --git a/pkg/k8sclient/resources/statefulset/sts.go b/pkg/k8sclient/resources/statefulset/sts.go index a69f9f4..af58e37 100644 --- a/pkg/k8sclient/resources/statefulset/sts.go +++ b/pkg/k8sclient/resources/statefulset/sts.go @@ -499,10 +499,7 @@ func (sts *StatefulSet) Sync(ctx context.Context) *StatefulSet { // HasError checks if statefulset contains error func (sts *StatefulSet) HasError() bool { - if sts.error != nil { - return true - } - return false + return sts.error != nil } // GetError returns statefulset error diff --git a/pkg/k8sclient/resources/volumegroupsnapshot/vgs.go b/pkg/k8sclient/resources/volumegroupsnapshot/vgs.go index e63f87d..e811d5b 100644 --- a/pkg/k8sclient/resources/volumegroupsnapshot/vgs.go +++ b/pkg/k8sclient/resources/volumegroupsnapshot/vgs.go @@ -192,10 +192,7 @@ func (vgs *VGS) Name() string { // HasError checks whether VGS has error func (vgs *VGS) HasError() bool { - if vgs.error != nil { - return true - } - return false + return vgs.error != nil } // GetError returns VGS error diff --git a/pkg/k8sclient/resources/volumesnapshot/v1/snap.go b/pkg/k8sclient/resources/volumesnapshot/v1/snap.go index a96f40f..e9128f7 100644 --- a/pkg/k8sclient/resources/volumesnapshot/v1/snap.go +++ b/pkg/k8sclient/resources/volumesnapshot/v1/snap.go @@ -262,10 +262,7 @@ func (snap *Snapshot) WaitForRunning(ctx context.Context) error { // HasError checks whether Snapshot has error func (snap *Snapshot) HasError() bool { - if snap.error != nil { - return true - } - return false + return snap.error != nil } // GetError returns snapshot error diff --git a/pkg/k8sclient/resources/volumesnapshot/v1beta1/snap.go b/pkg/k8sclient/resources/volumesnapshot/v1beta1/snap.go index dba151b..00a007f 100644 --- a/pkg/k8sclient/resources/volumesnapshot/v1beta1/snap.go +++ b/pkg/k8sclient/resources/volumesnapshot/v1beta1/snap.go @@ -261,10 +261,7 @@ func (snap *Snapshot) WaitForRunning(ctx context.Context) error { // HasError checks whether Snapshot has error func (snap *Snapshot) HasError() bool { - if snap.error != nil { - return true - } - return false + return snap.error != nil } // GetError returns snapshot error diff --git a/pkg/k8sclient/resources/volumesnapshotcontent/v1/content.go b/pkg/k8sclient/resources/volumesnapshotcontent/v1/content.go index e18819a..02b6d8a 100644 --- a/pkg/k8sclient/resources/volumesnapshotcontent/v1/content.go +++ b/pkg/k8sclient/resources/volumesnapshotcontent/v1/content.go @@ -193,10 +193,7 @@ func (cont *SnapshotContent) WaitForRunning(ctx context.Context) error { // HasError checks if snapshot content has error func (cont *SnapshotContent) HasError() bool { - if cont.error != nil { - return true - } - return false + return cont.error != nil } // GetError returns snapshot content error diff --git a/pkg/k8sclient/resources/volumesnapshotcontent/v1beta1/content.go b/pkg/k8sclient/resources/volumesnapshotcontent/v1beta1/content.go index 73e05c5..ad43bd7 100644 --- a/pkg/k8sclient/resources/volumesnapshotcontent/v1beta1/content.go +++ b/pkg/k8sclient/resources/volumesnapshotcontent/v1beta1/content.go @@ -191,10 +191,7 @@ func (cont *SnapshotContent) WaitForRunning(ctx context.Context) error { // HasError checks if snapshot content has error func (cont *SnapshotContent) HasError() bool { - if cont.error != nil { - return true - } - return false + return cont.error != nil } // GetError returns snapshot content error diff --git a/pkg/observer/va.go b/pkg/observer/va.go index 18c6728..a982a58 100644 --- a/pkg/observer/va.go +++ b/pkg/observer/va.go @@ -66,7 +66,7 @@ func (vao *VaObserver) StartWatching(_ context.Context, runner *Runner) { select { case <-vao.finished: // We can't finish if we haven't received all deletion events - if len(attachedVAs) == len(deletedVAs) || runner.ShouldClean == false { + if len(attachedVAs) == len(deletedVAs) || !runner.ShouldClean { err := runner.Database.SaveEvents(events) if err != nil { log.Errorf("Error saving events; error=%v", err) diff --git a/pkg/observer/va_alt.go b/pkg/observer/va_alt.go index e466339..89e3d8f 100644 --- a/pkg/observer/va_alt.go +++ b/pkg/observer/va_alt.go @@ -57,7 +57,7 @@ func (vao *VaListObserver) StartWatching(ctx context.Context, runner *Runner) { pollErr := wait.PollImmediate(500*time.Millisecond, time.Duration(timeout)*time.Second, func() (bool, error) { select { case <-vao.finished: - if len(attachedVAs) == len(deletedVAs) || runner.ShouldClean == false { + if len(attachedVAs) == len(deletedVAs) || !runner.ShouldClean { log.Debugf("%s finished watching", vao.GetName()) saveErr := runner.Database.SaveEvents(events) if saveErr != nil { diff --git a/pkg/plotter/plotter.go b/pkg/plotter/plotter.go index 0584ac9..29a2d7b 100644 --- a/pkg/plotter/plotter.go +++ b/pkg/plotter/plotter.go @@ -69,8 +69,7 @@ func GetReportPathDir(reportName string) (string, error) { // PlotStageMetricHistogram creates and saves a histogram of time distributions // +returns absolute filepath to created plot func PlotStageMetricHistogram(tc collector.TestCaseMetrics, stage interface{}, reportName string) (*plot.Plot, error) { - var metrics map[int]int - metrics = make(map[int]int) + metrics := make(map[int]int) var min int var max int @@ -90,14 +89,12 @@ func PlotStageMetricHistogram(tc collector.TestCaseMetrics, stage interface{}, r if isPvc { for _, pvcMetric := range tc.PVCs { - var value int - value = int(math.Round(pvcMetric.Metrics[pvcStage].Seconds())) + value := int(math.Round(pvcMetric.Metrics[pvcStage].Seconds())) metrics[value]++ } } else if isPod { for _, podMetric := range tc.Pods { - var value int - value = int(math.Round(podMetric.Metrics[podStage].Seconds())) + value := int(math.Round(podMetric.Metrics[podStage].Seconds())) metrics[value]++ } } else { @@ -117,8 +114,8 @@ func PlotStageMetricHistogram(tc collector.TestCaseMetrics, stage interface{}, r p := plot.New() if p == nil { - log.Errorf("Can't create new plot") - return nil, errors.New("Can't create new plot") + log.Errorf("can't create new plot") + return nil, errors.New("can't create new plot") } p.Title.Text = fmt.Sprintf("Distribution of %s times. Pods=%d, PVCs=%d", stage, len(tc.Pods), len(tc.PVCs)) @@ -132,7 +129,7 @@ func PlotStageMetricHistogram(tc collector.TestCaseMetrics, stage interface{}, r p.Add(barsBind) - filePath, err := GetReportPathDir(reportName) + filePath, _ := GetReportPathDir(reportName) filePath = fmt.Sprintf("%s/%s", filePath, tc.TestCase.Name+strconv.Itoa(int(tc.TestCase.ID))) _ = os.MkdirAll(filePath, 0o750) @@ -155,15 +152,13 @@ func PlotStageBoxPlot(tc collector.TestCaseMetrics, stage interface{}, reportNam if isPvc { values = make(plotter.Values, len(tc.PVCs)) for i, pvcMetric := range tc.PVCs { - var value float64 - value = pvcMetric.Metrics[pvcStage].Seconds() + value := pvcMetric.Metrics[pvcStage].Seconds() values[i] = value } } else if isPod { values = make(plotter.Values, len(tc.Pods)) for i, podMetric := range tc.Pods { - var value float64 - value = podMetric.Metrics[podStage].Seconds() + value := podMetric.Metrics[podStage].Seconds() values[i] = value } } else { @@ -174,8 +169,8 @@ func PlotStageBoxPlot(tc collector.TestCaseMetrics, stage interface{}, reportNam p := plot.New() if p == nil { - log.Errorf("Can't create new plot") - return nil, errors.New("Can't create new plot") + log.Errorf("can't create new plot") + return nil, errors.New("can't create new plot") } p.Title.Text = fmt.Sprintf("Box plot of %s times. Pods=%d, PVCs=%d", stage, len(tc.Pods), len(tc.PVCs)) p.Y.Label.Text = "times" @@ -188,7 +183,7 @@ func PlotStageBoxPlot(tc collector.TestCaseMetrics, stage interface{}, reportNam p.Add(boxPlot) - filePath, err := GetReportPathDir(reportName) + filePath, _ := GetReportPathDir(reportName) filePath = fmt.Sprintf("%s/%s", filePath, tc.TestCase.Name+strconv.Itoa(int(tc.TestCase.ID))) _ = os.MkdirAll(filePath, 0o750) @@ -256,10 +251,10 @@ func PlotEntityOverTime(tc collector.TestCaseMetrics, reportName string) (*plot. p := plot.New() if p == nil { - log.Errorf("Can't create new plot") - return nil, errors.New("Can't create new plot") + log.Errorf("can't create new plot") + return nil, errors.New("can't create new plot") } - p.Title.Text = fmt.Sprintf("EntityNumber over time") + p.Title.Text = "EntityNumber over time" p.Y.Label.Text = "number" p.X.Label.Text = "time" // Draw a grid behind the data @@ -411,13 +406,12 @@ func PlotEntityOverTime(tc collector.TestCaseMetrics, reportName string) (*plot. dc = draw.Crop(dc, 0, -legendWidth-vg.Millimeter, 0, 0) // Make space for the legend. p.Draw(dc) - filePath, err := GetReportPathDir(reportName) + filePath, _ := GetReportPathDir(reportName) filePath = fmt.Sprintf("%s/%s", filePath, tc.TestCase.Name+strconv.Itoa(int(tc.TestCase.ID))) _ = os.MkdirAll(filePath, 0o750) - var fileName string - fileName = fmt.Sprintf("%s.png", "EntityNumberOverTime") + fileName := fmt.Sprintf("%s.png", "EntityNumberOverTime") filePath = filepath.Join(filePath, fileName) w, err := os.Create(filepath.Clean(filePath)) @@ -585,8 +579,8 @@ func PlotIterationTimes(tcMetrics []collector.TestCaseMetrics, reportName string } p := plot.New() if p == nil { - log.Error("Can't create a new plot") - return nil, errors.New("Can't create new plot") + log.Error("can't create a new plot") + return nil, errors.New("can't create new plot") } p.Title.Text = "IterationTimes" @@ -599,11 +593,11 @@ func PlotIterationTimes(tcMetrics []collector.TestCaseMetrics, reportName string return nil, err } - filePath, err := GetReportPathDir(reportName) + filePath, _ := GetReportPathDir(reportName) _ = os.MkdirAll(filePath, 0o750) - filePath = filepath.Join(filePath, fmt.Sprintf("IterationTimes.png")) + filePath = filepath.Join(filePath, "IterationTimes.png") // Save the plot to a PNG file. if err := p.Save(6*vg.Inch, 4*vg.Inch, filePath); err != nil { @@ -651,8 +645,8 @@ func PlotAvgStageTimeOverIterations(tcMetrics []collector.TestCaseMetrics, repor p := plot.New() if p == nil { - log.Error("Can't create a new plot") - return errors.New("Can't create new plot") + log.Error("can't create a new plot") + return errors.New("can't create new plot") } p.Title.Text = fmt.Sprintf("Avg time of %s", name) p.Y.Label.Text = "time, s" @@ -668,10 +662,9 @@ func PlotAvgStageTimeOverIterations(tcMetrics []collector.TestCaseMetrics, repor p.Add(line) - filePath, err := GetReportPathDir(reportName) + filePath, _ := GetReportPathDir(reportName) _ = os.MkdirAll(filePath, 0o750) - var fileName string - fileName = fmt.Sprintf("%sOverIterations.png", name) + fileName := fmt.Sprintf("%sOverIterations.png", name) filePath = filepath.Join(filePath, fileName) if err := p.Save(8*vg.Inch, 4*vg.Inch, filePath); err != nil { @@ -685,10 +678,10 @@ func PlotAvgStageTimeOverIterations(tcMetrics []collector.TestCaseMetrics, repor func plotMemoryOrCPU(metrics map[string]plotter.XYs, reportName string, name string) error { p := plot.New() if p == nil { - log.Errorf("Can't create new plot") - return errors.New("Can't create new plot") + log.Errorf("can't create new plot") + return errors.New("can't create new plot") } - p.Title.Text = fmt.Sprintf(name) + p.Title.Text = name p.Y.Label.Text = "value" p.X.Label.Text = "time" // Draw a grid behind the data @@ -731,10 +724,9 @@ func plotMemoryOrCPU(metrics map[string]plotter.XYs, reportName string, name str // Make space for the legend. p.Draw(dc) - filePath, err := GetReportPathDir(reportName) + filePath, _ := GetReportPathDir(reportName) _ = os.MkdirAll(filePath, 0o750) - var fileName string - fileName = fmt.Sprintf("%s.png", name) + fileName := fmt.Sprintf("%s.png", name) filePath = filepath.Join(filePath, fileName) w, err := os.Create(filepath.Clean(filePath)) if err != nil { @@ -752,8 +744,8 @@ func plotMemoryOrCPU(metrics map[string]plotter.XYs, reportName string, name str func plotMinMax(minMetrics plotter.XYs, maxMetrics plotter.XYs, reportName string, name string) error { p := plot.New() if p == nil { - log.Errorf("Can't create new plot") - return errors.New("Can't create new plot") + log.Errorf("can't create new plot") + return errors.New("can't create new plot") } p.Title.Text = fmt.Sprintf("%s over time", name) p.Y.Label.Text = "number" @@ -815,7 +807,7 @@ func plotMinMax(minMetrics plotter.XYs, maxMetrics plotter.XYs, reportName strin // Make space for the legend. p.Draw(dc) - filePath, err := GetReportPathDir(reportName) + filePath, _ := GetReportPathDir(reportName) _ = os.MkdirAll(filePath, 0o750) diff --git a/pkg/store/store_test.go b/pkg/store/store_test.go index 5f838b3..b9109a5 100644 --- a/pkg/store/store_test.go +++ b/pkg/store/store_test.go @@ -157,7 +157,7 @@ func (suite *StoreTestSuite) TestAllStores() { suite.Equal(len(entities), 1, fmt.Sprintf("able to get entity relations using %s store", key)) suite.Equal(entities[0].Name, "pvc1", fmt.Sprintf("able to get entity name from relation using %s store", key)) - entities, err = store.GetEntities(Conditions{"type": Pvc}, "", 0) + entities, _ = store.GetEntities(Conditions{"type": Pvc}, "", 0) suite.Equal(len(entities), 1) nEntities := []*NumberEntities{ diff --git a/pkg/testcore/suites/functional-suites.go b/pkg/testcore/suites/functional-suites.go index 94ce8d1..851a4d1 100644 --- a/pkg/testcore/suites/functional-suites.go +++ b/pkg/testcore/suites/functional-suites.go @@ -110,7 +110,7 @@ func (vds *VolumeDeletionSuite) GetNamespace() string { // Parameters is returns format string func (vds *VolumeDeletionSuite) Parameters() string { - return fmt.Sprintf("{}") + return "{}" } // PodDeletionSuite is used for managing pod deletion test suite @@ -210,7 +210,7 @@ func (pds *PodDeletionSuite) GetNamespace() string { // Parameters returns format string func (pds *PodDeletionSuite) Parameters() string { - return fmt.Sprintf("{}") + return "{}" } // ClonedVolDeletionSuite is used to manage cloned volume deletion test suite @@ -330,7 +330,7 @@ func (pds *ClonedVolDeletionSuite) GetNamespace() string { // Parameters returns format string func (pds *ClonedVolDeletionSuite) Parameters() string { - return fmt.Sprintf("{}") + return "{}" } // SnapshotDeletionSuite is used for managing snapshot deletion test suite @@ -472,7 +472,7 @@ func (sds *SnapshotDeletionSuite) GetNamespace() string { // Parameters returns format string func (sds *SnapshotDeletionSuite) Parameters() string { - return fmt.Sprintf("{}") + return "{}" } // EphemeralVolumeSuite is used to manage ephemeral volume test suite @@ -638,10 +638,10 @@ func (nds *NodeDrainSuite) Run(ctx context.Context, _ string, clients *k8sclient log.Infof("Draining node with name:%s", color.YellowString(nds.Name)) nodeClient := clients.NodeClient - err := nodeClient.NodeCordon(ctx, nds.Name) + _ = nodeClient.NodeCordon(ctx, nds.Name) podClient := clients.PodClient - err = podClient.DeleteOrEvictPods(ctx, nds.Name, nds.GracePeriodSeconds) + err := podClient.DeleteOrEvictPods(ctx, nds.Name, nds.GracePeriodSeconds) if err != nil { return delFunc, err } @@ -730,7 +730,7 @@ func (nds *NodeDrainSuite) GetNamespace() string { // Parameters returns format string func (nds *NodeDrainSuite) Parameters() string { - return fmt.Sprintf("{}") + return "{}" } // NodeUncordonSuite is used to manage node uncordon test suite @@ -818,7 +818,7 @@ func (nds *NodeUncordonSuite) GetNamespace() string { // Parameters returns format string func (nds *NodeUncordonSuite) Parameters() string { - return fmt.Sprintf("{}") + return "{}" } // CapacityTrackingSuite is used to manage storage capacity tracking test suite @@ -935,7 +935,7 @@ func (cts *CapacityTrackingSuite) Run(ctx context.Context, storageClass string, } func getTopologyCount() (int, error) { - exe := []string{"bash", "-c", fmt.Sprintf("kubectl describe csinode | grep 'Topology Keys'")} + exe := []string{"bash", "-c", "kubectl describe csinode | grep 'Topology Keys'"} str, err := FindDriverLogs(exe) if err != nil { return 0, err diff --git a/pkg/testcore/suites/perf-suites.go b/pkg/testcore/suites/perf-suites.go index 88cce00..0779421 100644 --- a/pkg/testcore/suites/perf-suites.go +++ b/pkg/testcore/suites/perf-suites.go @@ -2722,7 +2722,7 @@ func (mas *MultiAttachSuite) Run(ctx context.Context, storageClass string, clien } } else { device := fmt.Sprintf("/dev%s0", podconf.MountPath) - file := fmt.Sprintf("/tmp/blob.data") + file := "/tmp/blob.data" hash := bytes.NewBufferString("") diff --git a/pkg/utils/k8s_utils.go b/pkg/utils/k8s_utils.go index 3bfce76..f3efd72 100644 --- a/pkg/utils/k8s_utils.go +++ b/pkg/utils/k8s_utils.go @@ -215,9 +215,9 @@ type DriverConfig struct { // ReadTestDriverConfig will read the driver config func ReadTestDriverConfig(driverconfig string) string { - file, err := os.ReadFile(filepath.Clean(driverconfig)) + file, _ := os.ReadFile(filepath.Clean(driverconfig)) var DriverConfig DriverConfig - err = yaml.Unmarshal(file, &DriverConfig) + err := yaml.Unmarshal(file, &DriverConfig) if err != nil { log.Errorf("Unable to read the driver config:%s", err.Error()) return "" @@ -234,9 +234,9 @@ func SkipTests(skipFile string) (string, error) { if skipFile == "" { skipFile = IgnoreFile } - file, err := os.ReadFile(filepath.Clean(skipFile)) + file, _ := os.ReadFile(filepath.Clean(skipFile)) var tests SkippedTests - err = yaml.Unmarshal(file, &tests) + err := yaml.Unmarshal(file, &tests) if err != nil { log.Errorf("YAML-Encoded error :%s", err) return "", err @@ -363,7 +363,7 @@ func ExecuteE2ECommand(args []string, ch chan os.Signal) error { // Execute the command cmdErr := cmd.Run() executionLogFile := defaultDir + executionLogFile + "_" + ReadTestDriverConfig(args[3]) + ".log" - err := os.Remove(filepath.Clean(executionLogFile)) + _ = os.Remove(filepath.Clean(executionLogFile)) f, err := os.Create(filepath.Clean(executionLogFile)) if err != nil { log.Errorf("Error in file operation: %s", err.Error())