Skip to content

Commit fe6b1c7

Browse files
xavpaicebanjoh
andauthored
Add workaround for EKS version string (#1449)
* Add workaround for EKS version string The EKS version string returned is not semver compliant. To work around this, we remove the suffix for version strings that contain -eks-. Fixes #1441 * Add parsing version test cases * Rename function --------- Co-authored-by: Evans Mungai <[email protected]>
1 parent 710366c commit fe6b1c7

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

pkg/analyze/cluster_version.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func analyzeClusterVersion(analyzer *troubleshootv1beta2.ClusterVersion, getColl
4242
return nil, errors.Wrap(err, "failed to parse cluster_version.json")
4343
}
4444

45-
k8sVersion, err := semver.Make(strings.TrimLeft(collectorClusterVersion.String, "v"))
45+
k8sVersion, err := parseK8sVersionString(collectorClusterVersion.String)
4646
if err != nil {
4747
return nil, errors.Wrap(err, "failed to parse semver from cluster_version.json")
4848
}
@@ -58,6 +58,16 @@ func title(checkName string) string {
5858
return checkName
5959
}
6060

61+
func parseK8sVersionString(version string) (semver.Version, error) {
62+
// Workaround for https://github.com/aws/containers-roadmap/issues/1404
63+
// for EKS, replace pre-release gitVersion string with the release version
64+
if strings.Contains(version, "-eks-") {
65+
version = strings.Split(version, "-")[0]
66+
}
67+
68+
return semver.Make(strings.TrimLeft(version, "v"))
69+
}
70+
6171
func analyzeClusterVersionResult(k8sVersion semver.Version, outcomes []*troubleshootv1beta2.Outcome, checkName string) (*AnalyzeResult, error) {
6272
for _, outcome := range outcomes {
6373
when := ""

pkg/analyze/cluster_version_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/blang/semver/v4"
88
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
9+
"github.com/stretchr/testify/assert"
910
)
1011

1112
func Test_analyzeClusterVersionResult(t *testing.T) {
@@ -103,3 +104,41 @@ func Test_analyzeClusterVersionResult(t *testing.T) {
103104
})
104105
}
105106
}
107+
108+
func Test_parseVersionString(t *testing.T) {
109+
tests := []struct {
110+
name string
111+
rawVersion string
112+
want semver.Version
113+
wantErr bool
114+
}{
115+
{
116+
name: "valid version",
117+
rawVersion: "1.17.0",
118+
want: semver.MustParse("1.17.0"),
119+
},
120+
{
121+
name: "valid version with v prefix",
122+
rawVersion: "v1.17.0",
123+
want: semver.MustParse("1.17.0"),
124+
},
125+
{
126+
name: "invalid version",
127+
rawVersion: "v1.17",
128+
want: semver.Version{},
129+
wantErr: true,
130+
},
131+
{
132+
name: "EKS version",
133+
rawVersion: "v1.25.16-eks-8cb36c9",
134+
want: semver.MustParse("1.25.16"),
135+
},
136+
}
137+
for _, tt := range tests {
138+
t.Run(tt.name, func(t *testing.T) {
139+
got, err := parseK8sVersionString(tt.rawVersion)
140+
assert.Equal(t, tt.wantErr, err != nil, "parseVersionString() error = %v, wantErr %v", err, tt.wantErr)
141+
assert.Equal(t, tt.want, got, "parseVersionString() = %v, want %v", got, tt.want)
142+
})
143+
}
144+
}

0 commit comments

Comments
 (0)