Skip to content

Commit

Permalink
Upgrade from v1.x operator (opendatahub-io#631)
Browse files Browse the repository at this point in the history
* Cleanup KfDef instances

* Add support for Uninstall configmap

* Go mod updates

* Update permissions

* Create Default DSC

* Update unit tests

* Update E2e tests
  • Loading branch information
VaishnaviHire authored Oct 20, 2023
1 parent 2231cba commit 14e2a04
Show file tree
Hide file tree
Showing 14 changed files with 1,685 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -866,10 +866,12 @@ spec:
resources:
- kfdefs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- kubeflow.org
Expand Down Expand Up @@ -1092,8 +1094,10 @@ spec:
resources:
- clusterserviceversions
verbs:
- delete
- get
- list
- update
- watch
- apiGroups:
- operators.coreos.com
Expand Down
182 changes: 182 additions & 0 deletions config/crd/external/kfdef.apps.kubeflow.org_kfdefs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: kfdefs.kfdef.apps.kubeflow.org
spec:
group: kfdef.apps.kubeflow.org
names:
kind: KfDef
listKind: KfDefList
plural: kfdefs
singular: kfdef
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: KfDef is the Schema for the kfdefs API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: KfDefSpec defines the desired state of KfDef
properties:
applications:
items:
description: Application defines an application to install
properties:
kustomizeConfig:
properties:
overlays:
items:
type: string
type: array
parameters:
items:
properties:
name:
type: string
value:
type: string
type: object
type: array
repoRef:
properties:
name:
type: string
path:
type: string
type: object
type: object
name:
type: string
type: object
type: array
plugins:
items:
description: Plugin can be used to customize the generation and
deployment of Kubeflow
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this
representation of an object. Servers should convert recognized
schemas to the latest internal value, and may reject unrecognized
values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource
this object represents. Servers may infer this from the endpoint
the client submits requests to. Cannot be updated. In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
type: object
type: object
type: array
repos:
items:
description: Repo provides information about a repository providing
config (e.g. kustomize packages, Deployment manager configs, etc...)
properties:
name:
description: Name is a name to identify the repository.
type: string
uri:
description: 'URI where repository can be obtained. Can use
any URI understood by go-getter: https://github.com/hashicorp/go-getter/blob/master/README.md#installation-and-usage'
type: string
type: object
type: array
secrets:
items:
description: Secret provides information about secrets needed to
configure Kubeflow. Secrets can be provided via references.
properties:
name:
type: string
secretSource:
properties:
envSource:
properties:
name:
type: string
type: object
literalSource:
properties:
value:
type: string
type: object
type: object
type: object
type: array
version:
type: string
type: object
status:
description: KfDefStatus defines the observed state of KfDef
properties:
conditions:
items:
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another.
format: date-time
type: string
lastUpdateTime:
description: The last time this condition was updated.
format: date-time
type: string
message:
description: A human readable message indicating details about
the transition.
type: string
reason:
description: The reason for the condition's last transition.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of deployment condition.
type: string
required:
- status
- type
type: object
type: array
reposCache:
description: ReposCache is used to cache information about local caching
of the URIs.
items:
properties:
localPath:
type: string
name:
type: string
required:
- localPath
type: object
type: array
type: object
type: object
served: true
storage: true
subresources:
status: {}
4 changes: 4 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,12 @@ rules:
resources:
- kfdefs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- kubeflow.org
Expand Down Expand Up @@ -910,8 +912,10 @@ rules:
resources:
- clusterserviceversions
verbs:
- delete
- get
- list
- update
- watch
- apiGroups:
- operators.coreos.com
Expand Down
49 changes: 44 additions & 5 deletions controllers/datasciencecluster/datasciencecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"context"
"errors"
"fmt"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/upgrade"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/rest"
"reflect"
"time"

Expand Down Expand Up @@ -55,8 +58,9 @@ import (
// DataScienceClusterReconciler reconciles a DataScienceCluster object.
type DataScienceClusterReconciler struct {
client.Client
Scheme *runtime.Scheme
Log logr.Logger
Scheme *runtime.Scheme
Log logr.Logger
RestConfig *rest.Config
// Recorder to generate events
Recorder record.EventRecorder
DataScienceCluster *DataScienceClusterConfig
Expand Down Expand Up @@ -86,13 +90,24 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
}

if len(instances.Items) == 0 {
// DataScienceCluster instance not found
// Request object not found, could have been deleted after reconcile request.
// Owned objects are automatically garbage collected. For additional cleanup logic use operatorUninstall function.
// Return and don't requeue
if upgrade.HasDeleteConfigMap(r.Client) {
return reconcile.Result{}, fmt.Errorf("error while operator uninstall: %v",
upgrade.OperatorUninstall(r.Client, r.RestConfig))
}
return ctrl.Result{}, nil
}

instance := &instances.Items[0]

if instance.GetDeletionTimestamp() != nil {
r.Log.Info("DataScienceCluster instance is deleted.", "name", instance.Name)
if upgrade.HasDeleteConfigMap(r.Client) {
// if delete configmap exists, requeue the request to handle operator uninstall
return reconcile.Result{Requeue: true}, nil
}
return ctrl.Result{}, nil
}

Expand All @@ -111,6 +126,15 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
}
}

