Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MGDAPI-5837 remove uninstall logic from rhoam #3375

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 0 additions & 5 deletions pkg/addon/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strconv"

integreatlyv1alpha1 "github.com/integr8ly/integreatly-operator/apis/v1alpha1"
l "github.com/integr8ly/integreatly-operator/pkg/resources/logger"
corev1 "k8s.io/api/core/v1"
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -21,10 +20,6 @@ const (
DefaultSecretName = "addon-managed-api-service-parameters"
)

var (
log = l.NewLoggerWithContext(l.Fields{l.ComponentLogContext: "addon"})
)

// GetParameter retrieves the value for an addon parameter by finding the Subscription
// CR and selecting the addon name from a secret associated with it.
func GetParameter(ctx context.Context, client k8sclient.Client, namespace, parameter string) ([]byte, bool, error) {
Expand Down
67 changes: 0 additions & 67 deletions pkg/addon/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,16 @@ 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
scheme *runtime.Scheme
client k8sclient.Client
}

var _ admission.Handler = &deleteRHMIHandler{}
Expand Down Expand Up @@ -85,28 +41,5 @@ 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")
}

func (h *deleteRHMIHandler) getClient() (k8sclient.Client, error) {
if h.client == nil {
c, err := k8sclient.New(h.restConfig, k8sclient.Options{
Scheme: h.scheme,
})
if err != nil {
return nil, err
}
h.client = c
}

return h.client, nil
}