diff --git a/controllers/hyperconverged/hyperconverged_controller.go b/controllers/hyperconverged/hyperconverged_controller.go index b40729b31..a0c2416e3 100644 --- a/controllers/hyperconverged/hyperconverged_controller.go +++ b/controllers/hyperconverged/hyperconverged_controller.go @@ -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" @@ -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 @@ -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 { diff --git a/controllers/hyperconverged/hyperconverged_controller_test.go b/controllers/hyperconverged/hyperconverged_controller_test.go index 5c78331e0..66d75c438 100644 --- a/controllers/hyperconverged/hyperconverged_controller_test.go +++ b/controllers/hyperconverged/hyperconverged_controller_test.go @@ -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" diff --git a/controllers/hyperconverged/hyperconverged_suite_test.go b/controllers/hyperconverged/hyperconverged_suite_test.go index 6f362c2ee..de4e028b1 100644 --- a/controllers/hyperconverged/hyperconverged_suite_test.go +++ b/controllers/hyperconverged/hyperconverged_suite_test.go @@ -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 (