Skip to content

Commit

Permalink
Move creation of default DSC
Browse files Browse the repository at this point in the history
  • Loading branch information
VaishnaviHire committed Oct 25, 2023
1 parent 014396c commit ab33109
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 39 deletions.
9 changes: 0 additions & 9 deletions controllers/dscinitialization/dscinitialization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
dsci "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"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 Down Expand Up @@ -139,13 +137,6 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re
return reconcile.Result{}, err
}

// Apply update from legacy operator
// TODO: Update upgrade logic to get components through KfDef
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 {
// Apply osd specific permissions
Expand Down
25 changes: 24 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
datascienceclustercontrollers "github.com/opendatahub-io/opendatahub-operator/v2/controllers/datasciencecluster"
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 @@ -46,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 @@ -206,6 +208,27 @@ func main() {
}
}

// Create new uncached client to run initial setup
setupCfg, err := config.GetConfig()
if err != nil {
setupLog.Error(err, "error getting config for setup")
os.Exit(1)
}

setupClient, err := client2.New(setupCfg, client2.Options{Scheme: scheme})
// Get operator platform
platform, err := deploy.GetPlatform(setupClient)
if err != nil {
setupLog.Error(err, "error getting client for setup")
os.Exit(1)
}

// 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)
}

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
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
59 changes: 31 additions & 28 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func HasDeleteConfigMap(c client.Client) bool {

// createDefaultDSC creates a default instance of DSC.
// Note: When the platform is not Managed, and a DSC instance already exists, the function doesn't re-create/update the resource.
func createDefaultDSC(cli client.Client, platform deploy.Platform) error {
func CreateDefaultDSC(cli client.Client, platform deploy.Platform) error {
releaseDataScienceCluster := &dsc.DataScienceCluster{
TypeMeta: metav1.TypeMeta{
Kind: "DataScienceCluster",
Expand Down Expand Up @@ -204,7 +204,7 @@ 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 := createDefaultDSC(cli, platform)
err := CreateDefaultDSC(cli, platform)
if err != nil {
return err
}
Expand All @@ -216,37 +216,40 @@ func UpdateFromLegacyVersion(cli client.Client, platform deploy.Platform) error
return nil
}

// 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 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 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 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 ab33109

Please sign in to comment.