From 0ff474ff375d92b6152a7652cb50398f9f48162c Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 21 Aug 2024 20:47:20 -0700 Subject: [PATCH] all: fix new lint warnings from bumping staticcheck In prep for updating to new staticcheck required for Go 1.23. Updates #12912 Change-Id: If77892a023b79c6fa798f936fc80428fd4ce0673 Signed-off-by: Brad Fitzpatrick --- cmd/k8s-operator/svc.go | 2 +- cmd/tailscale/cli/exitnode_test.go | 4 +-- net/art/table_test.go | 2 +- net/netmon/interfaces_linux.go | 43 ------------------------------ safesocket/unixsocket.go | 4 --- ssh/tailssh/tailssh.go | 1 + tstest/integration/vms/distros.go | 2 -- 7 files changed, 5 insertions(+), 53 deletions(-) diff --git a/cmd/k8s-operator/svc.go b/cmd/k8s-operator/svc.go index 73d3adf49..9e7c6f4f3 100644 --- a/cmd/k8s-operator/svc.go +++ b/cmd/k8s-operator/svc.go @@ -327,7 +327,7 @@ func (a *ServiceReconciler) maybeProvision(ctx context.Context, logger *zap.Suga if err != nil { msg := fmt.Sprintf("failed to parse cluster IP: %v", err) tsoperator.SetServiceCondition(svc, tsapi.ProxyReady, metav1.ConditionFalse, reasonProxyFailed, msg, a.clock, logger) - return fmt.Errorf(msg) + return errors.New(msg) } for _, ip := range tsIPs { addr, err := netip.ParseAddr(ip) diff --git a/cmd/tailscale/cli/exitnode_test.go b/cmd/tailscale/cli/exitnode_test.go index 4f66fa756..9d569a45a 100644 --- a/cmd/tailscale/cli/exitnode_test.go +++ b/cmd/tailscale/cli/exitnode_test.go @@ -135,7 +135,7 @@ func TestFilterFormatAndSortExitNodes(t *testing.T) { result := filterFormatAndSortExitNodes(ps, "") if res := cmp.Diff(result.Countries, want.Countries, cmpopts.IgnoreUnexported(key.NodePublic{})); res != "" { - t.Fatalf(res) + t.Fatal(res) } }) @@ -230,7 +230,7 @@ func TestFilterFormatAndSortExitNodes(t *testing.T) { result := filterFormatAndSortExitNodes(ps, "Pacific") if res := cmp.Diff(result.Countries, want.Countries, cmpopts.IgnoreUnexported(key.NodePublic{})); res != "" { - t.Fatalf(res) + t.Fatal(res) } }) } diff --git a/net/art/table_test.go b/net/art/table_test.go index cdc295c0e..a129c8484 100644 --- a/net/art/table_test.go +++ b/net/art/table_test.go @@ -589,7 +589,7 @@ func TestInsertCompare(t *testing.T) { } if debugInsert { - t.Logf(fast.debugSummary()) + t.Log(fast.debugSummary()) } seenVals4 := map[int]bool{} diff --git a/net/netmon/interfaces_linux.go b/net/netmon/interfaces_linux.go index ef7dcaaca..299f3101e 100644 --- a/net/netmon/interfaces_linux.go +++ b/net/netmon/interfaces_linux.go @@ -15,8 +15,6 @@ "net" "net/netip" "os" - "os/exec" - "runtime" "strings" "sync/atomic" @@ -50,9 +48,6 @@ func init() { func likelyHomeRouterIPLinux() (ret netip.Addr, myIP netip.Addr, ok bool) { if procNetRouteErr.Load() { // If we failed to read /proc/net/route previously, don't keep trying. - if runtime.GOOS == "android" { - return likelyHomeRouterIPAndroid() - } return ret, myIP, false } lineNum := 0 @@ -94,9 +89,6 @@ func likelyHomeRouterIPLinux() (ret netip.Addr, myIP netip.Addr, ok bool) { } if err != nil { procNetRouteErr.Store(true) - if runtime.GOOS == "android" { - return likelyHomeRouterIPAndroid() - } log.Printf("interfaces: failed to read /proc/net/route: %v", err) } if ret.IsValid() { @@ -137,41 +129,6 @@ func likelyHomeRouterIPLinux() (ret netip.Addr, myIP netip.Addr, ok bool) { return netip.Addr{}, netip.Addr{}, false } -// Android apps don't have permission to read /proc/net/route, at -// least on Google devices and the Android emulator. -func likelyHomeRouterIPAndroid() (ret netip.Addr, _ netip.Addr, ok bool) { - cmd := exec.Command("/system/bin/ip", "route", "show", "table", "0") - out, err := cmd.StdoutPipe() - if err != nil { - return - } - if err := cmd.Start(); err != nil { - log.Printf("interfaces: running /system/bin/ip: %v", err) - return - } - // Search for line like "default via 10.0.2.2 dev radio0 table 1016 proto static mtu 1500 " - lineread.Reader(out, func(line []byte) error { - const pfx = "default via " - if !mem.HasPrefix(mem.B(line), mem.S(pfx)) { - return nil - } - line = line[len(pfx):] - sp := bytes.IndexByte(line, ' ') - if sp == -1 { - return nil - } - ipb := line[:sp] - if ip, err := netip.ParseAddr(string(ipb)); err == nil && ip.Is4() { - ret = ip - log.Printf("interfaces: found Android default route %v", ip) - } - return nil - }) - cmd.Process.Kill() - cmd.Wait() - return ret, netip.Addr{}, ret.IsValid() -} - func defaultRoute() (d DefaultRouteDetails, err error) { v, err := defaultRouteInterfaceProcNet() if err == nil { diff --git a/safesocket/unixsocket.go b/safesocket/unixsocket.go index ef22263aa..ec8635bbb 100644 --- a/safesocket/unixsocket.go +++ b/safesocket/unixsocket.go @@ -7,7 +7,6 @@ import ( "context" - "errors" "fmt" "log" "net" @@ -18,9 +17,6 @@ ) func connect(ctx context.Context, path string) (net.Conn, error) { - if runtime.GOOS == "js" { - return nil, errors.New("safesocket.Connect not yet implemented on js/wasm") - } var std net.Dialer return std.DialContext(ctx, "unix", path) } diff --git a/ssh/tailssh/tailssh.go b/ssh/tailssh/tailssh.go index fd747f591..56d6e63c9 100644 --- a/ssh/tailssh/tailssh.go +++ b/ssh/tailssh/tailssh.go @@ -1731,6 +1731,7 @@ func envValFromList(env []string, wantKey string) (v string) { // envEq reports whether environment variable a == b for the current // operating system. func envEq(a, b string) bool { + //lint:ignore SA4032 in case this func moves elsewhere, permit the GOOS check if runtime.GOOS == "windows" { return strings.EqualFold(a, b) } diff --git a/tstest/integration/vms/distros.go b/tstest/integration/vms/distros.go index ea43e271b..ca2bf53ba 100644 --- a/tstest/integration/vms/distros.go +++ b/tstest/integration/vms/distros.go @@ -11,8 +11,6 @@ "github.com/tailscale/hujson" ) -// go:generate go run ./gen - type Distro struct { Name string // amazon-linux URL string // URL to a qcow2 image