Skip to content

Commit

Permalink
MGDAPI-5837 remove uninstall logic from rhoam
Browse files Browse the repository at this point in the history
  • Loading branch information
austincunningham committed Sep 22, 2023
1 parent 121bdd1 commit 9a8dc12
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 57 deletions.
6 changes: 0 additions & 6 deletions controllers/rhmi/rhmi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
51 changes: 0 additions & 51 deletions pkg/addon/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}

Expand Down

0 comments on commit 9a8dc12

Please sign in to comment.