diff --git a/controllers/components/dashboard_controller.go b/controllers/components/dashboard_controller.go index f226353f13c..cba88746ec6 100644 --- a/controllers/components/dashboard_controller.go +++ b/controllers/components/dashboard_controller.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "k8s.io/utils/pointer" + "path/filepath" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -45,6 +46,7 @@ import ( odhrec "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/reconciler" odhtypes "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/types" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy" + ctrlogger "github.com/opendatahub-io/opendatahub-operator/v2/pkg/logger" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels" ) @@ -257,9 +259,7 @@ func (a *InitializeAction) Execute(ctx context.Context, rr *odhtypes.Reconciliat } DefaultPath = manifestMap[rr.Platform] - rr.Manifests = odhtypes.Manifests{ - Paths: manifestMap, - } + rr.Manifests = manifestMap if err := deploy.ApplyParams(DefaultPath, imageParamMap); err != nil { log.Error(err, "failed to update image", "path", DefaultPath) @@ -289,9 +289,15 @@ func (a *SupportDevFlagsAction) Execute(ctx context.Context, rr *odhtypes.Reconc return err } if manifestConfig.SourcePath != "" { - // r.entryPath = filepath.Join(deploy.DefaultManifestPath, ComponentNameUpstream, manifestConfig.SourcePath) + rr.Manifests[rr.Platform] = filepath.Join(deploy.DefaultManifestPath, ComponentNameUpstream, manifestConfig.SourcePath) } } + + if rr.DSCI.Spec.DevFlags != nil { + mode := rr.DSCI.Spec.DevFlags.LogMode + a.Log = ctrlogger.NewNamedLogger(logf.FromContext(ctx), ComponentName, mode) + } + return nil } @@ -354,7 +360,7 @@ func (a *DeployComponentAction) Execute(ctx context.Context, rr *odhtypes.Reconc // return fmt.Errorf("failed to update params.env from %s : %w", r.entryPath, err) // } - path := rr.Manifests.Paths[rr.Platform] + path := rr.Manifests[rr.Platform] name := ComponentNameUpstream // common: Deploy odh-dashboard manifests diff --git a/controllers/datasciencecluster/datasciencecluster_controller.go b/controllers/datasciencecluster/datasciencecluster_controller.go index c03a67e9579..4f5f356e4d3 100644 --- a/controllers/datasciencecluster/datasciencecluster_controller.go +++ b/controllers/datasciencecluster/datasciencecluster_controller.go @@ -21,7 +21,6 @@ import ( "context" "errors" "fmt" - "reflect" "strings" "time" @@ -58,7 +57,6 @@ import ( "github.com/opendatahub-io/opendatahub-operator/v2/controllers/status" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster" odhClient "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/client" - ctrlogger "github.com/opendatahub-io/opendatahub-operator/v2/pkg/logger" annotations "github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/annotations" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/upgrade" @@ -288,6 +286,7 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R return ctrl.Result{}, nil } +// TODO: make it generic for all components. func (r *DataScienceClusterReconciler) reconcileDashboardComponent(ctx context.Context, instance *dscv1.DataScienceCluster) (*dscv1.DataScienceCluster, error) { r.Log.Info("Starting reconciliation of Dashboard component") componentName := componentsctrl.ComponentName @@ -311,11 +310,6 @@ func (r *DataScienceClusterReconciler) reconcileDashboardComponent(ctx context.C // Create the Dashboard instance dashboard := componentsctrl.CreateDashboardInstance(instance) - if dashboard == nil { - return instance, fmt.Errorf("failed to create Dashboard instance: CreateDashboardInstance returned nil") - } - r.Log.Info("Created Dashboard instance", "type", reflect.TypeOf(dashboard)) - // Reconcile component err := r.apply(ctx, instance, dashboard) @@ -347,15 +341,6 @@ func (r *DataScienceClusterReconciler) reconcileDashboardComponent(ctx context.C return instance, nil } -// newComponentLogger is a wrapper to add DSC name and extract log mode from DSCISpec. -func newComponentLogger(logger logr.Logger, componentName string, dscispec *dsciv1.DSCInitializationSpec) logr.Logger { - mode := "" - if dscispec.DevFlags != nil { - mode = dscispec.DevFlags.LogMode - } - return ctrlogger.NewNamedLogger(logger, "DSC.Components."+componentName, mode) -} - func (r *DataScienceClusterReconciler) reportError(err error, instance *dscv1.DataScienceCluster, message string) *dscv1.DataScienceCluster { log := r.Log log.Error(err, message, "instance.Name", instance.Name) @@ -381,7 +366,7 @@ var configMapPredicates = predicate.Funcs{ func (r *DataScienceClusterReconciler) apply(ctx context.Context, dsc *dscv1.DataScienceCluster, obj client.Object) error { if obj.GetObjectKind().GroupVersionKind().Empty() { - return fmt.Errorf("no groupversionkind defined") + return errors.New("no groupversionkind defined") } if err := ctrl.SetControllerReference(dsc, obj, r.Scheme); err != nil { return err diff --git a/main.go b/main.go index 8441bf09de5..8ad711c6543 100644 --- a/main.go +++ b/main.go @@ -291,8 +291,8 @@ func main() { //nolint:funlen,maintidx os.Exit(1) } - if err = componentsctrl.NewDashboardReconciler(ctx, mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "DashboardReconciler") + // Initialize component reconcilers + if err = CreateComponentReconcilers(ctx, mgr); err != nil { os.Exit(1) } @@ -395,3 +395,12 @@ func createDeploymentCacheConfig(platform cluster.Platform) map[string]cache.Con namespaceConfigs[modelregistry.DefaultModelRegistriesNamespace] = cache.Config{} return namespaceConfigs } + +func CreateComponentReconcilers(ctx context.Context, mgr manager.Manager) error { + // TODO: add more here or make it go routine + if err := componentsctrl.NewDashboardReconciler(ctx, mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "DashboardReconciler") + return err + } + return nil +} diff --git a/pkg/cluster/gvk/gvk.go b/pkg/cluster/gvk/gvk.go index 44a823b7715..5f2e0229bb4 100644 --- a/pkg/cluster/gvk/gvk.go +++ b/pkg/cluster/gvk/gvk.go @@ -73,4 +73,58 @@ var ( Version: "v1", Kind: "Dashboard", } + + Workbenches = schema.GroupVersionKind{ + Group: "components.opendatahub.io", + Version: "v1", + Kind: "Workbenches", + } + + ModelMeshServing = schema.GroupVersionKind{ + Group: "components.opendatahub.io", + Version: "v1", + Kind: "ModelMeshServing", + } + + DataSciencePipelines = schema.GroupVersionKind{ + Group: "components.opendatahub.io", + Version: "v1", + Kind: "DataSciencePipelines", + } + + Kserve = schema.GroupVersionKind{ + Group: "components.opendatahub.io", + Version: "v1", + Kind: "Kserve", + } + + CodeFlare = schema.GroupVersionKind{ + Group: "components.opendatahub.io", + Version: "v1", + Kind: "CodeFlare", + } + + Ray = schema.GroupVersionKind{ + Group: "components.opendatahub.io", + Version: "v1", + Kind: "Ray", + } + + TrustyAI = schema.GroupVersionKind{ + Group: "components.opendatahub.io", + Version: "v1", + Kind: "TrustyAI", + } + + ModelRegistry = schema.GroupVersionKind{ + Group: "components.opendatahub.io", + Version: "v1", + Kind: "ModelRegistry", + } + + TrainingOperator = schema.GroupVersionKind{ + Group: "components.opendatahub.io", + Version: "v1", + Kind: "TrainingOperator", + } ) diff --git a/pkg/controller/reconciler/component_reconciler.go b/pkg/controller/reconciler/component_reconciler.go index 22bc74ee006..202376041d7 100644 --- a/pkg/controller/reconciler/component_reconciler.go +++ b/pkg/controller/reconciler/component_reconciler.go @@ -96,14 +96,12 @@ func (r *ComponentReconciler[T]) Reconcile(ctx context.Context, req ctrl.Request } rr := types.ReconciliationRequest{ - Client: r.Client, - Instance: res, - DSC: &dscl.Items[0], - DSCI: &dscil.Items[0], - Platform: r.Platform, - Manifests: types.Manifests{ - Paths: make(map[cluster.Platform]string), - }, + Client: r.Client, + Instance: res, + DSC: &dscl.Items[0], + DSCI: &dscil.Items[0], + Platform: r.Platform, + Manifests: make(map[cluster.Platform]string), } // Handle deletion diff --git a/pkg/controller/types/types.go b/pkg/controller/types/types.go index 9610cf82b46..a519632dce3 100644 --- a/pkg/controller/types/types.go +++ b/pkg/controller/types/types.go @@ -25,9 +25,5 @@ type ReconciliationRequest struct { DSC *dscv1.DataScienceCluster DSCI *dsciv1.DSCInitialization Platform cluster.Platform - Manifests Manifests -} - -type Manifests struct { - Paths map[cluster.Platform]string + Manifests map[cluster.Platform]string }