Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync upstream main branch #86

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/codeflare/codeflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c *CodeFlare) ReconcileComponent(cli client.Client, owner metav1.Object, d
}

if found, err := deploy.OperatorExists(cli, dependentOperator); err != nil {
return err
return fmt.Errorf("operator exists throws error %v", err)
} else if found {
return fmt.Errorf("operator %s found. Please uninstall the operator before enabling %s component",
dependentOperator, ComponentName)
Expand Down
10 changes: 1 addition & 9 deletions controllers/dscinitialization/dscinitialization_controller.go
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 Expand Up @@ -163,13 +162,6 @@ 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 = upgrade.UpdateFromLegacyVersion(r.Client, platform); err != nil {
r.Log.Error(err, "unable to update from legacy operator version")
return reconcile.Result{}, err
}

switch platform {
case deploy.SelfManagedRhods:
err := r.createUserGroup(ctx, instance, "rhods-admins")
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
4 changes: 1 addition & 3 deletions tests/e2e/dsc_creation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ func (tc *testContext) testAllApplicationCreation(t *testing.T) error {
if tc.testDsc.Spec.Components.CodeFlare.ManagementState == operatorv1.Managed {
if err != nil {
// dependent operator error, as expected
if strings.Contains(err.Error(), "Please install the operator before enabling component") {
t.Logf("expected error: %v", err.Error())
} else {
{
require.NoError(t, err, "error validating application %v when enabled", tc.testDsc.Spec.Components.CodeFlare.GetComponentName())
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/dsc_deletion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (tc *testContext) testApplicationDeletion(component components.ComponentInt

if err := wait.PollUntilContextTimeout(tc.ctx, tc.resourceRetryInterval, tc.resourceCreationTimeout, false, func(ctx context.Context) (done bool, err error) {
appList, err := tc.kubeClient.AppsV1().Deployments(tc.applicationsNamespace).List(ctx, metav1.ListOptions{
LabelSelector: "app.kubernetes.io/part-of=" + component.GetComponentName(),
LabelSelector: "app.opendatahub.io/" + component.GetComponentName(),
})
if err != nil {
log.Printf("error listing component deployments :%v. Trying again...", err)
Expand Down
Loading