Skip to content

Commit e875361

Browse files
committed
capver: generate
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
1 parent 251e16d commit e875361

3 files changed

Lines changed: 99 additions & 52 deletions

File tree

hscontrol/capver/capver.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@ import (
1212
"tailscale.com/util/set"
1313
)
1414

15+
const (
16+
// minVersionParts is the minimum number of version parts needed for major.minor.
17+
minVersionParts = 2
18+
19+
// legacyDERPCapVer is the capability version when LegacyDERP can be cleaned up.
20+
legacyDERPCapVer = 111
21+
)
22+
1523
// CanOldCodeBeCleanedUp is intended to be called on startup to see if
1624
// there are old code that can ble cleaned up, entries should contain
1725
// a CapVer where something can be cleaned up and a panic if it can.
1826
// This is only intended to catch things in tests.
1927
//
2028
// All uses of Capability version checks should be listed here.
2129
func CanOldCodeBeCleanedUp() {
22-
if MinSupportedCapabilityVersion >= 111 {
30+
if MinSupportedCapabilityVersion >= legacyDERPCapVer {
2331
panic("LegacyDERP can be cleaned up in tail.go")
2432
}
2533
}
@@ -44,12 +52,25 @@ func TailscaleVersion(ver tailcfg.CapabilityVersion) string {
4452
}
4553

4654
// CapabilityVersion returns the CapabilityVersion for the given Tailscale version.
55+
// It accepts both full versions (v1.90.1) and minor versions (v1.90).
4756
func CapabilityVersion(ver string) tailcfg.CapabilityVersion {
4857
if !strings.HasPrefix(ver, "v") {
4958
ver = "v" + ver
5059
}
5160

52-
return tailscaleToCapVer[ver]
61+
// Try direct lookup first (works for minor versions like v1.90)
62+
if cv, ok := tailscaleToCapVer[ver]; ok {
63+
return cv
64+
}
65+
66+
// Try extracting minor version from full version (v1.90.1 -> v1.90)
67+
parts := strings.Split(strings.TrimPrefix(ver, "v"), ".")
68+
if len(parts) >= minVersionParts {
69+
minor := "v" + parts[0] + "." + parts[1]
70+
return tailscaleToCapVer[minor]
71+
}
72+
73+
return 0
5374
}
5475

5576
// TailscaleLatest returns the n latest Tailscale versions.

hscontrol/capver/capver_generated.go

Lines changed: 67 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,79 @@ package capver
55
import "tailscale.com/tailcfg"
66

77
var tailscaleToCapVer = map[string]tailcfg.CapabilityVersion{
8-
"v1.70.0": 102,
9-
"v1.72.0": 104,
10-
"v1.72.1": 104,
11-
"v1.74.0": 106,
12-
"v1.74.1": 106,
13-
"v1.76.0": 106,
14-
"v1.76.1": 106,
15-
"v1.76.6": 106,
16-
"v1.78.0": 109,
17-
"v1.78.1": 109,
18-
"v1.80.0": 113,
19-
"v1.80.1": 113,
20-
"v1.80.2": 113,
21-
"v1.80.3": 113,
22-
"v1.82.0": 115,
23-
"v1.82.5": 115,
24-
"v1.84.0": 116,
25-
"v1.84.1": 116,
26-
"v1.84.2": 116,
27-
"v1.86.0": 122,
28-
"v1.86.2": 123,
29-
"v1.88.1": 125,
30-
"v1.88.3": 125,
31-
"v1.90.1": 130,
32-
"v1.90.2": 130,
33-
"v1.90.3": 130,
34-
"v1.90.4": 130,
35-
"v1.90.6": 130,
36-
"v1.90.8": 130,
37-
"v1.90.9": 130,
8+
"v1.24": 32,
9+
"v1.26": 32,
10+
"v1.28": 32,
11+
"v1.30": 41,
12+
"v1.32": 46,
13+
"v1.34": 51,
14+
"v1.36": 56,
15+
"v1.38": 58,
16+
"v1.40": 61,
17+
"v1.42": 62,
18+
"v1.44": 63,
19+
"v1.46": 65,
20+
"v1.48": 68,
21+
"v1.50": 74,
22+
"v1.52": 79,
23+
"v1.54": 79,
24+
"v1.56": 82,
25+
"v1.58": 85,
26+
"v1.60": 87,
27+
"v1.62": 88,
28+
"v1.64": 90,
29+
"v1.66": 95,
30+
"v1.68": 97,
31+
"v1.70": 102,
32+
"v1.72": 104,
33+
"v1.74": 106,
34+
"v1.76": 106,
35+
"v1.78": 109,
36+
"v1.80": 113,
37+
"v1.82": 115,
38+
"v1.84": 116,
39+
"v1.86": 123,
40+
"v1.88": 125,
41+
"v1.90": 130,
42+
"v1.92": 131,
3843
}
3944

4045
var capVerToTailscaleVer = map[tailcfg.CapabilityVersion]string{
41-
102: "v1.70.0",
42-
104: "v1.72.0",
43-
106: "v1.74.0",
44-
109: "v1.78.0",
45-
113: "v1.80.0",
46-
115: "v1.82.0",
47-
116: "v1.84.0",
48-
122: "v1.86.0",
49-
123: "v1.86.2",
50-
125: "v1.88.1",
51-
130: "v1.90.1",
46+
32: "v1.24",
47+
41: "v1.30",
48+
46: "v1.32",
49+
51: "v1.34",
50+
56: "v1.36",
51+
58: "v1.38",
52+
61: "v1.40",
53+
62: "v1.42",
54+
63: "v1.44",
55+
65: "v1.46",
56+
68: "v1.48",
57+
74: "v1.50",
58+
79: "v1.52",
59+
82: "v1.56",
60+
85: "v1.58",
61+
87: "v1.60",
62+
88: "v1.62",
63+
90: "v1.64",
64+
95: "v1.66",
65+
97: "v1.68",
66+
102: "v1.70",
67+
104: "v1.72",
68+
106: "v1.74",
69+
109: "v1.78",
70+
113: "v1.80",
71+
115: "v1.82",
72+
116: "v1.84",
73+
123: "v1.86",
74+
125: "v1.88",
75+
130: "v1.90",
76+
131: "v1.92",
5277
}
5378

5479
// SupportedMajorMinorVersions is the number of major.minor Tailscale versions supported.
55-
const SupportedMajorMinorVersions = 9
80+
const SupportedMajorMinorVersions = 10
5681

5782
// MinSupportedCapabilityVersion represents the minimum capability version
5883
// supported by this Headscale instance (latest 10 minor versions)

hscontrol/capver/capver_test_data.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ var tailscaleLatestMajorMinorTests = []struct {
99
stripV bool
1010
expected []string
1111
}{
12-
{3, false, []string{"v1.86", "v1.88", "v1.90"}},
13-
{2, true, []string{"1.88", "1.90"}},
14-
{9, true, []string{
12+
{3, false, []string{"v1.88", "v1.90", "v1.92"}},
13+
{2, true, []string{"1.90", "1.92"}},
14+
{10, true, []string{
1515
"1.74",
1616
"1.76",
1717
"1.78",
@@ -21,6 +21,7 @@ var tailscaleLatestMajorMinorTests = []struct {
2121
"1.86",
2222
"1.88",
2323
"1.90",
24+
"1.92",
2425
}},
2526
{0, false, nil},
2627
}
@@ -29,11 +30,11 @@ var capVerMinimumTailscaleVersionTests = []struct {
2930
input tailcfg.CapabilityVersion
3031
expected string
3132
}{
32-
{106, "v1.74.0"},
33-
{102, "v1.70.0"},
34-
{104, "v1.72.0"},
35-
{109, "v1.78.0"},
36-
{113, "v1.80.0"},
33+
{106, "v1.74"},
34+
{32, "v1.24"},
35+
{41, "v1.30"},
36+
{46, "v1.32"},
37+
{51, "v1.34"},
3738
{9001, ""}, // Test case for a version higher than any in the map
3839
{60, ""}, // Test case for a version lower than any in the map
3940
}

0 commit comments

Comments
 (0)