From 24f270115289f9d541733b89c80bda68d35761e9 Mon Sep 17 00:00:00 2001 From: Peter Rifel Date: Fri, 22 Aug 2025 20:49:10 -0500 Subject: [PATCH] Use ReplaceAll --- cmd/kops/create_cluster.go | 2 +- cmd/kops/integration_test.go | 2 +- cmd/kops/lifecycle_integration_test.go | 2 +- .../clouddns/internal/managed_zones_service.go | 2 +- nodeup/pkg/model/kube_apiserver.go | 2 +- nodeup/pkg/model/kube_controller_manager.go | 2 +- pkg/assets/builder.go | 2 +- pkg/client/simple/api/clientset.go | 2 +- pkg/model/domodel/network.go | 2 +- pkg/model/master_volumes.go | 2 +- pkg/model/openstackmodel/network.go | 2 +- pkg/model/openstackmodel/servergroup.go | 14 +++++++------- pkg/resources/digitalocean/resources.go | 6 +++--- pkg/resources/openstack/network.go | 2 +- pkg/resources/openstack/sshkey.go | 4 ++-- pkg/testutils/golden/compare.go | 4 ++-- protokube/pkg/gossip/do/seeds.go | 2 +- protokube/pkg/protokube/do_volume.go | 4 ++-- tests/integration/conversion/integration_test.go | 4 ++-- .../fi/cloudup/awstasks/network_load_balancer.go | 2 +- upup/pkg/fi/cloudup/awstasks/sshkey.go | 4 ++-- upup/pkg/fi/cloudup/awsup/aws_utils.go | 2 +- upup/pkg/fi/cloudup/do/cloud.go | 6 +++--- upup/pkg/fi/cloudup/do/utils.go | 2 +- upup/pkg/fi/cloudup/dotasks/sshkey.go | 4 ++-- upup/pkg/fi/cloudup/gce/labels.go | 2 +- upup/pkg/fi/cloudup/gce/utils.go | 8 ++++---- upup/pkg/fi/cloudup/openstacktasks/servergroup.go | 2 +- upup/pkg/fi/cloudup/openstacktasks/sshkey.go | 4 ++-- upup/pkg/fi/cloudup/template_functions.go | 4 ++-- upup/pkg/fi/vfs_castore.go | 2 +- util/pkg/text/text.go | 2 +- 32 files changed, 53 insertions(+), 53 deletions(-) diff --git a/cmd/kops/create_cluster.go b/cmd/kops/create_cluster.go index 22ead7143a..aff448a7f9 100644 --- a/cmd/kops/create_cluster.go +++ b/cmd/kops/create_cluster.go @@ -858,7 +858,7 @@ func parseCloudLabels(s string) (map[string]string, error) { // Replace commas with newlines to allow a single pass with csv.Reader. // We can't use csv.Reader for the initial split because it would see each key=value record as a single field // and significantly complicates using quoted fields as keys or values. - records := strings.Replace(s, ",", "\n", -1) + records := strings.ReplaceAll(s, ",", "\n") // Let the CSV library do the heavy-lifting in handling nested ='s r := csv.NewReader(strings.NewReader(records)) diff --git a/cmd/kops/integration_test.go b/cmd/kops/integration_test.go index 2cc12e8d3d..c4dbd2b6aa 100644 --- a/cmd/kops/integration_test.go +++ b/cmd/kops/integration_test.go @@ -1605,7 +1605,7 @@ func (i *integrationTest) runTestTerraformAWS(t *testing.T) { "aws_cloudwatch_event_rule_" + awsup.GetClusterName40(i.clusterName) + "-SpotInterruption_event_pattern", "aws_cloudwatch_event_rule_" + awsup.GetClusterName40(i.clusterName) + "-InstanceStateChange_event_pattern", "aws_cloudwatch_event_rule_" + awsup.GetClusterName40(i.clusterName) + "-InstanceScheduledChange_event_pattern", - "aws_sqs_queue_" + strings.Replace(i.clusterName, ".", "-", -1) + "-nth_policy", + "aws_sqs_queue_" + strings.ReplaceAll(i.clusterName, ".", "-") + "-nth_policy", }...) } if i.nthRebalance { diff --git a/cmd/kops/lifecycle_integration_test.go b/cmd/kops/lifecycle_integration_test.go index 4198241c38..3242f44d79 100644 --- a/cmd/kops/lifecycle_integration_test.go +++ b/cmd/kops/lifecycle_integration_test.go @@ -56,7 +56,7 @@ func (o *LifecycleTestOptions) AddDefaults() { o.Version = "v1alpha2" } if o.ClusterName == "" { - o.ClusterName = strings.Replace(o.SrcDir, "_", "", -1) + ".example.com" + o.ClusterName = strings.ReplaceAll(o.SrcDir, "_", "") + ".example.com" } o.SrcDir = "../../tests/integration/update_cluster/" + o.SrcDir diff --git a/dnsprovider/pkg/dnsprovider/providers/google/clouddns/internal/managed_zones_service.go b/dnsprovider/pkg/dnsprovider/providers/google/clouddns/internal/managed_zones_service.go index a21daa2702..156f304d3f 100644 --- a/dnsprovider/pkg/dnsprovider/providers/google/clouddns/internal/managed_zones_service.go +++ b/dnsprovider/pkg/dnsprovider/providers/google/clouddns/internal/managed_zones_service.go @@ -46,6 +46,6 @@ func (m *ManagedZonesService) List(project string) interfaces.ManagedZonesListCa } func (m *ManagedZonesService) NewManagedZone(dnsName string) interfaces.ManagedZone { - name := "x" + strings.Replace(string(uuid.NewUUID()), "-", "", -1)[0:30] // Unique name, strip out the "-" chars to shorten it, start with a lower case alpha, and truncate to Cloud DNS 32 character limit + name := "x" + strings.ReplaceAll(string(uuid.NewUUID()), "-", "")[0:30] // Unique name, strip out the "-" chars to shorten it, start with a lower case alpha, and truncate to Cloud DNS 32 character limit return &ManagedZone{impl: &dns.ManagedZone{Name: name, Description: "Kubernetes Federated Service", DnsName: dnsName}} } diff --git a/nodeup/pkg/model/kube_apiserver.go b/nodeup/pkg/model/kube_apiserver.go index c3c99fb72b..3e28c6db01 100644 --- a/nodeup/pkg/model/kube_apiserver.go +++ b/nodeup/pkg/model/kube_apiserver.go @@ -795,7 +795,7 @@ func (b *KubeAPIServerBuilder) buildPod(ctx context.Context, kubeAPIServer *kops } for _, path := range b.SSLHostPaths() { - name := strings.Replace(path, "/", "", -1) + name := strings.ReplaceAll(path, "/", "") kubemanifest.AddHostPathMapping(pod, container, name, path) } diff --git a/nodeup/pkg/model/kube_controller_manager.go b/nodeup/pkg/model/kube_controller_manager.go index 0726f12a9c..412932460d 100644 --- a/nodeup/pkg/model/kube_controller_manager.go +++ b/nodeup/pkg/model/kube_controller_manager.go @@ -261,7 +261,7 @@ func (b *KubeControllerManagerBuilder) buildPod(kcm *kops.KubeControllerManagerC container.Args = append(container.Args, sortedStrings(flags)...) } for _, path := range b.SSLHostPaths() { - name := strings.Replace(path, "/", "", -1) + name := strings.ReplaceAll(path, "/", "") kubemanifest.AddHostPathMapping(pod, container, name, path) } diff --git a/pkg/assets/builder.go b/pkg/assets/builder.go index 0fd11d1a6f..ae7b9f4652 100644 --- a/pkg/assets/builder.go +++ b/pkg/assets/builder.go @@ -374,7 +374,7 @@ func NormalizeImage(a *AssetBuilder, image string) string { if !strings.HasPrefix(normalized, registryMirror+"/") { // We can't nest arbitrarily // Some risk of collisions, but also -- and __ in the names appear to be blocked by docker hub - normalized = strings.Replace(normalized, "/", "-", -1) + normalized = strings.ReplaceAll(normalized, "/", "-") normalized = registryMirror + "/" + normalized } image = normalized diff --git a/pkg/client/simple/api/clientset.go b/pkg/client/simple/api/clientset.go index 9ea74d191c..19330ee6e8 100644 --- a/pkg/client/simple/api/clientset.go +++ b/pkg/client/simple/api/clientset.go @@ -196,6 +196,6 @@ func restNamespaceForClusterName(clusterName string) string { // We are not allowed dots, so we map them to dashes // This can conflict, but this will simply be a limitation that we pass on to the user // i.e. it will not be possible to create a.b.example.com and a-b.example.com - namespace := strings.Replace(clusterName, ".", "-", -1) + namespace := strings.ReplaceAll(clusterName, ".", "-") return namespace } diff --git a/pkg/model/domodel/network.go b/pkg/model/domodel/network.go index 9384d32051..4b91c29eb8 100644 --- a/pkg/model/domodel/network.go +++ b/pkg/model/domodel/network.go @@ -39,7 +39,7 @@ func (b *NetworkModelBuilder) Build(c *fi.CloudupModelBuilderContext) error { return nil } - clusterName := strings.Replace(b.ClusterName(), ".", "-", -1) + clusterName := strings.ReplaceAll(b.ClusterName(), ".", "-") vpcName := "vpc-" + clusterName // Create a separate vpc for this cluster. diff --git a/pkg/model/master_volumes.go b/pkg/model/master_volumes.go index 119baee93a..587882c3ab 100644 --- a/pkg/model/master_volumes.go +++ b/pkg/model/master_volumes.go @@ -287,7 +287,7 @@ func (b *MasterVolumeBuilder) addGCEVolume(c *fi.CloudupModelBuilderContext, pre tags[gce.GceLabelNameEtcdClusterPrefix+etcd.Name] = gce.EncodeGCELabel(clusterSpec) // GCE disk names must match the following regular expression: '[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?' - prefix = strings.Replace(prefix, ".", "-", -1) + prefix = strings.ReplaceAll(prefix, ".", "-") if strings.IndexByte("0123456789-", prefix[0]) != -1 { prefix = "d" + prefix } diff --git a/pkg/model/openstackmodel/network.go b/pkg/model/openstackmodel/network.go index 29f8f05934..bed238315a 100644 --- a/pkg/model/openstackmodel/network.go +++ b/pkg/model/openstackmodel/network.go @@ -58,7 +58,7 @@ func (b *NetworkModelBuilder) Build(c *fi.CloudupModelBuilderContext) error { if osSpec.Router == nil || osSpec.Router.ExternalNetwork == nil { needRouter = false } - routerName := strings.Replace(clusterName, ".", "-", -1) + routerName := strings.ReplaceAll(clusterName, ".", "-") for _, sp := range b.Cluster.Spec.Networking.Subnets { // assumes that we do not need to create routers if we use existing subnets if sp.ID != "" { diff --git a/pkg/model/openstackmodel/servergroup.go b/pkg/model/openstackmodel/servergroup.go index 71df04841e..488c10aae6 100644 --- a/pkg/model/openstackmodel/servergroup.go +++ b/pkg/model/openstackmodel/servergroup.go @@ -88,7 +88,7 @@ func (b *ServerGroupModelBuilder) buildInstances(c *fi.CloudupModelBuilderContex return err } - sshKeyName := strings.Replace(sshKeyNameFull, ":", "_", -1) + sshKeyName := strings.ReplaceAll(sshKeyNameFull, ":", "_") igMeta := make(map[string]string) cloudTags, err := b.KopsModelContext.CloudTagsForInstanceGroup(ig) @@ -145,8 +145,8 @@ func (b *ServerGroupModelBuilder) buildInstances(c *fi.CloudupModelBuilderContex for i := int32(0); i < *ig.Spec.MinSize; i++ { // FIXME: Must ensure 63 or less characters // replace all dots and _ with -, this is needed to get external cloudprovider working - iName := strings.Replace(strings.ToLower(fmt.Sprintf("%s-%d.%s", ig.Name, i+1, b.ClusterName())), "_", "-", -1) - instanceName := fi.PtrTo(strings.Replace(iName, ".", "-", -1)) + iName := strings.ReplaceAll(strings.ToLower(fmt.Sprintf("%s-%d.%s", ig.Name, i+1, b.ClusterName())), "_", "-") + instanceName := fi.PtrTo(strings.ReplaceAll(iName, ".", "-")) var az *string var subnets []*openstacktasks.Subnet @@ -175,13 +175,13 @@ func (b *ServerGroupModelBuilder) buildInstances(c *fi.CloudupModelBuilderContex } // Create instance port task portName := fmt.Sprintf("%s-%s", "port", *instanceName) - portTagKopsName := strings.Replace( - strings.Replace( + portTagKopsName := strings.ReplaceAll( + strings.ReplaceAll( strings.ToLower( fmt.Sprintf("port-%s-%d", ig.Name, i+1), ), - "_", "-", -1, - ), ".", "-", -1, + "_", "-", + ), ".", "-", ) portTask := &openstacktasks.Port{ Name: fi.PtrTo(portName), diff --git a/pkg/resources/digitalocean/resources.go b/pkg/resources/digitalocean/resources.go index d9afb94630..e323199143 100644 --- a/pkg/resources/digitalocean/resources.go +++ b/pkg/resources/digitalocean/resources.go @@ -75,7 +75,7 @@ func listDroplets(cloud fi.Cloud, clusterName string) ([]*resources.Resource, er c := cloud.(do.DOCloud) var resourceTrackers []*resources.Resource - clusterTag := "KubernetesCluster:" + strings.Replace(clusterName, ".", "-", -1) + clusterTag := "KubernetesCluster:" + strings.ReplaceAll(clusterName, ".", "-") droplets, err := c.GetAllDropletsByTag(clusterTag) if err != nil { @@ -102,7 +102,7 @@ func listVolumes(cloud fi.Cloud, clusterName string) ([]*resources.Resource, err c := cloud.(do.DOCloud) var resourceTrackers []*resources.Resource - volumeMatch := strings.Replace(clusterName, ".", "-", -1) + volumeMatch := strings.ReplaceAll(clusterName, ".", "-") volumes, err := c.GetAllVolumesByRegion() if err != nil { @@ -220,7 +220,7 @@ func listLoadBalancers(cloud fi.Cloud, clusterName string) ([]*resources.Resourc c := cloud.(do.DOCloud) var resourceTrackers []*resources.Resource - clusterTag := "KubernetesCluster-Master:" + strings.Replace(clusterName, ".", "-", -1) + clusterTag := "KubernetesCluster-Master:" + strings.ReplaceAll(clusterName, ".", "-") lbs, err := c.GetAllLoadBalancers() if err != nil { diff --git a/pkg/resources/openstack/network.go b/pkg/resources/openstack/network.go index 7b5d74326c..732ce60fee 100644 --- a/pkg/resources/openstack/network.go +++ b/pkg/resources/openstack/network.go @@ -39,7 +39,7 @@ const ( func (os *clusterDiscoveryOS) ListNetwork() ([]*resources.Resource, error) { var resourceTrackers []*resources.Resource - routerName := strings.Replace(os.clusterName, ".", "-", -1) + routerName := strings.ReplaceAll(os.clusterName, ".", "-") projectNetworks, err := os.osCloud.ListNetworks(networks.ListOpts{}) if err != nil { diff --git a/pkg/resources/openstack/sshkey.go b/pkg/resources/openstack/sshkey.go index 0fb512b088..d500616fa2 100644 --- a/pkg/resources/openstack/sshkey.go +++ b/pkg/resources/openstack/sshkey.go @@ -29,8 +29,8 @@ const ( ) func openstackKeyPairName(org string) string { - name := strings.Replace(org, ".", "-", -1) - name = strings.Replace(name, ":", "_", -1) + name := strings.ReplaceAll(org, ".", "-") + name = strings.ReplaceAll(name, ":", "_") return name } diff --git a/pkg/testutils/golden/compare.go b/pkg/testutils/golden/compare.go index aa86406048..896024249f 100644 --- a/pkg/testutils/golden/compare.go +++ b/pkg/testutils/golden/compare.go @@ -53,8 +53,8 @@ func AssertMatchesFile(t *testing.T, actual string, p string) { expected := strings.TrimSpace(string(expectedBytes)) // on windows, with git set to autocrlf, the reference files on disk have windows line endings - expected = strings.Replace(expected, "\r\n", "\n", -1) - actual = strings.Replace(actual, "\r\n", "\n", -1) + expected = strings.ReplaceAll(expected, "\r\n", "\n") + actual = strings.ReplaceAll(actual, "\r\n", "\n") if actual == expected && err == nil { return diff --git a/protokube/pkg/gossip/do/seeds.go b/protokube/pkg/gossip/do/seeds.go index c288aa78c3..dd7c944176 100644 --- a/protokube/pkg/gossip/do/seeds.go +++ b/protokube/pkg/gossip/do/seeds.go @@ -44,7 +44,7 @@ func (p *SeedProvider) GetSeeds() ([]string, error) { for _, droplet := range droplets { for _, dropTag := range droplet.Tags { klog.V(4).Infof("Get Seeds - droplet found=%s,SeedProvider Tag=%s", dropTag, p.tag) - if strings.Contains(dropTag, strings.Replace(p.tag, ".", "-", -1)) { + if strings.Contains(dropTag, strings.ReplaceAll(p.tag, ".", "-")) { klog.V(4).Infof("Tag matched for droplet tag =%s. Getting private IP", p.tag) ip, err := droplet.PrivateIPv4() if err == nil { diff --git a/protokube/pkg/protokube/do_volume.go b/protokube/pkg/protokube/do_volume.go index 9d2c32a1cf..48af95f193 100644 --- a/protokube/pkg/protokube/do_volume.go +++ b/protokube/pkg/protokube/do_volume.go @@ -69,7 +69,7 @@ func GetClusterID() (string, error) { for _, dropletTag := range dropletTags { if strings.Contains(dropletTag, "KubernetesCluster:") { - clusterID = strings.Replace(dropletTag, ".", "-", -1) + clusterID = strings.ReplaceAll(dropletTag, ".", "-") tokens := strings.Split(clusterID, ":") if len(tokens) != 2 { @@ -181,7 +181,7 @@ func (d *DOCloudProvider) getEtcdClusterSpec(vol godo.Volume) (*etcd.EtcdCluster func (d *DOCloudProvider) GossipSeeds() (gossip.SeedProvider, error) { for _, dropletTag := range d.dropletTags { - if strings.Contains(dropletTag, strings.Replace(d.ClusterID, ".", "-", -1)) { + if strings.Contains(dropletTag, strings.ReplaceAll(d.ClusterID, ".", "-")) { return gossipdo.NewSeedProvider(d.godoClient, dropletTag) } } diff --git a/tests/integration/conversion/integration_test.go b/tests/integration/conversion/integration_test.go index a540549c4a..b768a7fa5b 100644 --- a/tests/integration/conversion/integration_test.go +++ b/tests/integration/conversion/integration_test.go @@ -132,8 +132,8 @@ func runTest(t *testing.T, srcDir string, fromVersion string, toVersion string) actualString := strings.TrimSpace(strings.Join(actual, "\n---\n\n")) expectedString := strings.TrimSpace(string(expectedBytes)) - actualString = strings.Replace(actualString, "\r", "", -1) - expectedString = strings.Replace(expectedString, "\r", "", -1) + actualString = strings.ReplaceAll(actualString, "\r", "") + expectedString = strings.ReplaceAll(expectedString, "\r", "") if actualString != expectedString { diffString := diff.FormatDiff(expectedString, actualString) diff --git a/upup/pkg/fi/cloudup/awstasks/network_load_balancer.go b/upup/pkg/fi/cloudup/awstasks/network_load_balancer.go index 84b7be45c7..c005c25763 100644 --- a/upup/pkg/fi/cloudup/awstasks/network_load_balancer.go +++ b/upup/pkg/fi/cloudup/awstasks/network_load_balancer.go @@ -689,7 +689,7 @@ func (_ *NetworkLoadBalancer) RenderTerraform(t *terraform.TerraformTarget, a, e } func (e *NetworkLoadBalancer) TerraformName() string { - tfName := strings.Replace(fi.ValueOf(e.Name), ".", "-", -1) + tfName := strings.ReplaceAll(fi.ValueOf(e.Name), ".", "-") return tfName } diff --git a/upup/pkg/fi/cloudup/awstasks/sshkey.go b/upup/pkg/fi/cloudup/awstasks/sshkey.go index 7ab194a6c8..a3bf99afac 100644 --- a/upup/pkg/fi/cloudup/awstasks/sshkey.go +++ b/upup/pkg/fi/cloudup/awstasks/sshkey.go @@ -197,7 +197,7 @@ func (_ *SSHKey) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SS if e.IsExistingKey() { return nil } - tfName := strings.Replace(*e.Name, ":", "", -1) + tfName := strings.ReplaceAll(*e.Name, ":", "") publicKey, err := t.AddFileResource("aws_key_pair", tfName, "public_key", e.PublicKey, false) if err != nil { return fmt.Errorf("error rendering PublicKey: %v", err) @@ -225,7 +225,7 @@ func (e *SSHKey) TerraformLink() *terraformWriter.Literal { if e.IsExistingKey() { return terraformWriter.LiteralFromStringValue(*e.Name) } - tfName := strings.Replace(*e.Name, ":", "", -1) + tfName := strings.ReplaceAll(*e.Name, ":", "") return terraformWriter.LiteralProperty("aws_key_pair", tfName, "id") } diff --git a/upup/pkg/fi/cloudup/awsup/aws_utils.go b/upup/pkg/fi/cloudup/awsup/aws_utils.go index 29e586ec81..4ecd738cd7 100644 --- a/upup/pkg/fi/cloudup/awsup/aws_utils.go +++ b/upup/pkg/fi/cloudup/awsup/aws_utils.go @@ -214,7 +214,7 @@ func GetClusterName40(cluster string) string { // GetResourceName32 will attempt to calculate a meaningful name for a resource given a prefix // Will never return a string longer than 32 chars func GetResourceName32(cluster string, prefix string) string { - s := prefix + "-" + strings.Replace(cluster, ".", "-", -1) + s := prefix + "-" + strings.ReplaceAll(cluster, ".", "-") // We always compute the hash and add it, lest we trick users into assuming that we never do this opt := truncate.TruncateStringOptions{ diff --git a/upup/pkg/fi/cloudup/do/cloud.go b/upup/pkg/fi/cloudup/do/cloud.go index 5e5e670a8a..b06887fa72 100644 --- a/upup/pkg/fi/cloudup/do/cloud.go +++ b/upup/pkg/fi/cloudup/do/cloud.go @@ -295,7 +295,7 @@ func (c *doCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([]fi return false, fmt.Errorf("LoadBalancers.List returned error: %v", err) } - lbName := "api-" + strings.Replace(cluster.Name, ".", "-", -1) + lbName := "api-" + strings.ReplaceAll(cluster.Name, ".", "-") for _, lb := range loadBalancers { if lb.Name == lbName { @@ -352,7 +352,7 @@ func findEtcdStatus(c *doCloudImplementation, cluster *kops.Cluster) ([]kops.Etc klog.V(8).Infof("findEtcdStatus status (from cloud): checking if volume with tag %q belongs to cluster", myTag) // check if volume belongs to this cluster. // tag will be in the format "KubernetesCluster:dev5-k8s-local" (where clusterName is dev5.k8s.local) - clusterName := strings.Replace(cluster.Name, ".", "-", -1) + clusterName := strings.ReplaceAll(cluster.Name, ".", "-") if strings.Contains(myTag, fmt.Sprintf("%s:%s", TagKubernetesClusterNamePrefix, clusterName)) { klog.V(10).Infof("findEtcdStatus cluster comparison matched for tag: %v", myTag) // this volume belongs to our cluster, add this to our etcdClusterSpec. @@ -453,7 +453,7 @@ func findInstanceGroups(c *doCloudImplementation, clusterName string) ([]DOInsta var result []DOInstanceGroup instanceGroupMap := make(map[string][]string) // map of instance group name with droplet ids - clusterTag := "KubernetesCluster:" + strings.Replace(clusterName, ".", "-", -1) + clusterTag := "KubernetesCluster:" + strings.ReplaceAll(clusterName, ".", "-") droplets, err := c.GetAllDropletsByTag(clusterTag) if err != nil { return nil, fmt.Errorf("get all droplets for tag %s returned error. Error=%v", clusterTag, err) diff --git a/upup/pkg/fi/cloudup/do/utils.go b/upup/pkg/fi/cloudup/do/utils.go index 31c9c53e12..839ee14f67 100644 --- a/upup/pkg/fi/cloudup/do/utils.go +++ b/upup/pkg/fi/cloudup/do/utils.go @@ -20,6 +20,6 @@ import "strings" func SafeClusterName(clusterName string) string { // DO does not support . in tags / names - safeClusterName := strings.Replace(clusterName, ".", "-", -1) + safeClusterName := strings.ReplaceAll(clusterName, ".", "-") return safeClusterName } diff --git a/upup/pkg/fi/cloudup/dotasks/sshkey.go b/upup/pkg/fi/cloudup/dotasks/sshkey.go index e1c9e9600f..4751bed13e 100644 --- a/upup/pkg/fi/cloudup/dotasks/sshkey.go +++ b/upup/pkg/fi/cloudup/dotasks/sshkey.go @@ -171,7 +171,7 @@ func (_ *SSHKey) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SS if e.IsExistingKey() { return nil } - tfName := strings.Replace(*e.Name, ":", "", -1) + tfName := strings.ReplaceAll(*e.Name, ":", "") publicKey, err := t.AddFileResource("digitalocean_ssh_key", tfName, "public_key", e.PublicKey, false) if err != nil { return fmt.Errorf("error rendering PublicKey: %v", err) @@ -198,7 +198,7 @@ func (e *SSHKey) TerraformLink() *terraformWriter.Literal { if e.IsExistingKey() { return terraformWriter.LiteralFromStringValue(*e.Name) } - tfName := strings.Replace(*e.Name, ":", "", -1) + tfName := strings.ReplaceAll(*e.Name, ":", "") return terraformWriter.LiteralProperty("digitalocean_ssh_key", tfName, "id") } diff --git a/upup/pkg/fi/cloudup/gce/labels.go b/upup/pkg/fi/cloudup/gce/labels.go index 48e249b0d9..2144903246 100644 --- a/upup/pkg/fi/cloudup/gce/labels.go +++ b/upup/pkg/fi/cloudup/gce/labels.go @@ -58,7 +58,7 @@ func EncodeGCELabel(s string) string { // DecodeGCELabel reverse EncodeGCELabel, taking the encoded RFC1035 compatible value back to a string func DecodeGCELabel(s string) (string, error) { - uriForm := strings.Replace(s, "-", "%", -1) + uriForm := strings.ReplaceAll(s, "-", "%") v, err := url.QueryUnescape(uriForm) if err != nil { return "", fmt.Errorf("cannot decode GCE label: %q", s) diff --git a/upup/pkg/fi/cloudup/gce/utils.go b/upup/pkg/fi/cloudup/gce/utils.go index c59cb797b7..a889fc02d2 100644 --- a/upup/pkg/fi/cloudup/gce/utils.go +++ b/upup/pkg/fi/cloudup/gce/utils.go @@ -58,7 +58,7 @@ func ClusterPrefixedName(objectName string, clusterName string, maxLength int) s } // GCE does not support . in tags / names - safeClusterName := strings.Replace(clusterName, ".", "-", -1) + safeClusterName := strings.ReplaceAll(clusterName, ".", "-") opt := truncate.TruncateStringOptions{ MaxLength: prefixLength, @@ -79,7 +79,7 @@ func ClusterSuffixedName(objectName string, clusterName string, maxLength int) s } // GCE does not support . in tags / names - safeClusterName := strings.Replace(clusterName, ".", "-", -1) + safeClusterName := strings.ReplaceAll(clusterName, ".", "-") opt := truncate.TruncateStringOptions{ MaxLength: suffixLength, @@ -95,7 +95,7 @@ func ClusterSuffixedName(objectName string, clusterName string, maxLength int) s // deprecated: prefer ClusterSuffixedName func SafeClusterName(clusterName string) string { // GCE does not support . in tags / names - safeClusterName := strings.Replace(clusterName, ".", "-", -1) + safeClusterName := strings.ReplaceAll(clusterName, ".", "-") return safeClusterName } @@ -113,7 +113,7 @@ func LabelForCluster(clusterName string) Label { // SafeTruncatedClusterName returns a safe and truncated cluster name func SafeTruncatedClusterName(clusterName string, maxLength int) string { // GCE does not support . in tags / names - safeClusterName := strings.Replace(clusterName, ".", "-", -1) + safeClusterName := strings.ReplaceAll(clusterName, ".", "-") opt := truncate.TruncateStringOptions{ MaxLength: maxLength, diff --git a/upup/pkg/fi/cloudup/openstacktasks/servergroup.go b/upup/pkg/fi/cloudup/openstacktasks/servergroup.go index a74cd64642..efd9bcdef1 100644 --- a/upup/pkg/fi/cloudup/openstacktasks/servergroup.go +++ b/upup/pkg/fi/cloudup/openstacktasks/servergroup.go @@ -163,7 +163,7 @@ func (_ *ServerGroup) RenderOpenstack(t *openstack.OpenstackAPITarget, a, e, cha for currentLastIndex > fi.ValueOf(maxSize) { iName := strings.ToLower(fmt.Sprintf("%s-%d.%s", igName, currentLastIndex, fi.ValueOf(a.ClusterName))) - instanceName := strings.Replace(iName, ".", "-", -1) + instanceName := strings.ReplaceAll(iName, ".", "-") opts := servers.ListOpts{ Name: fmt.Sprintf("^%s", igName), } diff --git a/upup/pkg/fi/cloudup/openstacktasks/sshkey.go b/upup/pkg/fi/cloudup/openstacktasks/sshkey.go index d07d77bcdc..1eba4cca7e 100644 --- a/upup/pkg/fi/cloudup/openstacktasks/sshkey.go +++ b/upup/pkg/fi/cloudup/openstacktasks/sshkey.go @@ -108,8 +108,8 @@ func (s *SSHKey) CheckChanges(a, e, changes *SSHKey) error { } func openstackKeyPairName(org string) string { - name := strings.Replace(org, ".", "-", -1) - name = strings.Replace(name, ":", "_", -1) + name := strings.ReplaceAll(org, ".", "-") + name = strings.ReplaceAll(name, ":", "_") return name } diff --git a/upup/pkg/fi/cloudup/template_functions.go b/upup/pkg/fi/cloudup/template_functions.go index 43f13cdd98..32627fdde4 100644 --- a/upup/pkg/fi/cloudup/template_functions.go +++ b/upup/pkg/fi/cloudup/template_functions.go @@ -95,7 +95,7 @@ func (tf *TemplateFunctions) AddTo(dest template.FuncMap, secretStore fi.SecretS dest["SharedVPC"] = tf.SharedVPC // Remember that we may be on a different arch from the target. Hard-code for now. dest["replace"] = func(s, find, replace string) string { - return strings.Replace(s, find, replace, -1) + return strings.ReplaceAll(s, find, replace) } dest["joinHostPort"] = net.JoinHostPort @@ -380,7 +380,7 @@ func (tf *TemplateFunctions) AddTo(dest template.FuncMap, secretStore fi.SecretS if cluster.Spec.CloudProvider.AWS != nil && cluster.Spec.CloudProvider.AWS.NodeTerminationHandler != nil { dest["DefaultQueueName"] = func() string { - s := strings.Replace(tf.ClusterName(), ".", "-", -1) + s := strings.ReplaceAll(tf.ClusterName(), ".", "-") domain := ".amazonaws.com/" if strings.Contains(tf.Region, "cn-") { domain = ".amazonaws.com.cn/" diff --git a/upup/pkg/fi/vfs_castore.go b/upup/pkg/fi/vfs_castore.go index 44fb8f1579..a4c4d815bc 100644 --- a/upup/pkg/fi/vfs_castore.go +++ b/upup/pkg/fi/vfs_castore.go @@ -302,7 +302,7 @@ func (c *VFSCAStore) AddSSHPublicKey(ctx context.Context, pubkey []byte) error { func (c *VFSCAStore) buildSSHPublicKeyPath(id string) vfs.Path { // id is fingerprint with colons, but we store without colons - id = strings.Replace(id, ":", "", -1) + id = strings.ReplaceAll(id, ":", "") return c.basedir.Join("ssh", "public", "admin", id) } diff --git a/util/pkg/text/text.go b/util/pkg/text/text.go index d6ae4d5e6f..ab17a85868 100644 --- a/util/pkg/text/text.go +++ b/util/pkg/text/text.go @@ -23,7 +23,7 @@ import ( // SplitContentToSections splits content of a kops manifest into sections. func SplitContentToSections(content []byte) [][]byte { // replace windows line endings with unix ones - normalized := bytes.Replace(content, []byte("\r\n"), []byte("\n"), -1) + normalized := bytes.ReplaceAll(content, []byte("\r\n"), []byte("\n")) return bytes.Split(normalized, []byte("\n---\n")) }