From 9a8dc12daa824694fd3fc63ff238deea51c5c6a0 Mon Sep 17 00:00:00 2001 From: Austin Cunningham Date: Fri, 22 Sep 2023 12:56:12 +0100 Subject: [PATCH] MGDAPI-5837 remove uninstall logic from rhoam --- controllers/rhmi/rhmi_controller.go | 6 ---- pkg/addon/uninstall.go | 51 ----------------------------- 2 files changed, 57 deletions(-) diff --git a/controllers/rhmi/rhmi_controller.go b/controllers/rhmi/rhmi_controller.go index f590fcfc55..1a9dcaf96b 100644 --- a/controllers/rhmi/rhmi_controller.go +++ b/controllers/rhmi/rhmi_controller.go @@ -638,12 +638,6 @@ func (r *RHMIReconciler) handleUninstall(installation *rhmiv1alpha1.RHMI, instal return ctrl.Result{}, merr } - err = addon.UninstallOperator(context.TODO(), r.Client, installation) - if err != nil { - merr.Add(err) - return ctrl.Result{}, merr - } - log.Info("uninstall completed") return ctrl.Result{}, nil } diff --git a/pkg/addon/uninstall.go b/pkg/addon/uninstall.go index 9f0ef73a64..de2f0122cb 100644 --- a/pkg/addon/uninstall.go +++ b/pkg/addon/uninstall.go @@ -4,55 +4,13 @@ import ( "context" "net/http" - l "github.com/integr8ly/integreatly-operator/pkg/resources/logger" - integreatlyv1alpha1 "github.com/integr8ly/integreatly-operator/apis/v1alpha1" - operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" - k8serr "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/rest" k8sclient "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" ) -// UninstallOperator uninstalls the RHMI operator by deleting the CSV. -// If the subscription is not found, it doesn't do anything, as the -// operator might not be run through OLM -func UninstallOperator(ctx context.Context, client k8sclient.Client, installation *integreatlyv1alpha1.RHMI) error { - // Get the operator subscription - subscription, err := GetSubscription(ctx, client, installation) - if err != nil { - return err - } - - // If the subscription is not found, finish: the operator might have been - // running locally - if subscription == nil { - return nil - } - - // Retrieve the operator CSV - csv := &operatorsv1alpha1.ClusterServiceVersion{} - err = client.Get(ctx, k8sclient.ObjectKey{ - Name: subscription.Status.InstalledCSV, - Namespace: installation.Namespace, - }, csv) - // If there's an unexpected error, return it - if err != nil && !k8serr.IsNotFound(err) { - return err - } - - // If the CSV wasn't found, there is nothing left to delete - if k8serr.IsNotFound(err) { - return nil - } - - log.Infof("Deleting operator CSV", l.Fields{"name": csv.Name}) - - // Delete the CSV - return client.Delete(ctx, csv) -} - type deleteRHMIHandler struct { decoder *admission.Decoder restConfig *rest.Config @@ -85,15 +43,6 @@ func (h *deleteRHMIHandler) Handle(ctx context.Context, request admission.Reques return admission.Allowed("RHMI CR has finalizers") } - client, err := h.getClient() - if err != nil { - return admission.Errored(http.StatusInternalServerError, err) - } - - if err := UninstallOperator(ctx, client, rhmi); err != nil { - return admission.Errored(http.StatusInternalServerError, err) - } - return admission.Allowed("Operator Uninstalled") }