Skip to content

Commit

Permalink
chore: support version with and without v prefix
Browse files Browse the repository at this point in the history
Support passing in version with and without `v` prefix to Talos machine
config version contract parser.

Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
frezbo committed Jul 4, 2024
1 parent 9a56b85 commit 1f28726
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/machinery/config/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"regexp"
"strconv"
"strings"
)

// VersionContract describes Talos version to generate config for.
Expand Down Expand Up @@ -39,6 +40,8 @@ var versionRegexp = regexp.MustCompile(`^v(\d+)\.(\d+)($|\.)`)

// ParseContractFromVersion parses Talos version into VersionContract.
func ParseContractFromVersion(version string) (*VersionContract, error) {
version = "v" + strings.TrimPrefix(version, "v")

matches := versionRegexp.FindStringSubmatch(version)
if len(matches) < 3 {
return nil, fmt.Errorf("error parsing version %q", version)
Expand Down
1 change: 1 addition & 0 deletions pkg/machinery/config/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestContractParseVersion(t *testing.T) {
"v1.5.1": config.TalosVersion1_5,
"v1.88": {1, 88},
"v1.5.3-alpha.4": config.TalosVersion1_5,
"1.6": config.TalosVersion1_6,
} {
t.Run(v, func(t *testing.T) {
t.Parallel()
Expand Down

0 comments on commit 1f28726

Please sign in to comment.