Skip to content

Commit

Permalink
parse k8s minor version for eks (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
nvanthao authored Jul 30, 2024
1 parent 5e8dbc2 commit 49b4b6e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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

0 comments on commit 49b4b6e

Please sign in to comment.