From 1f28726d46953262f33c91082528cd190f53b143 Mon Sep 17 00:00:00 2001 From: Noel Georgi Date: Wed, 3 Jul 2024 19:26:54 +0530 Subject: [PATCH] chore: support version with and without `v` prefix Support passing in version with and without `v` prefix to Talos machine config version contract parser. Signed-off-by: Noel Georgi --- pkg/machinery/config/contract.go | 3 +++ pkg/machinery/config/contract_test.go | 1 + 2 files changed, 4 insertions(+) diff --git a/pkg/machinery/config/contract.go b/pkg/machinery/config/contract.go index ae944f756d..896185e5b0 100644 --- a/pkg/machinery/config/contract.go +++ b/pkg/machinery/config/contract.go @@ -8,6 +8,7 @@ import ( "fmt" "regexp" "strconv" + "strings" ) // VersionContract describes Talos version to generate config for. @@ -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) diff --git a/pkg/machinery/config/contract_test.go b/pkg/machinery/config/contract_test.go index fd36544462..2d396a59f9 100644 --- a/pkg/machinery/config/contract_test.go +++ b/pkg/machinery/config/contract_test.go @@ -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()