Skip to content

Commit

Permalink
update: cleanup remove kfdef during uninstallation (opendatahub-io#1100)
Browse files Browse the repository at this point in the history
- also clean kfdef reference

Signed-off-by: Wen Zhou <wenzhou@redhat.com>
  • Loading branch information
zdtsw authored Jul 10, 2024
1 parent 973ff74 commit 60a44c2
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 87 deletions.
19 changes: 1 addition & 18 deletions bundle/manifests/opendatahub-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -898,24 +898,6 @@ spec:
- list
- patch
- watch
- apiGroups:
- kfdef.apps.kubeflow.org
resources:
- kfdefs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- kubeflow.org
resources:
- '*'
verbs:
- '*'
- apiGroups:
- machine.openshift.io
resources:
Expand Down Expand Up @@ -1824,6 +1806,7 @@ spec:
operations:
- CREATE
- UPDATE
- DELETE
resources:
- datascienceclusters
- dscinitializations
Expand Down
18 changes: 0 additions & 18 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -713,24 +713,6 @@ rules:
- list
- patch
- watch
- apiGroups:
- kfdef.apps.kubeflow.org
resources:
- kfdefs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- kubeflow.org
resources:
- '*'
verbs:
- '*'
- apiGroups:
- machine.openshift.io
resources:
Expand Down
4 changes: 0 additions & 4 deletions controllers/datasciencecluster/kubebuilder_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ package datasciencecluster
// +kubebuilder:rbac:groups="machine.openshift.io",resources=machinesets,verbs=list;patch;delete;get
// +kubebuilder:rbac:groups="machine.openshift.io",resources=machineautoscalers,verbs=list;patch;delete;get

/* TODO: cleanup once kfdef is not needed*/
// +kubebuilder:rbac:groups="kubeflow.org",resources=*,verbs=*
// +kubebuilder:rbac:groups="kfdef.apps.kubeflow.org",resources=kfdefs,verbs=get;list;watch;patch;delete;update

// +kubebuilder:rbac:groups="integreatly.org",resources=rhmis,verbs=list;watch;patch;delete;get

// +kubebuilder:rbac:groups="image.openshift.io",resources=imagestreams,verbs=patch;create;update;delete;get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ type DSCInitializationReconciler struct {
// +kubebuilder:rbac:groups="dscinitialization.opendatahub.io",resources=dscinitializations,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="features.opendatahub.io",resources=featuretrackers,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="features.opendatahub.io",resources=featuretrackers/status,verbs=get;update;patch;delete
// +kubebuilder:rbac:groups="kfdef.apps.kubeflow.org",resources=kfdefs,verbs=get;list;watch;create;update;patch;delete

// Reconcile contains controller logic specific to DSCInitialization instance updates.
func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { //nolint:funlen,gocyclo,maintidx
Expand Down
2 changes: 0 additions & 2 deletions controllers/dscinitialization/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

kfdefv1 "github.com/opendatahub-io/opendatahub-operator/apis/kfdef.apps.kubeflow.org/v1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
dsci "github.com/opendatahub-io/opendatahub-operator/v2/controllers/dscinitialization"
Expand Down Expand Up @@ -115,7 +114,6 @@ var _ = BeforeSuite(func() {
utilruntime.Must(ofapiv2.AddToScheme(testScheme))
utilruntime.Must(routev1.Install(testScheme))
utilruntime.Must(userv1.Install(testScheme))
utilruntime.Must(kfdefv1.AddToScheme(testScheme))
utilruntime.Must(monitoringv1.AddToScheme(testScheme))
// +kubebuilder:scaffold:scheme

Expand Down
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/manager"

kfdefv1 "github.com/opendatahub-io/opendatahub-operator/apis/kfdef.apps.kubeflow.org/v1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
featurev1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/v1"
Expand Down Expand Up @@ -87,7 +86,6 @@ func init() { //nolint:gochecknoinits
utilruntime.Must(ofapiv1alpha1.AddToScheme(scheme))
utilruntime.Must(userv1.Install(scheme))
utilruntime.Must(ofapiv2.AddToScheme(scheme))
utilruntime.Must(kfdefv1.AddToScheme(scheme))
utilruntime.Must(ocappsv1.Install(scheme))
utilruntime.Must(buildv1.Install(scheme))
utilruntime.Must(imagev1.Install(scheme))
Expand Down
8 changes: 2 additions & 6 deletions pkg/upgrade/uninstallation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@ const (
DeleteConfigMapLabel = "api.openshift.com/addon-managed-odh-delete"
)

// OperatorUninstall deletes all the externally generated resources. This includes monitoring resources and applications
// installed by KfDef.
// OperatorUninstall deletes all the externally generated resources.
// This includes DSCI, namespace created by operator (but not workbench or MR's), subscription and CSV.
func OperatorUninstall(ctx context.Context, cli client.Client) error {
platform, err := cluster.GetPlatform(ctx, cli)
if err != nil {
return err
}

if err := RemoveKfDefInstances(ctx, cli); err != nil {
return err
}

if err := removeDSCInitialization(ctx, cli); err != nil {
return err
}
Expand Down
36 changes: 0 additions & 36 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"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"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1"
Expand Down Expand Up @@ -328,41 +327,6 @@ func deleteOneResource(ctx context.Context, c client.Client, res ResourceSpec) e
return nil
}

func RemoveKfDefInstances(ctx context.Context, cli client.Client) error {
// Check if kfdef are deployed
kfdefCrd := &apiextv1.CustomResourceDefinition{}

err := cli.Get(ctx, client.ObjectKey{Name: "kfdefs.kfdef.apps.kubeflow.org"}, kfdefCrd)
if err != nil {
if k8serr.IsNotFound(err) {
// If no Crd found, return, since its a new Installation
return nil
}
return fmt.Errorf("error retrieving kfdef CRD : %w", err)
}
expectedKfDefList := &kfdefv1.KfDefList{}
err = cli.List(ctx, expectedKfDefList)
if err != nil {
return fmt.Errorf("error getting list of kfdefs: %w", err)
}
// Delete kfdefs
for _, kfdef := range expectedKfDefList.Items {
kfdef := kfdef
// Remove finalizer
updatedKfDef := &kfdef
updatedKfDef.Finalizers = []string{}
err = cli.Update(ctx, updatedKfDef)
if err != nil {
return fmt.Errorf("error removing finalizers from kfdef %v : %w", kfdef.Name, err)
}
err = cli.Delete(ctx, updatedKfDef)
if err != nil {
return fmt.Errorf("error deleting kfdef %v : %w", kfdef.Name, err)
}
}
return nil
}

func deleteDeprecatedResources(ctx context.Context, cli client.Client, namespace string, resourceList []string, resourceType client.ObjectList) error {
var multiErr *multierror.Error
listOpts := &client.ListOptions{Namespace: namespace}
Expand Down

0 comments on commit 60a44c2

Please sign in to comment.