diff --git a/components/README.md b/components/README.md index 22d53f32656..ebecaeced73 100644 --- a/components/README.md +++ b/components/README.md @@ -28,12 +28,13 @@ can be found [here](https://github.com/opendatahub-io/opendatahub-operator/tree/ - Define struct that includes a shared struct `Component` with common fields. - Implement [interface](https://github.com/opendatahub-io/opendatahub-operator/blob/main/components/component.go#L15) methods according to your component + ```go type ComponentInterface interface { - ReconcileComponent(owner metav1.Object, client client.Client, scheme *runtime.Scheme, - enabled bool, namespace string, manifestsUri string) error - GetComponentName() string - SetImageParamsMap(imageMap map[string]string) map[string]string + ReconcileComponent(cli client.Client, owner metav1.Object, DSCISpec *dsci.DSCInitializationSpec) error + GetComponentName() string + GetManagementState() operatorv1.ManagementState + SetImageParamsMap(imageMap map[string]string) map[string]string } ``` ### Add reconcile and Events diff --git a/components/codeflare/codeflare.go b/components/codeflare/codeflare.go index a220c7a4b4e..7b3d0776250 100644 --- a/components/codeflare/codeflare.go +++ b/components/codeflare/codeflare.go @@ -3,17 +3,16 @@ package codeflare import ( "fmt" + operatorv1 "github.com/openshift/api/operator/v1" "context" dsci "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy" imagev1 "github.com/openshift/api/image/v1" - operatorv1 "github.com/openshift/api/operator/v1" codeflarev1alpha1 "github.com/project-codeflare/codeflare-operator/api/codeflare/v1alpha1" apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -30,20 +29,20 @@ type CodeFlare struct { components.Component `json:""` } -func (d *CodeFlare) SetImageParamsMap(imageMap map[string]string) map[string]string { +func (c *CodeFlare) SetImageParamsMap(imageMap map[string]string) map[string]string { imageParamMap = imageMap return imageParamMap } -func (d *CodeFlare) GetComponentName() string { +func (c *CodeFlare) GetComponentName() string { return ComponentName } // Verifies that CodeFlare implements ComponentInterface var _ components.ComponentInterface = (*CodeFlare)(nil) -func (c *CodeFlare) ReconcileComponent(owner metav1.Object, cli client.Client, scheme *runtime.Scheme, managementState operatorv1.ManagementState, dscispec *dsci.DSCInitializationSpec) error { - enabled := managementState == operatorv1.Managed +func (d *CodeFlare) ReconcileComponent(cli client.Client, owner metav1.Object, dscispec *dsci.DSCInitializationSpec) error { + enabled := d.GetManagementState() == operatorv1.Managed if enabled { // check if the CodeFlare operator is installed @@ -57,15 +56,12 @@ func (c *CodeFlare) ReconcileComponent(owner metav1.Object, cli client.Client, s if platform == deploy.SelfManagedRhods || platform == deploy.ManagedRhods { dependentOperator = RHCodeflareOperator } - found, err := deploy.OperatorExists(cli, dependentOperator) - if !found { - if err != nil { - return err - } else { - return fmt.Errorf("operator %s not found. Please install the operator before enabling %s component", - dependentOperator, ComponentName) - } + if found, err := deploy.OperatorExists(cli, dependentOperator); err != nil { + return err + } else if !found { + return fmt.Errorf("operator %s not found. Please install the operator before enabling %s component", + dependentOperator, ComponentName) } // Update image parameters only when we do not have customized manifests set @@ -77,7 +73,7 @@ func (c *CodeFlare) ReconcileComponent(owner metav1.Object, cli client.Client, s } // Special handling to delete MCAD InstaScale ImageStream resources - if managementState == operatorv1.Removed { + if d.GetManagementState() == operatorv1.Removed { // Fetch the MCAD resource based on the request mcad := &codeflarev1alpha1.MCAD{} err := cli.Get(context.TODO(), client.ObjectKey{ @@ -116,10 +112,10 @@ func (c *CodeFlare) ReconcileComponent(owner metav1.Object, cli client.Client, s } // Deploy Codeflare - err := deploy.DeployManifestsFromPath(owner, cli, ComponentName, + err := deploy.DeployManifestsFromPath(owner, cli, d.GetComponentName(), CodeflarePath, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) return err diff --git a/components/component.go b/components/component.go index eb953520750..0fd1861745d 100644 --- a/components/component.go +++ b/components/component.go @@ -4,7 +4,6 @@ import ( dsci "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" operatorv1 "github.com/openshift/api/operator/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -22,9 +21,13 @@ type Component struct { // Add any other common fields across components below } +func (c *Component) GetManagementState() operatorv1.ManagementState { + return c.ManagementState +} + type ComponentInterface interface { - ReconcileComponent(owner metav1.Object, client client.Client, scheme *runtime.Scheme, - managementState operatorv1.ManagementState, DSCISpec *dsci.DSCInitializationSpec) error + ReconcileComponent(cli client.Client, owner metav1.Object, DSCISpec *dsci.DSCInitializationSpec) error GetComponentName() string + GetManagementState() operatorv1.ManagementState SetImageParamsMap(imageMap map[string]string) map[string]string } diff --git a/components/dashboard/dashboard.go b/components/dashboard/dashboard.go index 5d45a78f298..fef7e13c088 100644 --- a/components/dashboard/dashboard.go +++ b/components/dashboard/dashboard.go @@ -3,6 +3,7 @@ package dashboard import ( "fmt" + operatorv1 "github.com/openshift/api/operator/v1" "context" "strings" @@ -11,10 +12,8 @@ import ( "github.com/opendatahub-io/opendatahub-operator/v2/components" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/common" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy" - operatorv1 "github.com/openshift/api/operator/v1" routev1 "github.com/openshift/api/route/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -53,8 +52,7 @@ func (d *Dashboard) GetComponentName() string { // Verifies that Dashboard implements ComponentInterface var _ components.ComponentInterface = (*Dashboard)(nil) -func (d *Dashboard) ReconcileComponent(owner metav1.Object, cli client.Client, scheme *runtime.Scheme, managementState operatorv1.ManagementState, dscispec *dsci.DSCInitializationSpec) error { - enabled := managementState == operatorv1.Managed +func (d *Dashboard) ReconcileComponent(cli client.Client, owner metav1.Object, dscispec *dsci.DSCInitializationSpec) error { // TODO: Add any additional tasks if required when reconciling component @@ -62,7 +60,8 @@ func (d *Dashboard) ReconcileComponent(owner metav1.Object, cli client.Client, s if err != nil { return err } - + // Update Default rolebinding + enabled := d.GetManagementState() == operatorv1.Managed if enabled { if platform == deploy.OpenDataHub || platform == "" { err := common.UpdatePodSecurityRolebinding(cli, []string{"odh-dashboard"}, dscispec.ApplicationsNamespace) @@ -100,7 +99,7 @@ func (d *Dashboard) ReconcileComponent(owner metav1.Object, cli client.Client, s err = deploy.DeployManifestsFromPath(owner, cli, ComponentNameSupported, PathODHDashboardConfig, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) if err != nil { return fmt.Errorf("failed to set dashboard config from %s: %v", PathODHDashboardConfig, err) } @@ -109,7 +108,7 @@ func (d *Dashboard) ReconcileComponent(owner metav1.Object, cli client.Client, s err = deploy.DeployManifestsFromPath(owner, cli, ComponentNameSupported, PathOVMS, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) if err != nil { return fmt.Errorf("failed to set dashboard OVMS from %s: %v", PathOVMS, err) } @@ -122,7 +121,7 @@ func (d *Dashboard) ReconcileComponent(owner metav1.Object, cli client.Client, s err = deploy.DeployManifestsFromPath(owner, cli, ComponentNameSupported, PathAnaconda, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) if err != nil { return fmt.Errorf("failed to deploy anaconda resources from %s: %v", PathAnaconda, err) } @@ -141,7 +140,7 @@ func (d *Dashboard) ReconcileComponent(owner metav1.Object, cli client.Client, s err = deploy.DeployManifestsFromPath(owner, cli, ComponentName, Path, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) if err != nil { return err } @@ -150,7 +149,7 @@ func (d *Dashboard) ReconcileComponent(owner metav1.Object, cli client.Client, s err = deploy.DeployManifestsFromPath(owner, cli, ComponentNameSupported, PathSupported, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) if err != nil { return err } @@ -162,7 +161,7 @@ func (d *Dashboard) ReconcileComponent(owner metav1.Object, cli client.Client, s err = deploy.DeployManifestsFromPath(owner, cli, ComponentNameSupported, PathISVSM, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) if err != nil { return fmt.Errorf("failed to set dashboard ISV from %s: %v", PathISVSM, err) } @@ -184,7 +183,7 @@ func (d *Dashboard) ReconcileComponent(owner metav1.Object, cli client.Client, s err = deploy.DeployManifestsFromPath(owner, cli, ComponentNameSupported, PathConsoleLink, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) if err != nil { return fmt.Errorf("failed to set dashboard consolelink from %s: %v", PathConsoleLink, err) } @@ -193,7 +192,7 @@ func (d *Dashboard) ReconcileComponent(owner metav1.Object, cli client.Client, s err = deploy.DeployManifestsFromPath(owner, cli, ComponentNameSupported, PathISVAddOn, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) if err != nil { return fmt.Errorf("failed to set dashboard ISV from %s: %v", PathISVAddOn, err) } @@ -215,7 +214,7 @@ func (d *Dashboard) ReconcileComponent(owner metav1.Object, cli client.Client, s err = deploy.DeployManifestsFromPath(owner, cli, ComponentNameSupported, PathConsoleLink, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) if err != nil { return fmt.Errorf("failed to set dashboard consolelink from %s", PathConsoleLink) } diff --git a/components/datasciencepipelines/datasciencepipelines.go b/components/datasciencepipelines/datasciencepipelines.go index 47befc22f3b..b6c5efbc47c 100644 --- a/components/datasciencepipelines/datasciencepipelines.go +++ b/components/datasciencepipelines/datasciencepipelines.go @@ -7,7 +7,6 @@ import ( "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy" operatorv1 "github.com/openshift/api/operator/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -41,8 +40,8 @@ func (d *DataSciencePipelines) GetComponentName() string { // Verifies that Dashboard implements ComponentInterface var _ components.ComponentInterface = (*DataSciencePipelines)(nil) -func (d *DataSciencePipelines) ReconcileComponent(owner metav1.Object, cli client.Client, scheme *runtime.Scheme, managementState operatorv1.ManagementState, dscispec *dsci.DSCInitializationSpec) error { - enabled := managementState == operatorv1.Managed +func (d *DataSciencePipelines) ReconcileComponent(cli client.Client, owner metav1.Object, dscispec *dsci.DSCInitializationSpec) error { + enabled := d.GetManagementState() == operatorv1.Managed if enabled { // check if the dependent operator installed is done in dashboard @@ -54,10 +53,11 @@ func (d *DataSciencePipelines) ReconcileComponent(owner metav1.Object, cli clien } } } - err := deploy.DeployManifestsFromPath(owner, cli, ComponentName, + + err := deploy.DeployManifestsFromPath(owner, cli, d.GetComponentName(), Path, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) return err } diff --git a/components/kserve/kserve.go b/components/kserve/kserve.go index d396b53301e..35757019878 100644 --- a/components/kserve/kserve.go +++ b/components/kserve/kserve.go @@ -3,15 +3,14 @@ package kserve import ( "fmt" + operatorv1 "github.com/openshift/api/operator/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" dsci "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/common" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy" - operatorv1 "github.com/openshift/api/operator/v1" ) const ( @@ -35,41 +34,36 @@ type Kserve struct { components.Component `json:""` } -func (d *Kserve) SetImageParamsMap(imageMap map[string]string) map[string]string { +func (k *Kserve) SetImageParamsMap(imageMap map[string]string) map[string]string { imageParamMap = imageMap return imageParamMap } -func (d *Kserve) GetComponentName() string { +func (k *Kserve) GetComponentName() string { return ComponentName } // Verifies that Kserve implements ComponentInterface var _ components.ComponentInterface = (*Kserve)(nil) -func (k *Kserve) ReconcileComponent(owner metav1.Object, cli client.Client, scheme *runtime.Scheme, managementState operatorv1.ManagementState, dscispec *dsci.DSCInitializationSpec) error { - enabled := managementState == operatorv1.Managed +func (k *Kserve) ReconcileComponent(cli client.Client, owner metav1.Object, dscispec *dsci.DSCInitializationSpec) error { + enabled := k.GetManagementState() == operatorv1.Managed if enabled { // check on dependent operators - found, err := deploy.OperatorExists(cli, ServiceMeshOperator) - if !found { - if err != nil { - return err - } else { - return fmt.Errorf("operator %s not found. Please install the operator before enabling %s component", - ServiceMeshOperator, ComponentName) - } + if found, err := deploy.OperatorExists(cli, ServiceMeshOperator); err != nil { + return err + } else if !found { + return fmt.Errorf("operator %s not found. Please install the operator before enabling %s component", + ServiceMeshOperator, ComponentName) } + // check on dependent operators might be in multiple namespaces - found, err = deploy.OperatorExists(cli, ServerlessOperator) - if !found { - if err != nil { - return err - } else { - return fmt.Errorf("operator %s not found. Please install the operator before enabling %s component", - ServerlessOperator, ComponentName) - } + if found, err := deploy.OperatorExists(cli, ServerlessOperator); err != nil { + return err + } else if !found { + return fmt.Errorf("operator %s not found. Please install the operator before enabling %s component", + ServerlessOperator, ComponentName) } // Update image parameters only when we do not have customized manifests set @@ -83,7 +77,7 @@ func (k *Kserve) ReconcileComponent(owner metav1.Object, cli client.Client, sche if err := deploy.DeployManifestsFromPath(owner, cli, ComponentName, Path, dscispec.ApplicationsNamespace, - scheme, enabled); err != nil { + cli.Scheme(), enabled); err != nil { return err } @@ -100,10 +94,10 @@ func (k *Kserve) ReconcileComponent(owner metav1.Object, cli client.Client, sche } } } - if err := deploy.DeployManifestsFromPath(owner, cli, ComponentName, + if err := deploy.DeployManifestsFromPath(owner, cli, k.GetComponentName(), DependentPath, dscispec.ApplicationsNamespace, - scheme, enabled); err != nil { + cli.Scheme(), enabled); err != nil { return err } diff --git a/components/modelmeshserving/modelmeshserving.go b/components/modelmeshserving/modelmeshserving.go index 34c6924a4d5..f4a3609091d 100644 --- a/components/modelmeshserving/modelmeshserving.go +++ b/components/modelmeshserving/modelmeshserving.go @@ -3,14 +3,13 @@ package modelmeshserving import ( "context" + operatorv1 "github.com/openshift/api/operator/v1" dsci "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/common" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy" - operatorv1 "github.com/openshift/api/operator/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -44,8 +43,8 @@ func (m *ModelMeshServing) SetImageParamsMap(imageMap map[string]string) map[str // Verifies that Dashboard implements ComponentInterface var _ components.ComponentInterface = (*ModelMeshServing)(nil) -func (m *ModelMeshServing) ReconcileComponent(owner metav1.Object, cli client.Client, scheme *runtime.Scheme, managementState operatorv1.ManagementState, dscispec *dsci.DSCInitializationSpec) error { - enabled := managementState == operatorv1.Managed +func (m *ModelMeshServing) ReconcileComponent(cli client.Client, owner metav1.Object, dscispec *dsci.DSCInitializationSpec) error { + enabled := m.GetManagementState() == operatorv1.Managed // Update Default rolebinding if enabled { @@ -64,7 +63,7 @@ func (m *ModelMeshServing) ReconcileComponent(owner metav1.Object, cli client.Cl err := deploy.DeployManifestsFromPath(owner, cli, ComponentName, Path, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) if err != nil { return err @@ -89,7 +88,7 @@ func (m *ModelMeshServing) ReconcileComponent(owner metav1.Object, cli client.Cl err = deploy.DeployManifestsFromPath(owner, cli, ComponentName, monitoringPath, monitoringNamespace, - scheme, enabled) + cli.Scheme(), enabled) return err } diff --git a/components/ray/ray.go b/components/ray/ray.go index 2bb62e9c6f7..ab60f1423cb 100644 --- a/components/ray/ray.go +++ b/components/ray/ray.go @@ -7,7 +7,6 @@ import ( "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy" operatorv1 "github.com/openshift/api/operator/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -24,20 +23,20 @@ type Ray struct { components.Component `json:""` } -func (d *Ray) SetImageParamsMap(imageMap map[string]string) map[string]string { +func (r *Ray) SetImageParamsMap(imageMap map[string]string) map[string]string { imageParamMap = imageMap return imageParamMap } -func (d *Ray) GetComponentName() string { +func (r *Ray) GetComponentName() string { return ComponentName } // Verifies that Ray implements ComponentInterface var _ components.ComponentInterface = (*Ray)(nil) -func (d *Ray) ReconcileComponent(owner metav1.Object, cli client.Client, scheme *runtime.Scheme, managementState operatorv1.ManagementState, dscispec *dsci.DSCInitializationSpec) error { - enabled := managementState == operatorv1.Managed +func (r *Ray) ReconcileComponent(cli client.Client, owner metav1.Object, dscispec *dsci.DSCInitializationSpec) error { + enabled := r.GetManagementState() == operatorv1.Managed if enabled { if dscispec.DevFlags.ManifestsUri == "" { @@ -47,10 +46,10 @@ func (d *Ray) ReconcileComponent(owner metav1.Object, cli client.Client, scheme } } // Deploy Ray Operator - err := deploy.DeployManifestsFromPath(owner, cli, ComponentName, + err := deploy.DeployManifestsFromPath(owner, cli, r.GetComponentName(), RayPath, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) return err } diff --git a/components/workbenches/workbenches.go b/components/workbenches/workbenches.go index 4511bb6ba03..8def7be1c49 100644 --- a/components/workbenches/workbenches.go +++ b/components/workbenches/workbenches.go @@ -8,7 +8,6 @@ import ( "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy" operatorv1 "github.com/openshift/api/operator/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -40,9 +39,7 @@ func (w *Workbenches) SetImageParamsMap(imageMap map[string]string) map[string]s // Verifies that Dashboard implements ComponentInterface var _ components.ComponentInterface = (*Workbenches)(nil) -func (w *Workbenches) ReconcileComponent(owner metav1.Object, cli client.Client, scheme *runtime.Scheme, managementState operatorv1.ManagementState, dscispec *dsci.DSCInitializationSpec) error { - enabled := managementState == operatorv1.Managed - +func (w *Workbenches) ReconcileComponent(cli client.Client, owner metav1.Object, dscispec *dsci.DSCInitializationSpec) error { // Set default notebooks namespace // Create rhods-notebooks namespace in managed platforms platform, err := deploy.GetPlatform(cli) @@ -50,6 +47,8 @@ func (w *Workbenches) ReconcileComponent(owner metav1.Object, cli client.Client, return err } + enabled := w.GetManagementState() == operatorv1.Managed + if enabled { if platform == deploy.SelfManagedRhods || platform == deploy.ManagedRhods { err := common.CreateNamespace(cli, "rhods-notebooks") @@ -74,7 +73,7 @@ func (w *Workbenches) ReconcileComponent(owner metav1.Object, cli client.Client, err = deploy.DeployManifestsFromPath(owner, cli, ComponentName, notebookControllerPath, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) if err != nil { return err } @@ -98,13 +97,13 @@ func (w *Workbenches) ReconcileComponent(owner metav1.Object, cli client.Client, err = deploy.DeployManifestsFromPath(owner, cli, ComponentName, notebookImagesPath, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) return err } else { err = deploy.DeployManifestsFromPath(owner, cli, ComponentName, notebookImagesPathSupported, dscispec.ApplicationsNamespace, - scheme, enabled) + cli.Scheme(), enabled) return err } diff --git a/controllers/datasciencecluster/datasciencecluster_controller.go b/controllers/datasciencecluster/datasciencecluster_controller.go index bdcb10b4c92..441e6ea9bd2 100644 --- a/controllers/datasciencecluster/datasciencecluster_controller.go +++ b/controllers/datasciencecluster/datasciencecluster_controller.go @@ -20,6 +20,7 @@ package datasciencecluster import ( "context" "fmt" + v1 "github.com/openshift/api/operator/v1" "time" "sigs.k8s.io/controller-runtime/pkg/handler" @@ -51,8 +52,6 @@ import ( "k8s.io/client-go/tools/record" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" - - operatorv1 "github.com/openshift/api/operator/v1" ) // DataScienceClusterReconciler reconciles a DataScienceCluster object @@ -157,47 +156,43 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R componentErrorList := make(map[string]error) // reconcile dashboard component - if instance, err = r.reconcileSubComponent(ctx, instance, dashboard.ComponentName, instance.Spec.Components.Dashboard.ManagementState, - &(instance.Spec.Components.Dashboard)); err != nil { + if instance, err = r.reconcileSubComponent(ctx, instance, &(instance.Spec.Components.Dashboard)); err != nil { // no need to log any errors as this is done in the reconcileSubComponent method componentErrorList[dashboard.ComponentName] = err } // reconcile DataSciencePipelines component - if instance, err = r.reconcileSubComponent(ctx, instance, datasciencepipelines.ComponentName, instance.Spec.Components.DataSciencePipelines.ManagementState, - &(instance.Spec.Components.DataSciencePipelines)); err != nil { + if instance, err = r.reconcileSubComponent(ctx, instance, &(instance.Spec.Components.DataSciencePipelines)); err != nil { // no need to log any errors as this is done in the reconcileSubComponent method componentErrorList[datasciencepipelines.ComponentName] = err } // reconcile Workbench component - if instance, err = r.reconcileSubComponent(ctx, instance, workbenches.ComponentName, instance.Spec.Components.Workbenches.ManagementState, - &(instance.Spec.Components.Workbenches)); err != nil { + if instance, err = r.reconcileSubComponent(ctx, instance, &(instance.Spec.Components.Workbenches)); err != nil { // no need to log any errors as this is done in the reconcileSubComponent method componentErrorList[workbenches.ComponentName] = err } // reconcile Kserve component - if instance, err = r.reconcileSubComponent(ctx, instance, kserve.ComponentName, instance.Spec.Components.Kserve.ManagementState, &(instance.Spec.Components.Kserve)); err != nil { + if instance, err = r.reconcileSubComponent(ctx, instance, &(instance.Spec.Components.Kserve)); err != nil { // no need to log any errors as this is done in the reconcileSubComponent method componentErrorList[kserve.ComponentName] = err } // reconcile ModelMesh component - if instance, err = r.reconcileSubComponent(ctx, instance, modelmeshserving.ComponentName, instance.Spec.Components.ModelMeshServing.ManagementState, - &(instance.Spec.Components.ModelMeshServing)); err != nil { + if instance, err = r.reconcileSubComponent(ctx, instance, &(instance.Spec.Components.ModelMeshServing)); err != nil { // no need to log any errors as this is done in the reconcileSubComponent method componentErrorList[modelmeshserving.ComponentName] = err } // reconcile CodeFlare component - if instance, err = r.reconcileSubComponent(ctx, instance, codeflare.ComponentName, instance.Spec.Components.CodeFlare.ManagementState, &(instance.Spec.Components.CodeFlare)); err != nil { + if instance, err = r.reconcileSubComponent(ctx, instance, &(instance.Spec.Components.CodeFlare)); err != nil { // no need to log any errors as this is done in the reconcileSubComponent method componentErrorList[codeflare.ComponentName] = err } // reconcile Ray component - if instance, err = r.reconcileSubComponent(ctx, instance, ray.ComponentName, instance.Spec.Components.Ray.ManagementState, &(instance.Spec.Components.Ray)); err != nil { + if instance, err = r.reconcileSubComponent(ctx, instance, &(instance.Spec.Components.Ray)); err != nil { // no need to log any errors as this is done in the reconcileSubComponent method componentErrorList[ray.ComponentName] = err } @@ -232,17 +227,17 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R return ctrl.Result{}, nil } -func (r *DataScienceClusterReconciler) reconcileSubComponent(ctx context.Context, instance *dsc.DataScienceCluster, componentName string, mngmtState operatorv1.ManagementState, +func (r *DataScienceClusterReconciler) reconcileSubComponent(ctx context.Context, instance *dsc.DataScienceCluster, component components.ComponentInterface) (*dsc.DataScienceCluster, error) { - enabled := mngmtState == operatorv1.Managed - - // First set contidions to reflect a component is about to be reconciled + componentName := component.GetComponentName() + enabled := component.GetManagementState() == v1.Managed + // First set conditions to reflect a component is about to be reconciled instance, err := r.updateStatus(ctx, instance, func(saved *dsc.DataScienceCluster) { + message := "Component is disabled" if enabled { - status.SetComponentCondition(&saved.Status.Conditions, componentName, status.ReconcileInit, "Component is enabled", corev1.ConditionUnknown) - } else { - status.SetComponentCondition(&saved.Status.Conditions, componentName, status.ReconcileInit, "Component is disabled", corev1.ConditionUnknown) + message = "Component is enabled" } + status.SetComponentCondition(&saved.Status.Conditions, componentName, status.ReconcileInit, message, corev1.ConditionUnknown) }) if err != nil { instance = r.reportError(err, instance, "failed to update DataScienceCluster conditions before reconciling "+componentName) @@ -250,7 +245,7 @@ func (r *DataScienceClusterReconciler) reconcileSubComponent(ctx context.Context } // Reconcile component - err = component.ReconcileComponent(instance, r.Client, r.Scheme, mngmtState, r.DataScienceCluster.DSCISpec) + err = component.ReconcileComponent(r.Client, instance, r.DataScienceCluster.DSCISpec) if err != nil { // reconciliation failed: log errors, raise event and update status accordingly