// If Deletion configmap is found, reconcile to trigger operatorUninstall
if upgrade.HasDeleteConfigMap(r.Client) {
if err := r.Client.Delete(context.TODO(), instance); err != nil {
if !apierrs.IsNotFound(err) {
return reconcile.Result{}, err
}
}
return reconcile.Result{Requeue: true}, nil
}
// Verify a valid DSCInitialization instance is created
dsciInstances := &dsci.DSCInitializationList{}
err = r.Client.List(ctx, dsciInstances)
Expand Down Expand Up @@ -301,6 +325,7 @@ func (r *DataScienceClusterReconciler) SetupWithManager(mgr ctrl.Manager) error
Owns(&appsv1.ReplicaSet{}).
Owns(&corev1.Pod{}).
Watches(&source.Kind{Type: &dsci.DSCInitialization{}}, handler.EnqueueRequestsFromMapFunc(r.watchDataScienceClusterResources)).
Watches(&source.Kind{Type: &corev1.ConfigMap{}}, handler.EnqueueRequestsFromMapFunc(r.watchDataScienceClusterResources)).
// this predicates prevents meaningless reconciliations from being triggered
WithEventFilter(predicate.Or(predicate.GenerationChangedPredicate{}, predicate.LabelChangedPredicate{})).
Complete(r)
Expand Down Expand Up @@ -351,10 +376,24 @@ func (r *DataScienceClusterReconciler) watchDataScienceClusterResources(a client
return nil
}
if len(instanceList.Items) == 1 {
// Trigger reconcile function when uninstall configmap is created
if a.GetObjectKind().GroupVersionKind().Kind == "ConfigMap" {
labels := a.GetLabels()
if val, ok := labels[upgrade.DeleteConfigMapLabel]; ok && val == "true" {
return []reconcile.Request{{
NamespacedName: types.NamespacedName{Name: instanceList.Items[0].Name},
}}
} else {
return nil
}
}
return []reconcile.Request{{
NamespacedName: types.NamespacedName{Name: instanceList.Items[0].Name},
}}
} else {
return nil
} else if len(instanceList.Items) == 0 {
return []reconcile.Request{{
NamespacedName: types.NamespacedName{Name: "default"},
}}
}
return nil
}
4 changes: 2 additions & 2 deletions controllers/datasciencecluster/kubebuilder_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package datasciencecluster
// +kubebuilder:rbac:groups="dashboard.opendatahub.io",resources=odhapplications,verbs=create;get;patch;list;delete
// +kubebuilder:rbac:groups="dashboard.opendatahub.io",resources=acceleratorprofiles,verbs=create;get;patch;list;delete

// +kubebuilder:rbac:groups="operators.coreos.com",resources=clusterserviceversions,verbs=get;list;watch
// +kubebuilder:rbac:groups="operators.coreos.com",resources=clusterserviceversions,verbs=get;list;watch;delete;update
// +kubebuilder:rbac:groups="operators.coreos.com",resources=customresourcedefinitions,verbs=create;get;patch;delete
// +kubebuilder:rbac:groups="operators.coreos.com",resources=subscriptions,verbs=get;list;watch
// +kubebuilder:rbac:groups="operators.coreos.com",resources=operatorconditions,verbs=get;list;watch
Expand Down Expand Up @@ -111,7 +111,7 @@ package datasciencecluster

/* 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
// +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

Expand Down
10 changes: 6 additions & 4 deletions controllers/dscinitialization/dscinitialization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"errors"
"fmt"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/upgrade"
"path/filepath"

operatorv1 "github.com/openshift/api/operator/v1"
Expand Down Expand Up @@ -56,6 +57,7 @@ type DSCInitializationReconciler struct {
// +kubebuilder:rbac:groups="dscinitialization.opendatahub.io",resources=dscinitializations/status,verbs=get;update;patch;delete
// +kubebuilder:rbac:groups="dscinitialization.opendatahub.io",resources=dscinitializations/finalizers,verbs=get;update;patch;delete
// +kubebuilder:rbac:groups="dscinitialization.opendatahub.io",resources=dscinitializations,verbs=get;list;watch;create;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) {
Expand Down Expand Up @@ -124,10 +126,10 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re

// Apply update from legacy operator
// TODO: Update upgrade logic to get components through KfDef
// if err = updatefromLegacyVersion(r.Client); err != nil {
// r.Log.Error(err, "unable to update from legacy operator version")
// return reconcile.Result{}, err
// }
if err = upgrade.UpdateFromLegacyVersion(r.Client, platform); err != nil {
r.Log.Error(err, "unable to update from legacy operator version")
return reconcile.Result{}, err
}

// Apply Rhods specific configs
if platform == deploy.ManagedRhods || platform == deploy.SelfManagedRhods {
Expand Down
2 changes: 2 additions & 0 deletions controllers/dscinitialization/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package dscinitialization_test

import (
"context"
kfdefv1 "github.com/opendatahub-io/opendatahub-operator/apis/kfdef.apps.kubeflow.org/v1"
"k8s.io/apimachinery/pkg/runtime"
"path/filepath"
"testing"
Expand Down Expand Up @@ -107,6 +108,7 @@ var _ = BeforeSuite(func() {
utilruntime.Must(ofapi.AddToScheme(testScheme))
utilruntime.Must(routev1.Install(testScheme))
utilruntime.Must(userv1.Install(testScheme))
utilruntime.Must(kfdefv1.AddToScheme(testScheme))
//+kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: testScheme})
Expand Down
Loading

0 comments on commit 14e2a04

Please sign in to comment.