Repository: tailscale/tailscale (Go)

Issue:
tailscale update: Alpine edge 3.20.0 shows no update needed when a newer package is available
### What is the issue?

After upgrading Alpine to edge 3.20.0, `tailscale update` should pick up the latest available version (currently 1.58.2). Instead, `tailscale update` on version 1.54.1 shows no update needed. 



### Steps to reproduce

With a previous Tailscale version installed, upgrade Alpine repositories to edge and attempt `tailscale update`.

```
alpine:~# cat /etc/alpine-release
3.20.0_alpha20231219
alpine:~# tailscale update
already running stable version 1.54.1; no update needed

alpine:~# apk update && apk info tailscale
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
v20231219-4573-g19247761b6d [http://dl-cdn.alpinelinux.org/alpine/edge/main]
v20231219-4578-g68676dd018e [http://dl-cdn.alpinelinux.org/alpine/edge/community]
OK: 23375 distinct packages available
tailscale-1.54.1-r0 description:
The easiest, most secure way to use WireGuard and 2FA

tailscale-1.54.1-r0 webpage:
https://tailscale.com/

tailscale-1.54.1-r0 installed size:
34 MiB

tailscale-1.58.2-r0 description:
The easiest, most secure way to use WireGuard and 2FA

tailscale-1.58.2-r0 webpage:
https://tailscale.com/

tailscale-1.58.2-r0 installed size:
35 MiB
```

### Are there any recent changes that introduced the issue?

_No response_

### OS

Linux

### OS version

Alpine 3.20.0_alpha20231219

### Tailscale version

_No response_

### Other software

_No response_

### Bug report

_No response_


Discussion:
Another thing to fix here: detect when `/etc/apk/repositories` has a static version, like 3.19.
I'm having this issue as well.
I'm having this issue as well

current version 1.76.6
latest version 1.80.3

and it seems like it affects the DNS connection. I can't connect to the internet whenever tailscale is up
@Lastdough the latest version of tailscale in alpine v3.21 is 1.76.6: https://pkgs.alpinelinux.org/packages?name=tailscale&branch=v3.21&repo=&arch=x86_64&origin=&flagged=&maintainer=
You can get a newer version by running the edge branch of alpine: https://pkgs.alpinelinux.org/packages?name=tailscale&branch=edge&repo=&arch=x86_64&origin=&flagged=&maintainer=
These packages are managed by Alpine maintainers, not by us, so we can't publish a newer version.

For DNS issues, please open a new issue and provide more details about your tailnet DNS configuration and example DNS queries that fail.



Patch:
diff --git a/clientupdate/clientupdate.go b/clientupdate/clientupdate.go
index ddd21cd954c59..565544e7f451e 100644
--- a/clientupdate/clientupdate.go
+++ b/clientupdate/clientupdate.go
@@ -665,6 +665,7 @@ func (up *Updater) updateAlpineLike() (err error) {
 
 func parseAlpinePackageVersion(out []byte) (string, error) {
 	s := bufio.NewScanner(bytes.NewReader(out))
+	var maxVer string
 	for s.Scan() {
 		// The line should look like this:
 		// tailscale-1.44.2-r0 description:
@@ -676,7 +677,13 @@ func parseAlpinePackageVersion(out []byte) (string, error) {
 		if len(parts) < 3 {
 			return "", fmt.Errorf("malformed info line: %q", line)
 		}
-		return parts[1], nil
+		ver := parts[1]
+		if cmpver.Compare(ver, maxVer) == 1 {
+			maxVer = ver
+		}
+	}
+	if maxVer != "" {
+		return maxVer, nil
 	}
 	return "", errors.New("tailscale version not found in output")
 }


Test patch:
diff --git a/clientupdate/clientupdate_test.go b/clientupdate/clientupdate_test.go
index f0c7ebea0895a..eaad1206e1ce4 100644
--- a/clientupdate/clientupdate_test.go
+++ b/clientupdate/clientupdate_test.go
@@ -251,6 +251,29 @@ tailscale installed size:
 			out:     "",
 			wantErr: true,
 		},
+		{
+			desc: "multiple versions",
+			out: `
+tailscale-1.54.1-r0 description:
+The easiest, most secure way to use WireGuard and 2FA
+
+tailscale-1.54.1-r0 webpage:
+https://tailscale.com/
+
+tailscale-1.54.1-r0 installed size:
+34 MiB
+
+tailscale-1.58.2-r0 description:
+The easiest, most secure way to use WireGuard and 2FA
+
+tailscale-1.58.2-r0 webpage:
+https://tailscale.com/
+
+tailscale-1.58.2-r0 installed size:
+35 MiB
+`,
+			want: "1.58.2",
+		},
 	}
 
 	for _, tt := range tests {