Skip to content

Commit

Permalink
Add workaround for EKS version string (#1449)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
xavpaice and banjoh authored Feb 5, 2024
1 parent 710366c commit fe6b1c7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/analyze/cluster_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func analyzeClusterVersion(analyzer *troubleshootv1beta2.ClusterVersion, getColl
return nil, errors.Wrap(err, "failed to parse cluster_version.json")
}

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

func parseK8sVersionString(version string) (semver.Version, error) {
// Workaround for https://github.com/aws/containers-roadmap/issues/1404
// for EKS, replace pre-release gitVersion string with the release version
if strings.Contains(version, "-eks-") {
version = strings.Split(version, "-")[0]
}

return semver.Make(strings.TrimLeft(version, "v"))
}

func analyzeClusterVersionResult(k8sVersion semver.Version, outcomes []*troubleshootv1beta2.Outcome, checkName string) (*AnalyzeResult, error) {
for _, outcome := range outcomes {
when := ""
Expand Down
39 changes: 39 additions & 0 deletions pkg/analyze/cluster_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/blang/semver/v4"
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
"github.com/stretchr/testify/assert"
)

func Test_analyzeClusterVersionResult(t *testing.T) {
Expand Down Expand Up @@ -103,3 +104,41 @@ func Test_analyzeClusterVersionResult(t *testing.T) {
})
}
}

func Test_parseVersionString(t *testing.T) {
tests := []struct {
name string
rawVersion string
want semver.Version
wantErr bool
}{
{
name: "valid version",
rawVersion: "1.17.0",
want: semver.MustParse("1.17.0"),
},
{
name: "valid version with v prefix",
rawVersion: "v1.17.0",
want: semver.MustParse("1.17.0"),
},
{
name: "invalid version",
rawVersion: "v1.17",
want: semver.Version{},
wantErr: true,
},
{
name: "EKS version",
rawVersion: "v1.25.16-eks-8cb36c9",
want: semver.MustParse("1.25.16"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseK8sVersionString(tt.rawVersion)
assert.Equal(t, tt.wantErr, err != nil, "parseVersionString() error = %v, wantErr %v", err, tt.wantErr)
assert.Equal(t, tt.want, got, "parseVersionString() = %v, want %v", got, tt.want)
})
}
}

0 comments on commit fe6b1c7

Please sign in to comment.