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

update(dashboard): do not set owner on CR #224

Merged
merged 2 commits into from
Mar 20, 2024
Merged
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
3 changes: 2 additions & 1 deletion pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
42 changes: 38 additions & 4 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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/<componentName>" which is
// not present in v1. Since label selectors are immutable, we need to delete the existing
Expand Down
Loading