Skip to content

Commit

Permalink
pkg/upgrade: convert unsetOwnerReference to Action
Browse files Browse the repository at this point in the history
Signed-off-by: Yauheni Kaliuta <[email protected]>
  • Loading branch information
ykaliuta committed Apr 26, 2024
1 parent d1f65c8 commit 3e2f205
Showing 1 changed file with 7 additions and 27 deletions.
34 changes: 7 additions & 27 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/client"

kfdefv1 "github.com/opendatahub-io/opendatahub-operator/apis/kfdef.apps.kubeflow.org/v1"
Expand Down Expand Up @@ -382,31 +380,13 @@ func RemoveKfDefInstances(ctx context.Context, cli client.Client) error {
}

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
return action.NewDeleteOwnersReferences(cli).
Exec(context.TODO(), action.ResourceSpec{
Gvk: gvk.OdhDashboardConfig,
Namespace: applicationNS,
Path: []string{"metadata", "name"},
Values: []string{instanceName},
})
}

func deleteResource(cli client.Client, namespace string, resourceType string) error {
Expand Down

0 comments on commit 3e2f205

Please sign in to comment.