Skip to content

Commit

Permalink
Normalize the current Kubernetes versions for Openshift (#130)
Browse files Browse the repository at this point in the history
* Normalize the versions for Openshift

* Add UT
  • Loading branch information
asifdxtreme authored Dec 14, 2021
1 parent cd46ca5 commit 373ac09
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
8 changes: 6 additions & 2 deletions controllers/vdoconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,9 @@ func (r *VDOConfigReconciler) compareVersions(minVersion, currentVersion, maxVer
return false, err
}

currentVer, err := version.NewVersion(currentVersion)
// This is done to normalize the versions having + sign like 1.23+
normalizeCurrentVersion := strings.Replace(currentVersion, "+", "", -1)
currentVer, err := version.NewVersion(normalizeCurrentVersion)
if err != nil {
return false, err
}
Expand All @@ -1140,7 +1142,9 @@ func (r *VDOConfigReconciler) compareVersions(minVersion, currentVersion, maxVer
// compareSkewVersions checks if the given version matches with the skew version
func (r *VDOConfigReconciler) compareSkewVersions(currentVersion, supportedVersion string) (bool, error) {

currentVer, err := version.NewVersion(currentVersion)
// This is done to normalize the versions having + sign like 1.23+
normalizeCurrentVersion := strings.Replace(currentVersion, "+", "", -1)
currentVer, err := version.NewVersion(normalizeCurrentVersion)
if err != nil {
return false, err
}
Expand Down
48 changes: 48 additions & 0 deletions controllers/vdoconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,54 @@ var _ = Describe("TestReconcileNodeProviderID", func() {

})

var _ = Describe("TestCompareVersions", func() {
Context("Compare version with boundaries", func() {
RegisterFailHandler(Fail)

s := scheme.Scheme
s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.VDOConfig{})

r := VDOConfigReconciler{
Client: fake2.NewClientBuilder().WithRuntimeObjects().Build(),
Logger: ctrllog.Log.WithName("VDOConfigControllerTest"),
Scheme: s,
}

result, err := r.compareVersions("1.2.0", "1.3.0", "1.4.0")
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeTrue())

result, err = r.compareVersions("1.2.0", "1.5.0", "1.4.0")
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeFalse())

result, err = r.compareVersions("1.2.0", "1.2.0", "1.2.0")
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeTrue())

result, err = r.compareVersions("1.2.0", "1.2.1", "1.2.0")
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeFalse())

result, err = r.compareVersions("1.2.0", "1.2+", "1.2.2")
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeTrue())

result, err = r.compareSkewVersions("1.2.0", "1.2.0")
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeTrue())

result, err = r.compareSkewVersions("1.2.0", "1.1.0")
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeFalse())

result, err = r.compareSkewVersions("1.2+", "1.2.0")
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeTrue())

})
})

var _ = Describe("TestReconcileNodeLabel", func() {
node1 := v12.Node{
ObjectMeta: metav1.ObjectMeta{Name: "test-node1"},
Expand Down

0 comments on commit 373ac09

Please sign in to comment.