Skip to content

Commit

Permalink
Add TODO and refactor component reconciler
Browse files Browse the repository at this point in the history
Co-authored-by: Wen Zhou <[email protected]>
  • Loading branch information
VaishnaviHire and zdtsw committed Oct 15, 2024
1 parent f28d5c6 commit 8578f8f
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 37 deletions.
16 changes: 11 additions & 5 deletions controllers/components/dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
19 changes: 2 additions & 17 deletions controllers/datasciencecluster/datasciencecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"errors"
"fmt"
"reflect"
"strings"
"time"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
13 changes: 11 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}
54 changes: 54 additions & 0 deletions pkg/cluster/gvk/gvk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
)
14 changes: 6 additions & 8 deletions pkg/controller/reconciler/component_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions pkg/controller/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 8578f8f

Please sign in to comment.