Skip to content

Commit

Permalink
Merge pull request #24 from srl-labs/version-parse-relax
Browse files Browse the repository at this point in the history
relaxed regexp to parse version out of a tag
  • Loading branch information
hellt authored Oct 14, 2022
2 parents 88b58e7 + beaf7b0 commit 486959c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions api/types/v1alpha1/srl_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func parseVersionString(s string) (*SrlVersion, error) {
return &SrlVersion{"0", "", "", "", ""}, nil
}

// https://regex101.com/r/eWS6Ms/1
// https://regex101.com/r/eWS6Ms/3
re := regexp.MustCompile(
`^v?(?P<major>\d{1,3})\.(?P<minor>\d{1,2})\.?(?P<patch>\d{1,2})?-?(?P<build>\d{1,10})?-?(?P<commit>\S+)?`,
`(?P<major>\d{1,3})\.(?P<minor>\d{1,2})\.?(?P<patch>\d{1,2})?-?(?P<build>\d{1,10})?-?(?P<commit>\S+)?`,
)

v := re.FindStringSubmatch(s)
Expand Down
5 changes: 5 additions & 0 deletions api/types/v1alpha1/srl_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func TestParseVersionString(t *testing.T) {
got: "0.0.0-34652",
want: &SrlVersion{"0", "0", "0", "34652", ""},
},
{
desc: "version_0.0.0-34652",
got: "version_0.0.0-34652",
want: &SrlVersion{"0", "0", "0", "34652", ""},
},
{
desc: "latest",
got: "latest",
Expand Down
4 changes: 2 additions & 2 deletions api/types/v1alpha1/srlinux_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestGetImageVersion(t *testing.T) {
{
desc: "invalid version is present",
spec: &SrlinuxSpec{
Version: "abc21.11.1",
Version: "abc",
Config: &NodeConfig{Image: "ghcr.io/nokia/srlinux:somever"},
},
err: ErrVersionParse,
Expand All @@ -110,7 +110,7 @@ func TestGetImageVersion(t *testing.T) {
{
desc: "version is not present, invalid image tag is given",
spec: &SrlinuxSpec{
Config: &NodeConfig{Image: "ghcr.io/nokia/srlinux:21"},
Config: &NodeConfig{Image: "ghcr.io/nokia/srlinux:somesrl"},
},
err: ErrVersionParse,
},
Expand Down
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ kind: Kustomization
images:
- name: controller
newName: ghcr.io/srl-labs/srl-controller
newTag: 0.4.4
newTag: 0.4.5

0 comments on commit 486959c

Please sign in to comment.