Use ReplaceAll

This commit is contained in:
Peter Rifel 2025-08-22 20:49:10 -05:00
parent 05099d65d3
commit 24f2701152
No known key found for this signature in database
32 changed files with 53 additions and 53 deletions

View File

@ -858,7 +858,7 @@ func parseCloudLabels(s string) (map[string]string, error) {
// Replace commas with newlines to allow a single pass with csv.Reader. // 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 // 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. // 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 // Let the CSV library do the heavy-lifting in handling nested ='s
r := csv.NewReader(strings.NewReader(records)) r := csv.NewReader(strings.NewReader(records))

View File

@ -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) + "-SpotInterruption_event_pattern",
"aws_cloudwatch_event_rule_" + awsup.GetClusterName40(i.clusterName) + "-InstanceStateChange_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_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 { if i.nthRebalance {

View File

@ -56,7 +56,7 @@ func (o *LifecycleTestOptions) AddDefaults() {
o.Version = "v1alpha2" o.Version = "v1alpha2"
} }
if o.ClusterName == "" { 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 o.SrcDir = "../../tests/integration/update_cluster/" + o.SrcDir

View File

@ -46,6 +46,6 @@ func (m *ManagedZonesService) List(project string) interfaces.ManagedZonesListCa
} }
func (m *ManagedZonesService) NewManagedZone(dnsName string) interfaces.ManagedZone { 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}} return &ManagedZone{impl: &dns.ManagedZone{Name: name, Description: "Kubernetes Federated Service", DnsName: dnsName}}
} }

View File

@ -795,7 +795,7 @@ func (b *KubeAPIServerBuilder) buildPod(ctx context.Context, kubeAPIServer *kops
} }
for _, path := range b.SSLHostPaths() { for _, path := range b.SSLHostPaths() {
name := strings.Replace(path, "/", "", -1) name := strings.ReplaceAll(path, "/", "")
kubemanifest.AddHostPathMapping(pod, container, name, path) kubemanifest.AddHostPathMapping(pod, container, name, path)
} }

View File

@ -261,7 +261,7 @@ func (b *KubeControllerManagerBuilder) buildPod(kcm *kops.KubeControllerManagerC
container.Args = append(container.Args, sortedStrings(flags)...) container.Args = append(container.Args, sortedStrings(flags)...)
} }
for _, path := range b.SSLHostPaths() { for _, path := range b.SSLHostPaths() {
name := strings.Replace(path, "/", "", -1) name := strings.ReplaceAll(path, "/", "")
kubemanifest.AddHostPathMapping(pod, container, name, path) kubemanifest.AddHostPathMapping(pod, container, name, path)
} }

View File

@ -374,7 +374,7 @@ func NormalizeImage(a *AssetBuilder, image string) string {
if !strings.HasPrefix(normalized, registryMirror+"/") { if !strings.HasPrefix(normalized, registryMirror+"/") {
// We can't nest arbitrarily // We can't nest arbitrarily
// Some risk of collisions, but also -- and __ in the names appear to be blocked by docker hub // 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 normalized = registryMirror + "/" + normalized
} }
image = normalized image = normalized

View File

@ -196,6 +196,6 @@ func restNamespaceForClusterName(clusterName string) string {
// We are not allowed dots, so we map them to dashes // 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 // 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 // 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 return namespace
} }

View File

@ -39,7 +39,7 @@ func (b *NetworkModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
return nil return nil
} }
clusterName := strings.Replace(b.ClusterName(), ".", "-", -1) clusterName := strings.ReplaceAll(b.ClusterName(), ".", "-")
vpcName := "vpc-" + clusterName vpcName := "vpc-" + clusterName
// Create a separate vpc for this cluster. // Create a separate vpc for this cluster.

View File

@ -287,7 +287,7 @@ func (b *MasterVolumeBuilder) addGCEVolume(c *fi.CloudupModelBuilderContext, pre
tags[gce.GceLabelNameEtcdClusterPrefix+etcd.Name] = gce.EncodeGCELabel(clusterSpec) 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])?' // 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 { if strings.IndexByte("0123456789-", prefix[0]) != -1 {
prefix = "d" + prefix prefix = "d" + prefix
} }

