@@ -12,10 +12,11 @@ import (
12
12
13
13
var (
14
14
versionNum = `(0|[1-9][0-9]*)`
15
- internalPatchVersion = `(\-[a-zA-Z0-9_.+- ]+)`
15
+ internalPatchVersion = `(\-gke\.[0-9 ]+)`
16
16
17
17
versionRegex = regexp .MustCompile (`^` + versionNum + `\.` + versionNum + `\.` + versionNum + internalPatchVersion + "?$" )
18
18
minorVersionRegex = regexp .MustCompile (`^` + versionNum + `\.` + versionNum + `$` )
19
+ alphaVersionRegex = regexp .MustCompile (`^` + versionNum + `\.` + versionNum + `\.` + versionNum + `-alpha.*` )
19
20
gkeExtraVersionRegex = regexp .MustCompile (`^(?:gke)\.(0|[1-9][0-9]*)$` )
20
21
)
21
22
@@ -24,7 +25,9 @@ type version struct {
24
25
}
25
26
26
27
func (v * version ) String () string {
27
- if v .version [3 ] != - 1 {
28
+ if v .version [3 ] == - 2 {
29
+ return fmt .Sprintf ("%d.%d.%d-alpha" , v .version [0 ], v .version [1 ], v .version [2 ])
30
+ } else if v .version [3 ] != - 1 {
28
31
return fmt .Sprintf ("%d.%d.%d-gke.%d" , v .version [0 ], v .version [1 ], v .version [2 ], v .version [3 ])
29
32
}
30
33
@@ -82,6 +85,10 @@ func parseVersion(vs string) (*version, error) {
82
85
case versionRegex .MatchString (vs ):
83
86
submatches = versionRegex .FindStringSubmatch (vs )
84
87
lastIndex = 4
88
+ case alphaVersionRegex .MatchString (vs ):
89
+ submatches = alphaVersionRegex .FindStringSubmatch (vs )
90
+ v .version [3 ] = - 2
91
+ lastIndex = 4
85
92
case minorVersionRegex .MatchString (vs ):
86
93
submatches = minorVersionRegex .FindStringSubmatch (vs )
87
94
v .version [2 ] = - 1
@@ -99,7 +106,7 @@ func parseVersion(vs string) (*version, error) {
99
106
}
100
107
}
101
108
102
- if minorVersionRegex .MatchString (vs ) {
109
+ if minorVersionRegex .MatchString (vs ) || alphaVersionRegex . MatchString ( vs ) {
103
110
return & v , nil
104
111
}
105
112
@@ -131,9 +138,10 @@ func mustParseVersion(version string) *version {
131
138
}
132
139
133
140
// Helper function to compare versions.
134
- // -1 -- if left < right
135
- // 0 -- if left == right
136
- // 1 -- if left > right
141
+ //
142
+ // -1 -- if left < right
143
+ // 0 -- if left == right
144
+ // 1 -- if left > right
137
145
func (v * version ) compare (right * version ) int {
138
146
for i , b := range v .version {
139
147
if b > right .version [i ] {
0 commit comments