diff --git a/pkg/deploy/deploy.go b/pkg/deploy/deploy.go index 6b08c69fdd6..09636bff6ff 100644 --- a/pkg/deploy/deploy.go +++ b/pkg/deploy/deploy.go @@ -274,7 +274,8 @@ func manageResource(ctx context.Context, cli client.Client, obj *unstructured.Un if apierrs.IsNotFound(err) { // Set the owner reference for garbage collection // Skip set on CRD, e.g. we should not delete notebook CRD if we delete DSC instance - if found.GetKind() != "CustomResourceDefinition" { + // Skip on OdhDashboardConfig CR, because we want user to be able to update it + if found.GetKind() != "CustomResourceDefinition" || found.GetKind() != "OdhDashboardConfig" { if err = ctrl.SetControllerReference(owner, metav1.Object(obj), cli.Scheme()); err != nil { return err } diff --git a/pkg/upgrade/upgrade.go b/pkg/upgrade/upgrade.go index fdb9f38d4cc..e187e0f7c8d 100644 --- a/pkg/upgrade/upgrade.go +++ b/pkg/upgrade/upgrade.go @@ -206,7 +206,7 @@ func CreateDefaultDSC(cli client.Client, _ deploy.Platform) error { fmt.Printf("created DataScienceCluster resource\n") case apierrs.IsAlreadyExists(err): // Do not update the DSC if it already exists - fmt.Printf("DataScienceCluster resource already exists. It will not be updated with default DSC.\n") + fmt.Println("DataScienceCluster resource already exists. It will not be updated with default DSC.") return nil default: return fmt.Errorf("failed to create DataScienceCluster custom resource: %w", err) @@ -255,14 +255,14 @@ func CreateDefaultDSCI(cli client.Client, _ deploy.Platform, appNamespace, monNa switch { case len(instances.Items) > 1: - fmt.Printf("only one instance of DSCInitialization object is allowed. Please delete other instances.\n") + fmt.Println("only one instance of DSCInitialization object is allowed. Please delete other instances.") return nil case len(instances.Items) == 1: // Do not patch/update if DSCI already exists. - fmt.Printf("DSCInitialization resource already exists. It will not be updated with default DSCI.") + fmt.Println("DSCInitialization resource already exists. It will not be updated with default DSCI.") return nil case len(instances.Items) == 0: - fmt.Printf("create default DSCI CR.") + fmt.Println("create default DSCI CR.") err := cli.Create(context.TODO(), defaultDsci) if err != nil { return err @@ -285,6 +285,9 @@ func UpdateFromLegacyVersion(cli client.Client, platform deploy.Platform, appNS if err := deleteResource(cli, montNamespace, "statefulset"); err != nil { return err } + if err := unsetOwnerReference(cli, "odh-dashboard-config", appNS); err != nil { + return err + } fmt.Println("creating default DSC CR") if err := CreateDefaultDSC(cli, platform); err != nil { return err @@ -323,6 +326,9 @@ func UpdateFromLegacyVersion(cli client.Client, platform deploy.Platform, appNS if err := deleteResource(cli, montNamespace, "statefulset"); err != nil { return err } + if err := unsetOwnerReference(cli, "odh-dashboard-config", appNS); err != nil { + return err + } // create default DSC if err = CreateDefaultDSC(cli, platform); err != nil { return err @@ -556,6 +562,34 @@ func removOdhApplicationsCR(ctx context.Context, cli client.Client, gvk schema.G return nil } +func unsetOwnerReference(cli client.Client, instanceName string, applicationNS string) error { + OdhDashboardConfig := schema.GroupVersionKind{ + Group: "opendatahub.io", + Version: "v1alpha", + Kind: "OdhDashboardConfig", + } + crd := &apiextv1.CustomResourceDefinition{} + if err := cli.Get(context.TODO(), client.ObjectKey{Name: "odhdashboardconfigs.opendatahub.io"}, crd); err != nil { + return client.IgnoreNotFound(err) + } + odhObject := &unstructured.Unstructured{} + odhObject.SetGroupVersionKind(OdhDashboardConfig) + if err := cli.Get(context.TODO(), client.ObjectKey{ + Namespace: applicationNS, + Name: instanceName, + }, odhObject); err != nil { + return client.IgnoreNotFound(err) + } + if odhObject.GetOwnerReferences() != nil { + // set to nil as updates + odhObject.SetOwnerReferences(nil) + if err := cli.Update(context.TODO(), odhObject); err != nil { + return fmt.Errorf("error unset ownerreference for CR %s : %w", instanceName, err) + } + } + return nil +} + func deleteResource(cli client.Client, namespace string, resourceType string) error { // In v2, Deployment selectors use a label "app.opendatahub.io/" which is // not present in v1. Since label selectors are immutable, we need to delete the existing