From 14b68c2789f8af699d213cbf3ec69a13a63409a9 Mon Sep 17 00:00:00 2001 From: Gerard Nguyen Date: Tue, 30 Jul 2024 16:45:39 +1000 Subject: [PATCH] parse k8s minor version for eks --- pkg/k8sutil/clientset.go | 11 ++++++++++- pkg/k8sutil/clientset_test.go | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/k8sutil/clientset.go b/pkg/k8sutil/clientset.go index 99de2ae6..d10ec51f 100644 --- a/pkg/k8sutil/clientset.go +++ b/pkg/k8sutil/clientset.go @@ -1,6 +1,7 @@ package k8sutil import ( + "regexp" "strconv" "github.com/pkg/errors" @@ -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") } diff --git a/pkg/k8sutil/clientset_test.go b/pkg/k8sutil/clientset_test.go index 51ecb61a..bbbd66ae 100644 --- a/pkg/k8sutil/clientset_test.go +++ b/pkg/k8sutil/clientset_test.go @@ -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) {