Skip to content

Commit

Permalink
Drop code that clean v1alpha1 CRD version
Browse files Browse the repository at this point in the history
This API version is very old, and there is no need to remove it anymore.

Signed-off-by: Nahshon Unna-Tsameret <[email protected]>
  • Loading branch information
nunnatsa committed Dec 26, 2024
1 parent cc13889 commit 8e97220
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 113 deletions.
49 changes: 0 additions & 49 deletions controllers/hyperconverged/hyperconverged_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
schedulingv1 "k8s.io/api/scheduling/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
apimetav1 "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -444,16 +443,6 @@ func (r *ReconcileHyperConverged) doReconcile(req *common.HcoRequest) (reconcile
}

func (r *ReconcileHyperConverged) handleUpgrade(req *common.HcoRequest) (*reconcile.Result, error) {

crdStatusUpdated, err := r.updateCrdStoredVersions(req)
if err != nil {
return &reconcile.Result{Requeue: true}, err
}

if crdStatusUpdated {
return &reconcile.Result{Requeue: true}, nil
}

modified, err := r.migrateBeforeUpgrade(req)
if err != nil {
return &reconcile.Result{Requeue: true}, err
Expand Down Expand Up @@ -1102,44 +1091,6 @@ func (r *ReconcileHyperConverged) setOperatorUpgradeableStatus(request *common.H
return nil
}

const crdName = "hyperconvergeds.hco.kubevirt.io"

func (r *ReconcileHyperConverged) updateCrdStoredVersions(req *common.HcoRequest) (bool, error) {
versionsToBeRemoved := []string{"v1alpha1"}

found := &apiextensionsv1.CustomResourceDefinition{}
key := client.ObjectKey{Namespace: hcoutil.UndefinedNamespace, Name: crdName}
err := r.client.Get(req.Ctx, key, found)
if err != nil {
req.Logger.Error(err, fmt.Sprintf("failed to read the %s CRD; %s", crdName, err.Error()))
return false, err
}

needsUpdate := false
var newStoredVersions []string
for _, vToBeRemoved := range versionsToBeRemoved {
for _, sVersion := range found.Status.StoredVersions {
if vToBeRemoved != sVersion {
newStoredVersions = append(newStoredVersions, sVersion)
} else {
needsUpdate = true
}
}
}
if needsUpdate {
found.Status.StoredVersions = newStoredVersions
err = r.client.Status().Update(req.Ctx, found)
if err != nil {
req.Logger.Error(err, fmt.Sprintf("failed updating the %s CRD status: %s", crdName, err.Error()))
return false, err
}
req.Logger.Info("successfully updated status.storedVersions on HCO CRD", "CRD Name", crdName)
return true, nil
}

return false, nil
}

func (r *ReconcileHyperConverged) migrateBeforeUpgrade(req *common.HcoRequest) (bool, error) {
upgradePatched, err := r.applyUpgradePatches(req)
if err != nil {
Expand Down
60 changes: 0 additions & 60 deletions controllers/hyperconverged/hyperconverged_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1730,66 +1730,6 @@ var _ = Describe("HyperconvergedController", func() {
),
)

Context("Remove deprecated versions from .status.storedVersions on the CRD", func() {

It("should update .status.storedVersions on the HCO CRD during upgrades", func() {
// Simulate ongoing upgrade
UpdateVersion(&expected.hco.Status, hcoVersionName, oldVersion)

expected.hcoCRD.Status.StoredVersions = []string{"v1alpha1", "v1beta1", "v1"}

cl := expected.initClient()

foundHC, reconciler, requeue := doReconcile(cl, expected.hco, nil)
Expect(requeue).To(BeTrue())

foundCrd := &apiextensionsv1.CustomResourceDefinition{}
Expect(
cl.Get(context.TODO(),
client.ObjectKeyFromObject(expected.hcoCRD),
foundCrd),
).To(Succeed())
Expect(foundCrd.Status.StoredVersions).ToNot(ContainElement("v1alpha1"))
Expect(foundCrd.Status.StoredVersions).To(ContainElement("v1beta1"))
Expect(foundCrd.Status.StoredVersions).To(ContainElement("v1"))

By("Run reconcile again")
foundHC, reconciler, requeue = doReconcile(cl, foundHC, reconciler)
Expect(requeue).To(BeTrue())

// call again, make sure this time the requeue is false and the upgrade successfully completes
foundHC, _, requeue = doReconcile(cl, foundHC, reconciler)
Expect(requeue).To(BeFalse())

checkAvailability(foundHC, metav1.ConditionTrue)
ver, ok := GetVersion(&foundHC.Status, hcoVersionName)
Expect(ok).To(BeTrue())
Expect(ver).To(Equal(newHCOVersion))
})

It("should not update .status.storedVersions on the HCO CRD if not in upgrade mode", func() {
expected.hcoCRD.Status.StoredVersions = []string{"v1alpha1", "v1beta1", "v1"}

cl := expected.initClient()

foundHC, _, requeue := doReconcile(cl, expected.hco, nil)
checkAvailability(foundHC, metav1.ConditionTrue)
Expect(requeue).To(BeFalse())

foundCrd := &apiextensionsv1.CustomResourceDefinition{}
Expect(
cl.Get(context.TODO(),
client.ObjectKeyFromObject(expected.hcoCRD),
foundCrd),
).To(Succeed())
Expect(foundCrd.Status.StoredVersions).To(ContainElement("v1alpha1"))
Expect(foundCrd.Status.StoredVersions).To(ContainElement("v1beta1"))
Expect(foundCrd.Status.StoredVersions).To(ContainElement("v1"))

})

})

Context("Amend bad defaults", func() {
const (
badBandwidthPerMigration = "64Mi"
Expand Down
8 changes: 4 additions & 4 deletions controllers/hyperconverged/hyperconverged_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package hyperconverged

import (
"github.com/kubevirt/hyperconverged-cluster-operator/pkg/upgradepatches"
"os"
"path"
"strings"
"testing"

"github.com/kubevirt/hyperconverged-cluster-operator/controllers/commontestutils"
hcoutil "github.com/kubevirt/hyperconverged-cluster-operator/pkg/util"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/kubevirt/hyperconverged-cluster-operator/controllers/commontestutils"
"github.com/kubevirt/hyperconverged-cluster-operator/pkg/upgradepatches"
hcoutil "github.com/kubevirt/hyperconverged-cluster-operator/pkg/util"
)

const (
Expand Down

0 comments on commit 8e97220

Please sign in to comment.