View File

@ -58,7 +58,7 @@ func (b *NetworkModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
if osSpec.Router == nil || osSpec.Router.ExternalNetwork == nil { if osSpec.Router == nil || osSpec.Router.ExternalNetwork == nil {
needRouter = false needRouter = false
} }
routerName := strings.Replace(clusterName, ".", "-", -1) routerName := strings.ReplaceAll(clusterName, ".", "-")
for _, sp := range b.Cluster.Spec.Networking.Subnets { for _, sp := range b.Cluster.Spec.Networking.Subnets {
// assumes that we do not need to create routers if we use existing subnets // assumes that we do not need to create routers if we use existing subnets
if sp.ID != "" { if sp.ID != "" {

View File

@ -88,7 +88,7 @@ func (b *ServerGroupModelBuilder) buildInstances(c *fi.CloudupModelBuilderContex
return err return err
} }
sshKeyName := strings.Replace(sshKeyNameFull, ":", "_", -1) sshKeyName := strings.ReplaceAll(sshKeyNameFull, ":", "_")
igMeta := make(map[string]string) igMeta := make(map[string]string)
cloudTags, err := b.KopsModelContext.CloudTagsForInstanceGroup(ig) 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++ { for i := int32(0); i < *ig.Spec.MinSize; i++ {
// FIXME: Must ensure 63 or less characters // FIXME: Must ensure 63 or less characters
// replace all dots and _ with -, this is needed to get external cloudprovider working // 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) iName := strings.ReplaceAll(strings.ToLower(fmt.Sprintf("%s-%d.%s", ig.Name, i+1, b.ClusterName())), "_", "-")
instanceName := fi.PtrTo(strings.Replace(iName, ".", "-", -1)) instanceName := fi.PtrTo(strings.ReplaceAll(iName, ".", "-"))
var az *string var az *string
var subnets []*openstacktasks.Subnet var subnets []*openstacktasks.Subnet
@ -175,13 +175,13 @@ func (b *ServerGroupModelBuilder) buildInstances(c *fi.CloudupModelBuilderContex
} }
// Create instance port task // Create instance port task
portName := fmt.Sprintf("%s-%s", "port", *instanceName) portName := fmt.Sprintf("%s-%s", "port", *instanceName)
portTagKopsName := strings.Replace( portTagKopsName := strings.ReplaceAll(
strings.Replace( strings.ReplaceAll(
strings.ToLower( strings.ToLower(
fmt.Sprintf("port-%s-%d", ig.Name, i+1), fmt.Sprintf("port-%s-%d", ig.Name, i+1),
), ),
"_", "-", -1, "_", "-",
), ".", "-", -1, ), ".", "-",
) )
portTask := &openstacktasks.Port{ portTask := &openstacktasks.Port{
Name: fi.PtrTo(portName), Name: fi.PtrTo(portName),

View File

@ -75,7 +75,7 @@ func listDroplets(cloud fi.Cloud, clusterName string) ([]*resources.Resource, er
c := cloud.(do.DOCloud) c := cloud.(do.DOCloud)
var resourceTrackers []*resources.Resource var resourceTrackers []*resources.Resource
clusterTag := "KubernetesCluster:" + strings.Replace(clusterName, ".", "-", -1) clusterTag := "KubernetesCluster:" + strings.ReplaceAll(clusterName, ".", "-")
droplets, err := c.GetAllDropletsByTag(clusterTag) droplets, err := c.GetAllDropletsByTag(clusterTag)
if err != nil { if err != nil {
@ -102,7 +102,7 @@ func listVolumes(cloud fi.Cloud, clusterName string) ([]*resources.Resource, err
c := cloud.(do.DOCloud) c := cloud.(do.DOCloud)
var resourceTrackers []*resources.Resource var resourceTrackers []*resources.Resource
volumeMatch := strings.Replace(clusterName, ".", "-", -1) volumeMatch := strings.ReplaceAll(clusterName, ".", "-")
volumes, err := c.GetAllVolumesByRegion() volumes, err := c.GetAllVolumesByRegion()
if err != nil { if err != nil {
@ -220,7 +220,7 @@ func listLoadBalancers(cloud fi.Cloud, clusterName string) ([]*resources.Resourc
c := cloud.(do.DOCloud) c := cloud.(do.DOCloud)
var resourceTrackers []*resources.Resource var resourceTrackers []*resources.Resource
clusterTag := "KubernetesCluster-Master:" + strings.Replace(clusterName, ".", "-", -1) clusterTag := "KubernetesCluster-Master:" + strings.ReplaceAll(clusterName, ".", "-")
lbs, err := c.GetAllLoadBalancers() lbs, err := c.GetAllLoadBalancers()
if err != nil { if err != nil {

View File

@ -39,7 +39,7 @@ const (
func (os *clusterDiscoveryOS) ListNetwork() ([]*resources.Resource, error) { func (os *clusterDiscoveryOS) ListNetwork() ([]*resources.Resource, error) {
var resourceTrackers []*resources.Resource var resourceTrackers []*resources.Resource
routerName := strings.Replace(os.clusterName, ".", "-", -1) routerName := strings.ReplaceAll(os.clusterName, ".", "-")
projectNetworks, err := os.osCloud.ListNetworks(networks.ListOpts{}) projectNetworks, err := os.osCloud.ListNetworks(networks.ListOpts{})
if err != nil { if err != nil {

View File

@ -29,8 +29,8 @@ const (
) )
func openstackKeyPairName(org string) string { func openstackKeyPairName(org string) string {
name := strings.Replace(org, ".", "-", -1) name := strings.ReplaceAll(org, ".", "-")
name = strings.Replace(name, ":", "_", -1) name = strings.ReplaceAll(name, ":", "_")
return name return name
} }

View File

@ -53,8 +53,8 @@ func AssertMatchesFile(t *testing.T, actual string, p string) {
expected := strings.TrimSpace(string(expectedBytes)) expected := strings.TrimSpace(string(expectedBytes))
// on windows, with git set to autocrlf, the reference files on disk have windows line endings // on windows, with git set to autocrlf, the reference files on disk have windows line endings
expected = strings.Replace(expected, "\r\n", "\n", -1) expected = strings.ReplaceAll(expected, "\r\n", "\n")
actual = strings.Replace(actual, "\r\n", "\n", -1) actual = strings.ReplaceAll(actual, "\r\n", "\n")
if actual == expected && err == nil { if actual == expected && err == nil {
return return

View File

@ -44,7 +44,7 @@ func (p *SeedProvider) GetSeeds() ([]string, error) {
for _, droplet := range droplets { for _, droplet := range droplets {
for _, dropTag := range droplet.Tags { for _, dropTag := range droplet.Tags {
klog.V(4).Infof("Get Seeds - droplet found=%s,SeedProvider Tag=%s", dropTag, p.tag) 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) klog.V(4).Infof("Tag matched for droplet tag =%s. Getting private IP", p.tag)
ip, err := droplet.PrivateIPv4() ip, err := droplet.PrivateIPv4()
if err == nil { if err == nil {

View File

@ -69,7 +69,7 @@ func GetClusterID() (string, error) {
for _, dropletTag := range dropletTags { for _, dropletTag := range dropletTags {
if strings.Contains(dropletTag, "KubernetesCluster:") { if strings.Contains(dropletTag, "KubernetesCluster:") {
clusterID = strings.Replace(dropletTag, ".", "-", -1) clusterID = strings.ReplaceAll(dropletTag, ".", "-")
tokens := strings.Split(clusterID, ":") tokens := strings.Split(clusterID, ":")
if len(tokens) != 2 { if len(tokens) != 2 {
@ -181,7 +181,7 @@ func (d *DOCloudProvider) getEtcdClusterSpec(vol godo.Volume) (*etcd.EtcdCluster
func (d *DOCloudProvider) GossipSeeds() (gossip.SeedProvider, error) { func (d *DOCloudProvider) GossipSeeds() (gossip.SeedProvider, error) {
for _, dropletTag := range d.dropletTags { 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) return gossipdo.NewSeedProvider(d.godoClient, dropletTag)
} }
} }

View File

@ -132,8 +132,8 @@ func runTest(t *testing.T, srcDir string, fromVersion string, toVersion string)
actualString := strings.TrimSpace(strings.Join(actual, "\n---\n\n")) actualString := strings.TrimSpace(strings.Join(actual, "\n---\n\n"))
expectedString := strings.TrimSpace(string(expectedBytes)) expectedString := strings.TrimSpace(string(expectedBytes))
actualString = strings.Replace(actualString, "\r", "", -1) actualString = strings.ReplaceAll(actualString, "\r", "")
expectedString = strings.Replace(expectedString, "\r", "", -1) expectedString = strings.ReplaceAll(expectedString, "\r", "")
if actualString != expectedString { if actualString != expectedString {
diffString := diff.FormatDiff(expectedString, actualString) diffString := diff.FormatDiff(expectedString, actualString)

View File

@ -689,7 +689,7 @@ func (_ *NetworkLoadBalancer) RenderTerraform(t *terraform.TerraformTarget, a, e
} }
func (e *NetworkLoadBalancer) TerraformName() string { func (e *NetworkLoadBalancer) TerraformName() string {
tfName := strings.Replace(fi.ValueOf(e.Name), ".", "-", -1) tfName := strings.ReplaceAll(fi.ValueOf(e.Name), ".", "-")
return tfName return tfName
} }

View File

@ -197,7 +197,7 @@ func (_ *SSHKey) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SS
if e.IsExistingKey() { if e.IsExistingKey() {
return nil 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) publicKey, err := t.AddFileResource("aws_key_pair", tfName, "public_key", e.PublicKey, false)
if err != nil { if err != nil {
return fmt.Errorf("error rendering PublicKey: %v", err) return fmt.Errorf("error rendering PublicKey: %v", err)
@ -225,7 +225,7 @@ func (e *SSHKey) TerraformLink() *terraformWriter.Literal {
if e.IsExistingKey() { if e.IsExistingKey() {
return terraformWriter.LiteralFromStringValue(*e.Name) return terraformWriter.LiteralFromStringValue(*e.Name)
} }
tfName := strings.Replace(*e.Name, ":", "", -1) tfName := strings.ReplaceAll(*e.Name, ":", "")
return terraformWriter.LiteralProperty("aws_key_pair", tfName, "id") return terraformWriter.LiteralProperty("aws_key_pair", tfName, "id")
} }

View File

@ -214,7 +214,7 @@ func GetClusterName40(cluster string) string {
// GetResourceName32 will attempt to calculate a meaningful name for a resource given a prefix // GetResourceName32 will attempt to calculate a meaningful name for a resource given a prefix
// Will never return a string longer than 32 chars // Will never return a string longer than 32 chars
func GetResourceName32(cluster string, prefix string) string { 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 // We always compute the hash and add it, lest we trick users into assuming that we never do this
opt := truncate.TruncateStringOptions{ opt := truncate.TruncateStringOptions{

View File

@ -295,7 +295,7 @@ func (c *doCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([]fi
return false, fmt.Errorf("LoadBalancers.List returned error: %v", err) 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 { for _, lb := range loadBalancers {
if lb.Name == lbName { 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) 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. // check if volume belongs to this cluster.
// tag will be in the format "KubernetesCluster:dev5-k8s-local" (where clusterName is dev5.k8s.local) // 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)) { if strings.Contains(myTag, fmt.Sprintf("%s:%s", TagKubernetesClusterNamePrefix, clusterName)) {
klog.V(10).Infof("findEtcdStatus cluster comparison matched for tag: %v", myTag) klog.V(10).Infof("findEtcdStatus cluster comparison matched for tag: %v", myTag)
// this volume belongs to our cluster, add this to our etcdClusterSpec. // 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 var result []DOInstanceGroup
instanceGroupMap := make(map[string][]string) // map of instance group name with droplet ids 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) droplets, err := c.GetAllDropletsByTag(clusterTag)
if err != nil { if err != nil {
return nil, fmt.Errorf("get all droplets for tag %s returned error. Error=%v", clusterTag, err) return nil, fmt.Errorf("get all droplets for tag %s returned error. Error=%v", clusterTag, err)

View File

@ -20,6 +20,6 @@ import "strings"
func SafeClusterName(clusterName string) string { func SafeClusterName(clusterName string) string {
// DO does not support . in tags / names // DO does not support . in tags / names
safeClusterName := strings.Replace(clusterName, ".", "-", -1) safeClusterName := strings.ReplaceAll(clusterName, ".", "-")
return safeClusterName return safeClusterName
} }

View File

@ -171,7 +171,7 @@ func (_ *SSHKey) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SS
if e.IsExistingKey() { if e.IsExistingKey() {
return nil 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) publicKey, err := t.AddFileResource("digitalocean_ssh_key", tfName, "public_key", e.PublicKey, false)
if err != nil { if err != nil {
return fmt.Errorf("error rendering PublicKey: %v", err) return fmt.Errorf("error rendering PublicKey: %v", err)
@ -198,7 +198,7 @@ func (e *SSHKey) TerraformLink() *terraformWriter.Literal {
if e.IsExistingKey() { if e.IsExistingKey() {
return terraformWriter.LiteralFromStringValue(*e.Name) return terraformWriter.LiteralFromStringValue(*e.Name)
} }
tfName := strings.Replace(*e.Name, ":", "", -1) tfName := strings.ReplaceAll(*e.Name, ":", "")
return terraformWriter.LiteralProperty("digitalocean_ssh_key", tfName, "id") return terraformWriter.LiteralProperty("digitalocean_ssh_key", tfName, "id")
} }

View File

@ -58,7 +58,7 @@ func EncodeGCELabel(s string) string {
// DecodeGCELabel reverse EncodeGCELabel, taking the encoded RFC1035 compatible value back to a string // DecodeGCELabel reverse EncodeGCELabel, taking the encoded RFC1035 compatible value back to a string
func DecodeGCELabel(s string) (string, error) { func DecodeGCELabel(s string) (string, error) {
uriForm := strings.Replace(s, "-", "%", -1) uriForm := strings.ReplaceAll(s, "-", "%")
v, err := url.QueryUnescape(uriForm) v, err := url.QueryUnescape(uriForm)
if err != nil { if err != nil {
return "", fmt.Errorf("cannot decode GCE label: %q", s) return "", fmt.Errorf("cannot decode GCE label: %q", s)

View File

@ -58,7 +58,7 @@ func ClusterPrefixedName(objectName string, clusterName string, maxLength int) s
} }
// GCE does not support . in tags / names // GCE does not support . in tags / names
safeClusterName := strings.Replace(clusterName, ".", "-", -1) safeClusterName := strings.ReplaceAll(clusterName, ".", "-")
opt := truncate.TruncateStringOptions{ opt := truncate.TruncateStringOptions{
MaxLength: prefixLength, MaxLength: prefixLength,
@ -79,7 +79,7 @@ func ClusterSuffixedName(objectName string, clusterName string, maxLength int) s
} }
// GCE does not support . in tags / names // GCE does not support . in tags / names
safeClusterName := strings.Replace(clusterName, ".", "-", -1) safeClusterName := strings.ReplaceAll(clusterName, ".", "-")
opt := truncate.TruncateStringOptions{ opt := truncate.TruncateStringOptions{
MaxLength: suffixLength, MaxLength: suffixLength,
@ -95,7 +95,7 @@ func ClusterSuffixedName(objectName string, clusterName string, maxLength int) s
// deprecated: prefer ClusterSuffixedName // deprecated: prefer ClusterSuffixedName
func SafeClusterName(clusterName string) string { func SafeClusterName(clusterName string) string {
// GCE does not support . in tags / names // GCE does not support . in tags / names
safeClusterName := strings.Replace(clusterName, ".", "-", -1) safeClusterName := strings.ReplaceAll(clusterName, ".", "-")
return safeClusterName return safeClusterName
} }
@ -113,7 +113,7 @@ func LabelForCluster(clusterName string) Label {
// SafeTruncatedClusterName returns a safe and truncated cluster name // SafeTruncatedClusterName returns a safe and truncated cluster name
func SafeTruncatedClusterName(clusterName string, maxLength int) string { func SafeTruncatedClusterName(clusterName string, maxLength int) string {
// GCE does not support . in tags / names // GCE does not support . in tags / names
safeClusterName := strings.Replace(clusterName, ".", "-", -1) safeClusterName := strings.ReplaceAll(clusterName, ".", "-")
opt := truncate.TruncateStringOptions{ opt := truncate.TruncateStringOptions{
MaxLength: maxLength, MaxLength: maxLength,

View File

@ -163,7 +163,7 @@ func (_ *ServerGroup) RenderOpenstack(t *openstack.OpenstackAPITarget, a, e, cha
for currentLastIndex > fi.ValueOf(maxSize) { for currentLastIndex > fi.ValueOf(maxSize) {
iName := strings.ToLower(fmt.Sprintf("%s-%d.%s", igName, currentLastIndex, fi.ValueOf(a.ClusterName))) 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{ opts := servers.ListOpts{
Name: fmt.Sprintf("^%s", igName), Name: fmt.Sprintf("^%s", igName),
} }

View File

@ -108,8 +108,8 @@ func (s *SSHKey) CheckChanges(a, e, changes *SSHKey) error {
} }
func openstackKeyPairName(org string) string { func openstackKeyPairName(org string) string {
name := strings.Replace(org, ".", "-", -1) name := strings.ReplaceAll(org, ".", "-")
name = strings.Replace(name, ":", "_", -1) name = strings.ReplaceAll(name, ":", "_")
return name return name
} }

View File

@ -95,7 +95,7 @@ func (tf *TemplateFunctions) AddTo(dest template.FuncMap, secretStore fi.SecretS
dest["SharedVPC"] = tf.SharedVPC dest["SharedVPC"] = tf.SharedVPC
// Remember that we may be on a different arch from the target. Hard-code for now. // Remember that we may be on a different arch from the target. Hard-code for now.
dest["replace"] = func(s, find, replace string) string { 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 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 { if cluster.Spec.CloudProvider.AWS != nil && cluster.Spec.CloudProvider.AWS.NodeTerminationHandler != nil {
dest["DefaultQueueName"] = func() string { dest["DefaultQueueName"] = func() string {
s := strings.Replace(tf.ClusterName(), ".", "-", -1) s := strings.ReplaceAll(tf.ClusterName(), ".", "-")
domain := ".amazonaws.com/" domain := ".amazonaws.com/"
if strings.Contains(tf.Region, "cn-") { if strings.Contains(tf.Region, "cn-") {
domain = ".amazonaws.com.cn/" domain = ".amazonaws.com.cn/"

View File

@ -302,7 +302,7 @@ func (c *VFSCAStore) AddSSHPublicKey(ctx context.Context, pubkey []byte) error {
func (c *VFSCAStore) buildSSHPublicKeyPath(id string) vfs.Path { func (c *VFSCAStore) buildSSHPublicKeyPath(id string) vfs.Path {
// id is fingerprint with colons, but we store without colons // 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) return c.basedir.Join("ssh", "public", "admin", id)
} }

View File

@ -23,7 +23,7 @@ import (
// SplitContentToSections splits content of a kops manifest into sections. // SplitContentToSections splits content of a kops manifest into sections.
func SplitContentToSections(content []byte) [][]byte { func SplitContentToSections(content []byte) [][]byte {
// replace windows line endings with unix ones // 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")) return bytes.Split(normalized, []byte("\n---\n"))
} }