Skip to content

Commit fad8b54

Browse files
Merge pull request #40 from srl-labs/feat/ignore-license-if-version-parse-fails
feat: dont error out on version parse if we fail, just skip dealing w/ license secret
2 parents 1844b46 + 1cd1e85 commit fad8b54

File tree

5 files changed

+19
-29
lines changed

5 files changed

+19
-29
lines changed

api/v1/srl_version.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55
package v1
66

77
import (
8-
"errors"
98
"regexp"
109
"strings"
1110
)
1211

13-
// ErrVersionParse is an error which is raised when srlinux version is failed to parse.
14-
var ErrVersionParse = errors.New("version parsing failed")
15-
1612
// SrlVersion represents an sr linux version as a set of fields.
1713
type SrlVersion struct {
1814
Major string `json:"major,omitempty"`
@@ -22,12 +18,12 @@ type SrlVersion struct {
2218
Commit string `json:"commit,omitempty"`
2319
}
2420

25-
func parseVersionString(s string) (*SrlVersion, error) {
21+
func parseVersionString(s string) *SrlVersion {
2622
// Check if the version string is an engineering build with major = 0
2723
engineeringVersions := []string{"", "latest", "ga"}
2824
for _, ver := range engineeringVersions {
2925
if ver == strings.ToLower(s) {
30-
return &SrlVersion{"0", "", "", "", ""}, nil
26+
return &SrlVersion{"0", "", "", "", ""}
3127
}
3228
}
3329

@@ -38,8 +34,8 @@ func parseVersionString(s string) (*SrlVersion, error) {
3834

3935
v := re.FindStringSubmatch(s)
4036
if v == nil {
41-
return nil, ErrVersionParse
37+
return &SrlVersion{"0", "", "", "", ""}
4238
}
4339

44-
return &SrlVersion{v[1], v[2], v[3], v[4], v[5]}, nil
40+
return &SrlVersion{v[1], v[2], v[3], v[4], v[5]}
4541
}

api/v1/srl_version_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package v1
66

77
import (
8-
"errors"
98
"testing"
109

1110
"github.com/google/go-cmp/cmp"
@@ -16,7 +15,6 @@ func TestParseVersionString(t *testing.T) {
1615
desc string
1716
got string
1817
want *SrlVersion
19-
err error
2018
}{
2119
{
2220
desc: "maj, minor, patch",
@@ -86,17 +84,13 @@ func TestParseVersionString(t *testing.T) {
8684
{
8785
desc: "invalid1",
8886
got: "abcd",
89-
want: nil,
90-
err: ErrVersionParse,
87+
want: &SrlVersion{"0", "", "", "", ""},
9188
},
9289
}
9390

9491
for _, tt := range tests {
9592
t.Run(tt.desc, func(t *testing.T) {
96-
ver, err := parseVersionString(tt.got)
97-
if !errors.Is(err, tt.err) {
98-
t.Fatalf("got error '%v' but expected '%v'", err, tt.err)
99-
}
93+
ver := parseVersionString(tt.got)
10094

10195
if !cmp.Equal(ver, tt.want) {
10296
t.Fatalf(

api/v1/srlinux_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (s *SrlinuxSpec) GetImage() string {
159159
// When Version field is set it is returned.
160160
// In other cases, Image string is evaluated and it's tag substring is parsed.
161161
// If no tag is present, or tag is latest, the 0.0 version is assumed to be in use.
162-
func (s *SrlinuxSpec) GetImageVersion() (*SrlVersion, error) {
162+
func (s *SrlinuxSpec) GetImageVersion() *SrlVersion {
163163
if s.Version != "" {
164164
return parseVersionString(s.Version)
165165
}

api/v1/srlinux_types_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package v1
66

77
import (
88
"context"
9-
"errors"
109
"testing"
1110

1211
"github.com/google/go-cmp/cmp"
@@ -98,7 +97,7 @@ func TestGetImageVersion(t *testing.T) {
9897
Version: "abc",
9998
Config: &NodeConfig{Image: "ghcr.io/nokia/srlinux:somever"},
10099
},
101-
err: ErrVersionParse,
100+
want: &SrlVersion{"0", "", "", "", ""},
102101
},
103102
{
104103
desc: "version is not present, valid image tag is given",
@@ -112,17 +111,13 @@ func TestGetImageVersion(t *testing.T) {
112111
spec: &SrlinuxSpec{
113112
Config: &NodeConfig{Image: "ghcr.io/nokia/srlinux:somesrl"},
114113
},
115-
err: ErrVersionParse,
114+
want: &SrlVersion{"0", "", "", "", ""},
116115
},
117116
}
118117

119118
for _, tt := range tests {
120119
t.Run(tt.desc, func(t *testing.T) {
121-
v, err := tt.spec.GetImageVersion()
122-
123-
if !errors.Is(err, tt.err) {
124-
t.Fatalf("got error '%v' but expected '%v'", err, tt.err)
125-
}
120+
v := tt.spec.GetImageVersion()
126121

127122
if !cmp.Equal(v, tt.want) {
128123
t.Fatalf(

controllers/secret.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,22 @@ func (r *SrlinuxReconciler) createSecrets(
3131
return err
3232
}
3333

34-
v, err := s.Spec.GetImageVersion()
35-
if err != nil {
36-
return err
34+
v := s.Spec.GetImageVersion()
35+
36+
if v.Major == "0" {
37+
log.Info(
38+
"SR Linux image version could not be parsed, will continue without handling license",
39+
)
40+
41+
return nil
3742
}
3843

3944
log.Info("SR Linux image version parsed", "version", v)
4045

4146
// set license key matching image version
4247
s.InitLicenseKey(ctx, secret, v)
4348

44-
return err
49+
return nil
4550
}
4651

4752
func (r *SrlinuxReconciler) addOrUpdateLicenseSecret(

0 commit comments

Comments
 (0)