From c4557c10cd178943efc2a5e7644ba24904ec20ce Mon Sep 17 00:00:00 2001 From: Yauheni Kaliuta Date: Mon, 8 Apr 2024 22:44:31 +0300 Subject: [PATCH] pkg/upgrade: use common function instead of removOdhApplicationsCR With ignoring NoKindMatchError error deleteResources() code should work for the purpose of removOdhApplicationsCR as well. Signed-off-by: Yauheni Kaliuta --- pkg/upgrade/upgrade.go | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/pkg/upgrade/upgrade.go b/pkg/upgrade/upgrade.go index ab24fa3971e..b429aca2cb9 100644 --- a/pkg/upgrade/upgrade.go +++ b/pkg/upgrade/upgrade.go @@ -343,19 +343,22 @@ func CleanupExistingResource(ctx context.Context, cli client.Client, platform de } // common logic for both self-managed and managed - del := JobSpec{ + toDelete = append(toDelete, JobSpec{ Gvk: gvkServiceMonitor, Namespace: dscMonitoringNamespace, Path: pathName, Values: []string{"rhods-monitor-federation2"}, - } + }) - toDelete = append(toDelete, del) + // Handling for dashboard Jupyterhub CR, see jira #443 + toDelete = append(toDelete, JobSpec{ + Gvk: gvkOdhApplication, + Namespace: dscApplicationsNamespace, + Path: pathName, + Values: []string{"jupiterhub"}, + }) multiErr = multierror.Append(multiErr, deleteResources(ctx, cli, &toDelete)) - - // Handling for dashboard Jupyterhub CR, see jira #443 - multiErr = multierror.Append(multiErr, removOdhApplicationsCR(ctx, cli, gvkOdhApplication, "jupyterhub", dscApplicationsNamespace)) return multiErr.ErrorOrNil() } @@ -443,29 +446,6 @@ func RemoveKfDefInstances(ctx context.Context, cli client.Client) error { return nil } -func removOdhApplicationsCR(ctx context.Context, cli client.Client, gvk schema.GroupVersionKind, instanceName string, applicationNS string) error { - // first check if CRD in cluster - crd := &apiextv1.CustomResourceDefinition{} - if err := cli.Get(ctx, client.ObjectKey{Name: "odhapplications.dashboard.opendatahub.io"}, crd); err != nil { - return client.IgnoreNotFound(err) - } - - // then check if CR in cluster to delete - odhObject := &unstructured.Unstructured{} - odhObject.SetGroupVersionKind(gvk) - if err := cli.Get(ctx, client.ObjectKey{ - Namespace: applicationNS, - Name: instanceName, - }, odhObject); err != nil { - return client.IgnoreNotFound(err) - } - if err := cli.Delete(ctx, odhObject); err != nil { - return fmt.Errorf("error deleting CR %s : %w", instanceName, err) - } - - return nil -} - func unsetOwnerReference(cli client.Client, instanceName string, applicationNS string) error { crd := &apiextv1.CustomResourceDefinition{} if err := cli.Get(context.TODO(), client.ObjectKey{Name: "odhdashboardconfigs.opendatahub.io"}, crd); err != nil {