Skip to content

Commit

Permalink
Address perfsprint linter violations
Browse files Browse the repository at this point in the history
"fmt.Sprintf can be replaced with string concatenation"
"fmt.Errorf can be replaced with errors.New"

Signed-off-by: Tom Pantelis <[email protected]>
  • Loading branch information
tpantelis committed Jan 7, 2025
1 parent cd2da4b commit 4c83648
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions coredns/gateway/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package gateway

import (
"context"
"fmt"
"os"
"sync/atomic"

Expand Down Expand Up @@ -110,7 +109,7 @@ func (c *Controller) Start(client dynamic.Interface) error {
go c.informer.Run(c.stopCh)

if ok := cache.WaitForCacheSync(c.stopCh, c.informer.HasSynced); !ok {
return fmt.Errorf("failed to wait for informer cache to sync")
return errors.New("failed to wait for informer cache to sync")
}

go c.queue.Run(c.stopCh, c.processNextGateway)
Expand Down
3 changes: 2 additions & 1 deletion coredns/loadbalancer/smooth_weighted_round_robin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package loadbalancer
import (
"fmt"

"github.com/pkg/errors"
"github.com/submariner-io/admiral/pkg/log"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -67,7 +68,7 @@ func (lb *smoothWeightedRR) ItemCount() int {
// Add - adds a new unique item to the list.
func (lb *smoothWeightedRR) Add(item interface{}, weight int64) error {
if item == nil {
return fmt.Errorf("item cannot be nil")
return errors.New("item cannot be nil")
}

if weight < 0 {
Expand Down
9 changes: 4 additions & 5 deletions pkg/agent/controller/controller_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func (c *cluster) awaitServiceExportCondition(expected ...*mcsv1a1.ServiceExport
}

return nil
}).ShouldNot(BeNil(), fmt.Sprintf("ServiceExport condition not received. Expected: %s", resource.ToJSON(expected[i])))
}).ShouldNot(BeNil(), "ServiceExport condition not received. Expected: "+resource.ToJSON(expected[i]))
}

last := len(expected) - 1
Expand All @@ -551,7 +551,7 @@ func (c *cluster) awaitServiceExportCondition(expected ...*mcsv1a1.ServiceExport
}

return nil
}).ShouldNot(BeNil(), fmt.Sprintf("ServiceExport condition not found. Expected: %s", resource.ToJSON(expected[last])))
}).ShouldNot(BeNil(), "ServiceExport condition not found. Expected: "+resource.ToJSON(expected[last]))

for i := range expected {
assertEquivalentConditions(actual[i], expected[i])
Expand All @@ -575,16 +575,15 @@ func (c *cluster) ensureLastServiceExportCondition(expected *mcsv1a1.ServiceExpo
}
}

Fail(fmt.Sprintf("ServiceExport condition not found. Expected: %s", resource.ToJSON(expected)))
Fail("ServiceExport condition not found. Expected: " + resource.ToJSON(expected))

return -1
}

initialIndex := indexOfLastCondition()
Consistently(func() int {
return indexOfLastCondition()
}).Should(Equal(initialIndex), fmt.Sprintf("Expected ServiceExport condition to not change: %s",
resource.ToJSON(expected)))
}).Should(Equal(initialIndex), "Expected ServiceExport condition to not change: "+resource.ToJSON(expected))
}

func (c *cluster) ensureNoServiceExportCondition(condType mcsv1a1.ServiceExportConditionType, serviceExports ...*mcsv1a1.ServiceExport) {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func (f *Framework) AwaitPodIngressIPs(targetCluster framework.ClusterIndex, svc
ipList := make([]string, 0)

for i := range len(podList.Items) {
ingressIPName := fmt.Sprintf("pod-%s", podList.Items[i].Name)
ingressIPName := "pod-" + podList.Items[i].Name
ingressIP := f.Framework.AwaitGlobalIngressIP(targetCluster, ingressIPName, svc.Namespace)

if isLocal {
Expand Down Expand Up @@ -652,7 +652,7 @@ func (f *Framework) GetHealthCheckEnabledInfo(cluster framework.ClusterIndex) bo
}, func(result interface{}) (bool, string, error) {
unstructuredSubmarinerConfig := result.(*unstructured.Unstructured)

framework.By(fmt.Sprintf("Getting the Submariner Config, for cluster %s", framework.TestContext.ClusterIDs[cluster]))
framework.By("Getting the Submariner Config, for cluster " + framework.TestContext.ClusterIDs[cluster])

var found bool
var err error
Expand Down

0 comments on commit 4c83648

Please sign in to comment.