Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [sc-109535] k8s minor version parsing error #198

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pkg/k8sutil/clientset.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package k8sutil

import (
"regexp"
"strconv"

"github.com/pkg/errors"
Expand Down Expand Up @@ -76,7 +77,15 @@ func GetK8sMinorVersion(clientset kubernetes.Interface) (int, error) {
return -1, errors.Wrap(err, "failed to get kubernetes server version")
}

k8sMinorVersion, err := strconv.Atoi(k8sVersion.Minor)
// remove + sign from Minor version if any (for EKS)
// https://github.com/aws/containers-roadmap/issues/1404
reg := regexp.MustCompile(`[0-9]+`)
minorVersion := reg.FindString(k8sVersion.Minor)
if minorVersion == "" {
return -1, errors.New("failed to get k8s minor version")
}

k8sMinorVersion, err := strconv.Atoi(minorVersion)
if err != nil {
return -1, errors.Wrap(err, "failed to convert k8s minor version to int")
}
Expand Down
1 change: 1 addition & 0 deletions pkg/k8sutil/clientset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestGetK8sMinorVersion(t *testing.T) {
{"expect minor version 22", args{mockClientsetK8sVersion("1", "22")}, 22, false},
{"expect minor version 21", args{mockClientsetK8sVersion("1", "21")}, 21, false},
{"expect minor version conversion error", args{mockClientsetK8sVersion("1", "a")}, -1, true},
{"expect minor version 30", args{mockClientsetK8sVersion("1", "30+")}, 30, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading