Skip to content

Commit

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

Signed-off-by: Tom Pantelis <[email protected]>
  • Loading branch information
tpantelis authored and skitt committed Nov 18, 2024
1 parent a64ffe6 commit 98d0d7e
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 23 deletions.
4 changes: 2 additions & 2 deletions pkg/apis/submariner.io/v1/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ func parsePort(port string) (int32, error) {

func (ep *EndpointSpec) GenerateName() (string, error) {
if ep.ClusterID == "" {
return "", fmt.Errorf("ClusterID cannot be empty")
return "", errors.New("ClusterID cannot be empty")
}

if ep.CableName == "" {
return "", fmt.Errorf("CableName cannot be empty")
return "", errors.New("CableName cannot be empty")
}

return resource.EnsureValidName(fmt.Sprintf("%s-%s", ep.ClusterID, ep.CableName)), nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/cable/wireguard/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func NewDriver(localEndpoint *endpoint.Local, _ *types.SubmarinerCluster) (cable
// Create the controller.
if w.client, err = wgctrl.New(); err != nil {
if os.IsNotExist(err) {
return nil, fmt.Errorf("wgctrl is not available on this system")
return nil, errors.New("wgctrl is not available on this system")
}

return nil, errors.Wrap(err, "failed to open wgctl client")
Expand Down Expand Up @@ -312,7 +312,7 @@ func (w *wireguard) ConnectToEndpoint(endpointInfo *natdiscovery.NATEndpointInfo
func keyFromSpec(ep *v1.EndpointSpec) (*wgtypes.Key, error) {
s, found := ep.BackendConfig[PublicKey]
if !found {
return nil, fmt.Errorf("endpoint is missing public key")
return nil, errors.New("endpoint is missing public key")
}

key, err := wgtypes.ParseKey(s)
Expand Down
4 changes: 1 addition & 3 deletions pkg/globalnet/controllers/egress_pod_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ limitations under the License.
package controllers

import (
"fmt"

"github.com/pkg/errors"
"github.com/submariner-io/admiral/pkg/log"
"github.com/submariner-io/admiral/pkg/watcher"
Expand Down Expand Up @@ -53,7 +51,7 @@ func startEgressPodWatcher(name, namespace string, namedSet packetfilter.NamedSe
Scheme: config.Scheme,
ResourceConfigs: []watcher.ResourceConfig{
{
Name: fmt.Sprintf("Pod watcher %s", name),
Name: "Pod watcher " + name,
ResourceType: &corev1.Pod{},
Handler: watcher.EventHandlerFuncs{
OnCreateFunc: pw.onCreateOrUpdate,
Expand Down
3 changes: 2 additions & 1 deletion pkg/ipset/ipset.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ limitations under the License.
package ipset

import (
"errors"
"fmt"
"os/exec"
"regexp"
Expand Down Expand Up @@ -384,7 +385,7 @@ func (runner *runner) ListSets() ([]string, error) {
// ListEntries lists all the entries from a named set.
func (runner *runner) ListEntries(set string) ([]string, error) {
if set == "" {
return nil, fmt.Errorf("set name can't be empty")
return nil, errors.New("set name can't be empty")
}

out, err := runner.runWithOutput([]string{"list", set}, "error listing set %q", set)
Expand Down
4 changes: 2 additions & 2 deletions pkg/netlink/netlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func GetDefaultGatewayInterface() (*net.Interface, error) {
for i := range routes {
if routes[i].Dst == nil || routes[i].Dst.String() == allZeroAddress {
if routes[i].LinkIndex == 0 {
return nil, fmt.Errorf("default gateway interface could not be determined")
return nil, errors.New("default gateway interface could not be determined")
}

iface, err := net.InterfaceByIndex(routes[i].LinkIndex)
Expand All @@ -286,7 +286,7 @@ func GetDefaultGatewayInterface() (*net.Interface, error) {
}
}

return nil, fmt.Errorf("unable to find default route")
return nil, errors.New("unable to find default route")
}

func DeleteIfaceAndAssociatedRoutes(iface string, tableID int) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/routeagent_driver/handlers/ovn/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func jsonToIP(jsonData string) (string, error) {

ipStr, found := data["ipv4"]
if !found {
return "", fmt.Errorf("json data does not contain an 'ipv4' field")
return "", errors.New("json data does not contain an 'ipv4' field")
}

ip, _, err := net.ParseCIDR(ipStr)
Expand Down
7 changes: 4 additions & 3 deletions pkg/routeagent_driver/handlers/ovn/vsctl/vsctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"bytes"
"fmt"
"os/exec"
"strconv"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -75,8 +76,8 @@ func DelBridge(bridgeName string) error {

func AddInternalPort(bridgeName, portName, macAddress string, mtu int) error {
_, err := vsctlCmd("--may-exist", "add-port", bridgeName, portName, "--",
"set", "interface", portName, "type=internal", "mtu_request="+fmt.Sprintf("%d", mtu),
fmt.Sprintf("mac=%s", strings.ReplaceAll(macAddress, ":", "\\:")))
"set", "interface", portName, "type=internal", "mtu_request="+strconv.Itoa(mtu),
"mac="+strings.ReplaceAll(macAddress, ":", "\\:"))

return err
}
Expand Down Expand Up @@ -109,7 +110,7 @@ func AddOVNBridgeMapping(netName, bridgeName string) error {
}

if _, err = vsctlCmd("set", "Open_vSwitch", ".",
fmt.Sprintf("external_ids:ovn-bridge-mappings=%s", bridgeMappings)); err != nil {
"external_ids:ovn-bridge-mappings="+bridgeMappings); err != nil {
return errors.Wrap(err, "failed to set ovn-bridge-mappings")
}

Expand Down
9 changes: 4 additions & 5 deletions pkg/versions/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ limitations under the License.
package versions

import (
"fmt"
"runtime"

"github.com/submariner-io/admiral/pkg/log"
Expand All @@ -32,10 +31,10 @@ var (
)

func Log(logger *log.Logger) {
logger.Info(fmt.Sprintf("Go Version: %s", runtime.Version()))
logger.Info(fmt.Sprintf("Go Arch: %s", runtime.GOARCH))
logger.Info(fmt.Sprintf("Git Commit Hash: %s", gitCommitHash))
logger.Info(fmt.Sprintf("Git Commit Date: %s", gitCommitDate))
logger.Info("Go Version: " + runtime.Version())
logger.Info("Go Arch: " + runtime.GOARCH)
logger.Info("Git Commit Hash: " + gitCommitHash)
logger.Info("Git Commit Date: " + gitCommitDate)
}

// Submariner returns the version info of submariner.
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/framework/dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func getGlobalIngressIP(p tcp.ConnectivityTestParams, service *v1.Service) strin
} else if p.ToEndpointType == tcp.GlobalPodIP {
podList := p.Framework.AwaitPodsByLabelSelector(p.ToCluster, labels.Set(service.Spec.Selector).AsSelector().String(),
service.Namespace, 1)
ingressIPName := fmt.Sprintf("pod-%s", podList.Items[0].Name)
ingressIPName := "pod-" + podList.Items[0].Name

return p.Framework.AwaitGlobalIngressIP(p.ToCluster, ingressIPName, service.Namespace)
}
Expand All @@ -228,7 +228,7 @@ func getGlobalIngressIP(p tcp.ConnectivityTestParams, service *v1.Service) strin
}

func newGlobalEgressIPObj(namespace string, selector *metav1.LabelSelector) (*unstructured.Unstructured, error) {
geipName := fmt.Sprintf("test-e2e-egressip-%s", namespace)
geipName := "test-e2e-egressip-" + namespace
egressIPSpec := &submarinerv1.GlobalEgressIP{
ObjectMeta: metav1.ObjectMeta{
Name: geipName,
Expand Down
4 changes: 2 additions & 2 deletions test/external/dataplane/gn_connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func testGlobalNetExternalConnectivity(p testParams, g globalnetTestParams) {
}

func newGlobalEgressIPObj(namespace string, selector *metav1.LabelSelector) (*unstructured.Unstructured, error) {
geipName := fmt.Sprintf("test-e2e-egressip-%s", namespace)
geipName := "test-e2e-egressip-" + namespace
egressIPSpec := &submarinerv1.GlobalEgressIP{
ObjectMeta: metav1.ObjectMeta{
Name: geipName,
Expand Down Expand Up @@ -461,7 +461,7 @@ func getGlobalIngressIP(p testParams, service *v1.Service) string {
case tcp.GlobalPodIP:
podList := p.Framework.AwaitPodsByLabelSelector(p.Cluster, labels.Set(service.Spec.Selector).AsSelector().String(),
service.Namespace, 1)
ingressIPName := fmt.Sprintf("pod-%s", podList.Items[0].Name)
ingressIPName := "pod-" + podList.Items[0].Name

return p.Framework.AwaitGlobalIngressIP(p.Cluster, ingressIPName, service.Namespace)
}
Expand Down

0 comments on commit 98d0d7e

Please sign in to comment.