diff --git a/.golangci.yaml b/.golangci.yaml index 433ae4616..3b889db04 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -31,9 +31,6 @@ linters: - linters: - staticcheck text: "QF1002:" # could use tagged switch on args[0] (staticcheck) - - linters: - - staticcheck - text: "QF1004:" # could use strings.ReplaceAll instead (staticcheck) - linters: - staticcheck text: "ST1008:" # error should be returned as the last argument (staticcheck) diff --git a/pkg/daemon/ceph/client/crush.go b/pkg/daemon/ceph/client/crush.go index 75bb6fc01..e8cf796a4 100644 --- a/pkg/daemon/ceph/client/crush.go +++ b/pkg/daemon/ceph/client/crush.go @@ -152,7 +152,7 @@ func GetCrushHostName(context *clusterd.Context, clusterInfo *ClusterInfo, osdID // NormalizeCrushName replaces . with - func NormalizeCrushName(name string) string { - return strings.Replace(name, ".", "-", -1) + return strings.ReplaceAll(name, ".", "-") } // Obtain the cluster-wide default crush root from the cluster spec diff --git a/pkg/operator/ceph/cluster/osd/deviceSet.go b/pkg/operator/ceph/cluster/osd/deviceSet.go index 5c53d4b73..f43728d2f 100644 --- a/pkg/operator/ceph/cluster/osd/deviceSet.go +++ b/pkg/operator/ceph/cluster/osd/deviceSet.go @@ -320,8 +320,8 @@ func legacyDeviceSetPVCID(deviceSetName string, setIndex int) string { // This is the new function that generates the labels // It includes the pvcTemplateName in it func deviceSetPVCID(deviceSetName, pvcTemplateName string, setIndex int) string { - cleanName := strings.Replace(pvcTemplateName, " ", "-", -1) - deviceSetName = strings.Replace(deviceSetName, ".", "-", -1) + cleanName := strings.ReplaceAll(pvcTemplateName, " ", "-") + deviceSetName = strings.ReplaceAll(deviceSetName, ".", "-") return fmt.Sprintf("%s-%s-%d", deviceSetName, cleanName, setIndex) } diff --git a/pkg/operator/ceph/config/config.go b/pkg/operator/ceph/config/config.go index 434585b5e..c8ffc3e2b 100644 --- a/pkg/operator/ceph/config/config.go +++ b/pkg/operator/ceph/config/config.go @@ -89,7 +89,7 @@ var ( // when they are specified as "some config key" in one section, "some_config_key" in another // section, and "some-config-key" in yet another section. func normalizeKey(key string) string { - return strings.Replace(strings.Replace(key, " ", "_", -1), "-", "_", -1) + return strings.ReplaceAll(strings.ReplaceAll(key, " ", "_"), "-", "_") } // NewFlag returns the key-value pair in the format of a Ceph command line-compatible flag. @@ -97,7 +97,7 @@ func NewFlag(key, value string) string { // A flag is a normalized key with underscores replaced by dashes. // "debug default" ~normalize~> "debug_default" ~to~flag~> "debug-default" n := normalizeKey(key) - f := strings.Replace(n, "_", "-", -1) + f := strings.ReplaceAll(n, "_", "-") return fmt.Sprintf("--%s=%s", f, value) } diff --git a/pkg/operator/ceph/file/mds/mds.go b/pkg/operator/ceph/file/mds/mds.go index 70fed99c5..15c07207c 100644 --- a/pkg/operator/ceph/file/mds/mds.go +++ b/pkg/operator/ceph/file/mds/mds.go @@ -354,7 +354,7 @@ func (c *Cluster) scaleDownDeployments(replicas int32, activeCount int32, desire logger.Errorf("failed to delete mds deployment. %v", err) } - daemonName := strings.Replace(d.GetName(), fmt.Sprintf("%s-", AppName), "", -1) + daemonName := strings.ReplaceAll(d.GetName(), fmt.Sprintf("%s-", AppName), "") err := c.DeleteMdsCephObjects(daemonName) if err != nil { logger.Errorf("%v", err) diff --git a/pkg/operator/ceph/object/config.go b/pkg/operator/ceph/object/config.go index 2e83f5ed0..ea4b23484 100644 --- a/pkg/operator/ceph/object/config.go +++ b/pkg/operator/ceph/object/config.go @@ -91,7 +91,7 @@ func (c *clusterConfig) portString() string { func generateCephXUser(name string) string { user := strings.TrimPrefix(name, AppName) - return "client.rgw" + strings.Replace(user, "-", ".", -1) + return "client.rgw" + strings.ReplaceAll(user, "-", ".") } func (c *clusterConfig) generateKeyring(rgwConfig *rgwConfig) (string, error) { diff --git a/pkg/operator/ceph/object/objectstore_test.go b/pkg/operator/ceph/object/objectstore_test.go index 76532f867..6e2bddf89 100644 --- a/pkg/operator/ceph/object/objectstore_test.go +++ b/pkg/operator/ceph/object/objectstore_test.go @@ -249,7 +249,7 @@ func TestConfigureStoreWithSharedPools(t *testing.T) { zoneGetCalled = true if sharedDataPoolAlreadySet == "" && sharedMetaPoolAlreadySet == "" { replaceDataPool := "rgw-data-pool:store-a.buckets.data" - return strings.Replace(objectZoneJson, replaceDataPool, "datapool:store-a.buckets.data", -1), nil + return strings.ReplaceAll(objectZoneJson, replaceDataPool, "datapool:store-a.buckets.data"), nil } return fmt.Sprintf(objectZoneSharedPoolsJsonTempl, sharedMetaPoolAlreadySet, sharedDataPoolAlreadySet), nil } else if args[1] == "set" { diff --git a/pkg/util/flags/flags.go b/pkg/util/flags/flags.go index d1441b855..7b37935dd 100644 --- a/pkg/util/flags/flags.go +++ b/pkg/util/flags/flags.go @@ -56,7 +56,7 @@ func SetFlagsFromEnv(flags *pflag.FlagSet, prefix string) { var errorFlag bool var err error flags.VisitAll(func(f *pflag.Flag) { - envVar := prefix + "_" + strings.Replace(strings.ToUpper(f.Name), "-", "_", -1) + envVar := prefix + "_" + strings.ReplaceAll(strings.ToUpper(f.Name), "-", "_") value := os.Getenv(envVar) if value != "" { // Set the environment variable. Will override default values, but be overridden by command line parameters. diff --git a/pkg/util/sys/device.go b/pkg/util/sys/device.go index 8158dd775..6831b3d29 100644 --- a/pkg/util/sys/device.go +++ b/pkg/util/sys/device.go @@ -376,7 +376,7 @@ func parseKeyValuePairString(propsRaw string) map[string]string { if len(kvp) == 2 { // first element is the final key, second element is the final value // (don't forget to remove surrounding quotes from the value) - propMap[kvp[0]] = strings.Replace(kvp[1], `"`, "", -1) + propMap[kvp[0]] = strings.ReplaceAll(kvp[1], `"`, "") } } diff --git a/tests/framework/utils/snapshot.go b/tests/framework/utils/snapshot.go index 2196ace52..99d6efec2 100644 --- a/tests/framework/utils/snapshot.go +++ b/tests/framework/utils/snapshot.go @@ -69,7 +69,7 @@ func (k8sh *K8sHelper) snapshotController(action string) error { if err != nil { return err } - controllerManifest = strings.Replace(controllerManifest, "canary", snapshotterVersion, -1) + controllerManifest = strings.ReplaceAll(controllerManifest, "canary", snapshotterVersion) logger.Infof("snapshot controller: %s", controllerManifest) _, err = k8sh.KubectlWithStdin(controllerManifest, action, "-f", "-") diff --git a/tests/integration/ceph_upgrade_test.go b/tests/integration/ceph_upgrade_test.go index 7fd081196..9927fad0f 100644 --- a/tests/integration/ceph_upgrade_test.go +++ b/tests/integration/ceph_upgrade_test.go @@ -313,7 +313,7 @@ func (s *UpgradeSuite) gatherLogs(systemNamespace, testSuffix string) { if installer.TestLogCollectionLevel() == "all" { s.k8sh.PrintPodDescribe(s.namespace) } - n := strings.Replace(s.T().Name(), "/", "_", -1) + testSuffix + n := strings.ReplaceAll(s.T().Name(), "/", "_") + testSuffix s.installer.GatherAllRookLogs(n, systemNamespace, s.namespace) }