From 53c94efc02b9467c4316c686bf4946ef19bd7a10 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Fri, 2 Jun 2023 11:29:35 +0200 Subject: [PATCH] build: address `gocritic` warnings Signed-off-by: Niels de Vos --- internal/nfs/nodeserver/nodeserver.go | 2 +- internal/rbd/rbd_util_test.go | 2 +- internal/util/crushlocation.go | 2 +- internal/util/log/log_utils.go | 2 +- internal/util/log/log_utils_test.go | 2 +- internal/util/topology.go | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/nfs/nodeserver/nodeserver.go b/internal/nfs/nodeserver/nodeserver.go index c4e7ca845..7d49fdc39 100644 --- a/internal/nfs/nodeserver/nodeserver.go +++ b/internal/nfs/nodeserver/nodeserver.go @@ -232,7 +232,7 @@ func (ns *NodeServer) mountNFS( volumeID, source, mountPoint, mountOptions) if netNamespaceFilePath != "" { _, stderr, err = util.ExecuteCommandWithNSEnter( - ctx, netNamespaceFilePath, "mount", args[:]...) + ctx, netNamespaceFilePath, "mount", args...) } else { err = ns.Mounter.Mount(source, mountPoint, "nfs", mountOptions) } diff --git a/internal/rbd/rbd_util_test.go b/internal/rbd/rbd_util_test.go index bd9dbcd53..b707af713 100644 --- a/internal/rbd/rbd_util_test.go +++ b/internal/rbd/rbd_util_test.go @@ -297,7 +297,7 @@ func TestStrategicActionOnLogFile(t *testing.T) { var err error switch tt.args.logStrategy { case "compress": - newExt := strings.Replace(tt.args.logFile, ".log", ".gz", -1) + newExt := strings.ReplaceAll(tt.args.logFile, ".log", ".gz") if _, err = os.Stat(newExt); os.IsNotExist(err) { t.Errorf("compressed logFile (%s) not found: %v", newExt, err) } diff --git a/internal/util/crushlocation.go b/internal/util/crushlocation.go index f7cfc6302..5f3751c33 100644 --- a/internal/util/crushlocation.go +++ b/internal/util/crushlocation.go @@ -64,7 +64,7 @@ func getCrushLocationMap(crushLocationLabels string, nodeLabels map[string]strin crushLocationType = "host" } // replace "." with "-" to satisfy ceph crush map. - value = strings.Replace(strings.TrimSpace(value), ".", "-", -1) + value = strings.ReplaceAll(strings.TrimSpace(value), ".", "-") crushLocationMap[crushLocationType] = value } diff --git a/internal/util/log/log_utils.go b/internal/util/log/log_utils.go index d78d96e63..4e6cd9671 100644 --- a/internal/util/log/log_utils.go +++ b/internal/util/log/log_utils.go @@ -29,7 +29,7 @@ func GzipLogFile(pathToFile string) error { } // Replace .log extension with .gz extension. - newExt := strings.Replace(pathToFile, ".log", ".gz", -1) + newExt := strings.ReplaceAll(pathToFile, ".log", ".gz") // Open file for writing. gf, err := os.OpenFile(newExt, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0o644) // #nosec:G304,G302, file inclusion & perms diff --git a/internal/util/log/log_utils_test.go b/internal/util/log/log_utils_test.go index c7a3d0166..11467d2dc 100644 --- a/internal/util/log/log_utils_test.go +++ b/internal/util/log/log_utils_test.go @@ -37,7 +37,7 @@ func TestGzipLogFile(t *testing.T) { t.Errorf("GzipLogFile failed: %v", err) } - newExt := strings.Replace(logFile.Name(), ".log", ".gz", -1) + newExt := strings.ReplaceAll(logFile.Name(), ".log", ".gz") if _, err = os.Stat(newExt); errors.Is(err, os.ErrNotExist) { t.Errorf("compressed logFile (%s) not found: %v", newExt, err) } diff --git a/internal/util/topology.go b/internal/util/topology.go index c6d53e111..be99dbbe1 100644 --- a/internal/util/topology.go +++ b/internal/util/topology.go @@ -66,7 +66,7 @@ func GetTopologyFromDomainLabels(domainLabels, nodeName, driverName string) (map // driverName is validated, and we are adding a lowercase "topology." to it, so no validation for conformance // Convert passed in labels to a map, and check for uniqueness - labelsToRead := strings.SplitN(domainLabels, labelSeparator, -1) + labelsToRead := strings.Split(domainLabels, labelSeparator) log.DefaultLog("passed in node labels for processing: %+v", labelsToRead) labelsIn := make(map[string]bool) @@ -158,7 +158,7 @@ func GetTopologyFromRequest( } // extract topology based pools configuration - err := json.Unmarshal([]byte(strings.Replace(topologyPoolsStr, "\n", " ", -1)), &topologyPools) + err := json.Unmarshal([]byte(strings.ReplaceAll(topologyPoolsStr, "\n", " ")), &topologyPools) if err != nil { return nil, nil, fmt.Errorf( "failed to parse JSON encoded topology constrained pools parameter (%s): %w",