From 3c8fbfca7445189721a461a168db5f0aeacc1c07 Mon Sep 17 00:00:00 2001 From: Anuj Chaudhari Date: Tue, 3 May 2022 12:14:21 -0700 Subject: [PATCH] Consider additional metadata as part of k8s's build version --- pkg/v1/tkg/utils/common.go | 7 ++-- pkg/v1/tkg/utils/common_test.go | 57 +++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/pkg/v1/tkg/utils/common.go b/pkg/v1/tkg/utils/common.go index 4ff1983a0d2..b4b0dd41a14 100644 --- a/pkg/v1/tkg/utils/common.go +++ b/pkg/v1/tkg/utils/common.go @@ -114,8 +114,11 @@ func CompareVMwareVersionStrings(v1, v2 string) (int, error) { return compareResult, nil } - v1VmwareBuildVersion, err1 := strconv.Atoi(v1s[1]) - v2VmwareBuildVersion, err2 := strconv.Atoi(v2s[1]) + buildVersionV1 := strings.Split(v1s[1], "-") + buildVersionV2 := strings.Split(v2s[1], "-") + + v1VmwareBuildVersion, err1 := strconv.Atoi(buildVersionV1[0]) + v2VmwareBuildVersion, err2 := strconv.Atoi(buildVersionV2[0]) if err1 != nil || err2 != nil { return 0, errors.New("invalid version string") } diff --git a/pkg/v1/tkg/utils/common_test.go b/pkg/v1/tkg/utils/common_test.go index 9a8548497d2..b255814a500 100644 --- a/pkg/v1/tkg/utils/common_test.go +++ b/pkg/v1/tkg/utils/common_test.go @@ -16,6 +16,8 @@ var ( k8sv1174 = "v1.17.4+vmware.2" k8sv1182 = "v1.18.2+vmware.2" k8sv1191 = "v1.19.1+vmware.2" + k8sv11731Fips1 = "v1.17.3+vmware.1-fips.1" + k8sv11732Fips1 = "v1.17.3+vmware.2-fips.1" vABC = "vA.B.C" fakePathABC = "gcr.io/fakepath/tkg/kind/node:vA.B.C" tkrNameSample = "tkr---version" @@ -413,6 +415,61 @@ var _ = Describe("CompareVMwareVersionStrings", func() { Expect(err).To(MatchError("invalid version string")) }) }) + + Context("When buildVersion includes more information about fips etc", func() { + BeforeEach(func() { + fromVersion = k8sv11731Fips1 + toVersion = "v1.17.4+vmware.1-fips.1" + }) + It("expect compareResult < 0", func() { + Expect(err).NotTo(HaveOccurred()) + Expect(compareResult < 0).To(Equal(true)) + }) + }) + + Context("When buildVersion includes more information about fips etc and buildVersion is different", func() { + BeforeEach(func() { + fromVersion = k8sv11731Fips1 + toVersion = k8sv11732Fips1 + }) + It("expect compareResult < 0", func() { + Expect(err).NotTo(HaveOccurred()) + Expect(compareResult < 0).To(Equal(true)) + }) + }) + + Context("When buildVersion includes more information about fips etc and buildVersion is different", func() { + BeforeEach(func() { + fromVersion = k8sv11732Fips1 + toVersion = k8sv11731Fips1 + }) + It("expect compareResult > 0", func() { + Expect(err).NotTo(HaveOccurred()) + Expect(compareResult > 0).To(Equal(true)) + }) + }) + + Context("When buildVersion includes more information about fips etc and buildVersion are same", func() { + BeforeEach(func() { + fromVersion = k8sv11731Fips1 + toVersion = k8sv11731Fips1 + }) + It("expect compareResult = 0", func() { + Expect(err).NotTo(HaveOccurred()) + Expect(compareResult == 0).To(Equal(true)) + }) + }) + + Context("When buildVersion includes more information about fips and fips build version are different", func() { + BeforeEach(func() { + fromVersion = k8sv11731Fips1 + toVersion = "v1.17.3+vmware.1-fips.2" + }) + It("expect compareResult = 0", func() { + Expect(err).NotTo(HaveOccurred()) + Expect(compareResult == 0).To(Equal(true)) + }) + }) }) var _ = Describe("GenerateRandomID", func() {