Skip to content

Commit

Permalink
Move creation of default DSC
Browse files Browse the repository at this point in the history
(cherry picked from commit ab33109)
  • Loading branch information
VaishnaviHire committed Oct 25, 2023
1 parent 5f1c0d4 commit 00ddd6c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import (
"github.com/go-logr/logr"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/upgrade"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
netv1 "k8s.io/api/networking/v1"
Expand All @@ -49,6 +47,7 @@ import (

dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/upgrade"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand Down
15 changes: 7 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ import (
"context"
"encoding/json"
"flag"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/upgrade"
"sigs.k8s.io/controller-runtime/pkg/client/config"

kfdefv1 "github.com/opendatahub-io/opendatahub-operator/apis/kfdef.apps.kubeflow.org/v1"
dsc "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
dsci "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
dscicontr "github.com/opendatahub-io/opendatahub-operator/v2/controllers/dscinitialization"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/secretgenerator"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/upgrade"
addonv1alpha1 "github.com/openshift/addon-operator/apis/addons/v1alpha1"
ocv1 "github.com/openshift/api/oauth/v1"
operatorv1 "github.com/openshift/api/operator/v1"
Expand All @@ -49,7 +48,7 @@ import (
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"os"
client2 "sigs.k8s.io/controller-runtime/pkg/client"

"sigs.k8s.io/controller-runtime/pkg/client/config"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
Expand Down Expand Up @@ -227,10 +226,10 @@ func main() {
setupLog.Error(err, "error getting platform")
os.Exit(1)
}
// Create Default DSC
err = upgrade.CreateDefaultDSC(mgr.GetClient(), platform)
if err != nil {
setupLog.Error(err, "error creating rhods DSC")

// Apply update from legacy operator
if err = upgrade.UpdateFromLegacyVersion(setupClient, platform); err != nil {
setupLog.Error(err, "unable to update from legacy operator version")
os.Exit(1)
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,15 @@ func manageResource(ctx context.Context, cli client.Client, obj *unstructured.Un
}
}

if obj.GetOwnerReferences() == nil {
existingOwnerReferences := obj.GetOwnerReferences()
if existingOwnerReferences == nil {
return cli.Delete(ctx, found)
} else if len(existingOwnerReferences) > 0 {
for _, owner := range existingOwnerReferences {
if owner.Kind != "DataScienceCluster" && owner.Kind != "DataScienceInitialization" {
return nil
}
}
}

found.SetOwnerReferences([]metav1.OwnerReference{})
Expand Down
52 changes: 36 additions & 16 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,32 +208,52 @@ func CreateDefaultDSC(cli client.Client, platform deploy.Platform) error {
func UpdateFromLegacyVersion(cli client.Client, platform deploy.Platform) error {
// If platform is Managed, remove Kfdefs and create default dsc
if platform == deploy.ManagedRhods {
err := RemoveKfDefInstances(cli, platform)
err := CreateDefaultDSC(cli, platform)
if err != nil {
return err
}

err = RemoveKfDefInstances(cli, platform)
if err != nil {
return err
}
return nil
}

// If KfDef Instances found, and no DSC instances are found in Self-managed, that means this is an upgrade path from
// legacy version. Create a default DSC instance
kfDefList := &kfdefv1.KfDefList{}
err := cli.List(context.TODO(), kfDefList)
if err != nil {
if apierrs.IsNotFound(err) {
// If no KfDefs, do nothing and return
return nil
} else {
return fmt.Errorf("error getting list of kfdefs: %v", err)
if platform == deploy.SelfManagedRhods {
// If KfDef CRD is not found, we see it as a cluster not pre-installed v1 operator // Check if kfdef are deployed
kfdefCrd := &apiextv1.CustomResourceDefinition{}
err := cli.Get(context.TODO(), client.ObjectKey{Name: "kfdefs.kfdef.apps.kubeflow.org"}, kfdefCrd)
if err != nil {
if apierrs.IsNotFound(err) {
// If no Crd found, return, since its a new Installation
return nil
} else {
return fmt.Errorf("error retrieving kfdef CRD : %v", err)
}
}
}
if len(kfDefList.Items) > 0 {
err := CreateDefaultDSC(cli, platform)

// If KfDef Instances found, and no DSC instances are found in Self-managed, that means this is an upgrade path from
// legacy version. Create a default DSC instance
kfDefList := &kfdefv1.KfDefList{}
err = cli.List(context.TODO(), kfDefList)
if err != nil {
return err
if apierrs.IsNotFound(err) {
// If no KfDefs, do nothing and return
return nil
} else {
return fmt.Errorf("error getting list of kfdefs: %v", err)
}
}
if len(kfDefList.Items) > 0 {
err := CreateDefaultDSC(cli, platform)
if err != nil {
return err
}
}
return err
}
return err
return nil
}

func GetOperatorNamespace() (string, error) {
Expand Down

0 comments on commit 00ddd6c

Please sign in to comment.