Skip to content

Commit

Permalink
pkg/upgrade: use common function instead of removOdhApplicationsCR
Browse files Browse the repository at this point in the history
With ignoring NoKindMatchError error deleteResources() code should
work for the purpose of removOdhApplicationsCR as well.

Signed-off-by: Yauheni Kaliuta <[email protected]>
  • Loading branch information
ykaliuta committed Apr 8, 2024
1 parent a206bbe commit c4557c1
Showing 1 changed file with 9 additions and 29 deletions.
38 changes: 9 additions & 29 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c4557c1

Please sign in to comment.