Skip to content

Commit

Permalink
refactor: dashboard with new manifests structure (opendatahub-io#1065)
Browse files Browse the repository at this point in the history
* refactor: dashboard with new manifests structure

- change type of platform, skip convert to string
- add more support for ApplyParam() to
  not only take ENV but also anything from ExtraParamMaps
* update: simplify override function
* update: add value for Unknown platform
---------

Signed-off-by: Wen Zhou <[email protected]>
(cherry picked from commit 438f4c2)
  • Loading branch information
zdtsw authored and VaishnaviHire committed Jul 24, 2024
1 parent b10ab4a commit 7fd5586
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 19 deletions.
2 changes: 1 addition & 1 deletion components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ can be found [here](https://github.com/opendatahub-io/opendatahub-operator/tree/
Cleanup(cli client.Client, DSCISpec *dsciv1.DSCInitializationSpec) error
GetComponentName() string
GetManagementState() operatorv1.ManagementState
OverrideManifests(platform string) error
OverrideManifests(platform cluster.Platform) error
UpdatePrometheusConfig(cli client.Client, enable bool, component string) error
ConfigComponentLogger(logger logr.Logger, component string, dscispec *dsciv1.DSCInitializationSpec) logr.Logger
}
Expand Down
4 changes: 2 additions & 2 deletions components/codeflare/codeflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type CodeFlare struct {
components.Component `json:""`
}

func (c *CodeFlare) OverrideManifests(ctx context.Context, _ string) error {
func (c *CodeFlare) OverrideManifests(ctx context.Context, _ cluster.Platform) error {
// If devflags are set, update default manifests path
if len(c.DevFlags.Manifests) != 0 {
manifestConfig := c.DevFlags.Manifests[0]
Expand Down Expand Up @@ -76,7 +76,7 @@ func (c *CodeFlare) ReconcileComponent(ctx context.Context,
if enabled {
if c.DevFlags != nil {
// Download manifests and update paths
if err := c.OverrideManifests(ctx, string(platform)); err != nil {
if err := c.OverrideManifests(ctx, platform); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/datasciencepipelines/datasciencepipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type DataSciencePipelines struct {
components.Component `json:""`
}

func (d *DataSciencePipelines) OverrideManifests(ctx context.Context, _ string) error {
func (d *DataSciencePipelines) OverrideManifests(ctx context.Context, _ cluster.Platform) error {
// If devflags are set, update default manifests path
if len(d.DevFlags.Manifests) != 0 {
manifestConfig := d.DevFlags.Manifests[0]
Expand Down Expand Up @@ -97,7 +97,7 @@ func (d *DataSciencePipelines) ReconcileComponent(ctx context.Context,
if enabled {
if d.DevFlags != nil {
// Download manifests and update paths
if err := d.OverrideManifests(ctx, string(platform)); err != nil {
if err := d.OverrideManifests(ctx, platform); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/kserve/kserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type Kserve struct {
DefaultDeploymentMode DefaultDeploymentMode `json:"defaultDeploymentMode,omitempty"`
}

func (k *Kserve) OverrideManifests(ctx context.Context, _ string) error {
func (k *Kserve) OverrideManifests(ctx context.Context, _ cluster.Platform) error {
// Download manifests if defined by devflags
// Go through each manifest and set the overlays if defined
for _, subcomponent := range k.DevFlags.Manifests {
Expand Down Expand Up @@ -118,7 +118,7 @@ func (k *Kserve) ReconcileComponent(ctx context.Context, cli client.Client,
}
if k.DevFlags != nil {
// Download manifests and update paths
if err := k.OverrideManifests(ctx, string(platform)); err != nil {
if err := k.OverrideManifests(ctx, platform); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/kueue/kueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Kueue struct {
components.Component `json:""`
}

func (k *Kueue) OverrideManifests(ctx context.Context, _ string) error {
func (k *Kueue) OverrideManifests(ctx context.Context, _ cluster.Platform) error {
// If devflags are set, update default manifests path
if len(k.DevFlags.Manifests) != 0 {
manifestConfig := k.DevFlags.Manifests[0]
Expand Down Expand Up @@ -65,7 +65,7 @@ func (k *Kueue) ReconcileComponent(ctx context.Context, cli client.Client, logge
if enabled {
if k.DevFlags != nil {
// Download manifests and update paths
if err := k.OverrideManifests(ctx, string(platform)); err != nil {
if err := k.OverrideManifests(ctx, platform); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/modelmeshserving/modelmeshserving.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ModelMeshServing struct {
components.Component `json:""`
}

func (m *ModelMeshServing) OverrideManifests(ctx context.Context, _ string) error {
func (m *ModelMeshServing) OverrideManifests(ctx context.Context, _ cluster.Platform) error {
// Go through each manifest and set the overlays if defined
for _, subcomponent := range m.DevFlags.Manifests {
if strings.Contains(subcomponent.URI, DependentComponentName) {
Expand Down Expand Up @@ -100,7 +100,7 @@ func (m *ModelMeshServing) ReconcileComponent(ctx context.Context,
if enabled {
if m.DevFlags != nil {
// Download manifests and update paths
if err := m.OverrideManifests(ctx, string(platform)); err != nil {
if err := m.OverrideManifests(ctx, platform); err != nil {
return err
}
}
Expand Down
106 changes: 106 additions & 0 deletions components/modelregistry/modelregistry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Package modelregistry provides utility functions to config ModelRegistry, an ML Model metadata repository service
// +groupName=datasciencecluster.opendatahub.io
package modelregistry

import (
"context"
"fmt"
"path/filepath"

"github.com/go-logr/logr"
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

dsciv1 "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/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
)

var (
ComponentName = "model-registry-operator"
Path = deploy.DefaultManifestPath + "/" + ComponentName + "/overlays/odh"
// we should not apply this label to the namespace, as it triggered namspace deletion during operator uninstall
// modelRegistryLabels = cluster.WithLabels(
// labels.ODH.OwnedNamespace, "true",
// ).
)

// Verifies that ModelRegistry implements ComponentInterface.
var _ components.ComponentInterface = (*ModelRegistry)(nil)

// ModelRegistry struct holds the configuration for the ModelRegistry component.
// +kubebuilder:object:generate=true
type ModelRegistry struct {
components.Component `json:""`
}

func (m *ModelRegistry) OverrideManifests(ctx context.Context, _ cluster.Platform) error {
// If devflags are set, update default manifests path
if len(m.DevFlags.Manifests) != 0 {
manifestConfig := m.DevFlags.Manifests[0]
if err := deploy.DownloadManifests(ctx, ComponentName, manifestConfig); err != nil {
return err
}
// If overlay is defined, update paths
defaultKustomizePath := "overlays/odh"
if manifestConfig.SourcePath != "" {
defaultKustomizePath = manifestConfig.SourcePath
}
Path = filepath.Join(deploy.DefaultManifestPath, ComponentName, defaultKustomizePath)
}

return nil
}

func (m *ModelRegistry) GetComponentName() string {
return ComponentName
}

func (m *ModelRegistry) ReconcileComponent(ctx context.Context, cli client.Client, logger logr.Logger,
owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error {
l := m.ConfigComponentLogger(logger, ComponentName, dscispec)
var imageParamMap = map[string]string{
"IMAGES_MODELREGISTRY_OPERATOR": "RELATED_IMAGE_ODH_MODEL_REGISTRY_OPERATOR_IMAGE",
"IMAGES_GRPC_SERVICE": "RELATED_IMAGE_ODH_MLMD_GRPC_SERVER_IMAGE",
"IMAGES_REST_SERVICE": "RELATED_IMAGE_ODH_MODEL_REGISTRY_IMAGE",
}
enabled := m.GetManagementState() == operatorv1.Managed

if enabled {
if m.DevFlags != nil {
// Download manifests and update paths
if err := m.OverrideManifests(ctx, platform); err != nil {
return err
}
}

// Update image parameters only when we do not have customized manifests set
if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (m.DevFlags == nil || len(m.DevFlags.Manifests) == 0) {
if err := deploy.ApplyParams(Path, imageParamMap, false); err != nil {
return fmt.Errorf("failed to update image from %s : %w", Path, err)
}
}

// Create odh-model-registries namespace
// We do not delete this namespace even when ModelRegistry is Removed or when operator is uninstalled.
_, err := cluster.CreateNamespace(ctx, cli, "odh-model-registries")
if err != nil {
return err
}
}
// Deploy ModelRegistry Operator
if err := deploy.DeployManifestsFromPath(ctx, cli, owner, Path, dscispec.ApplicationsNamespace, m.GetComponentName(), enabled); err != nil {
return err
}
l.Info("apply manifests done")

// Create additional model registry resources, componentEnabled=true because these extras are never deleted!
if err := deploy.DeployManifestsFromPath(ctx, cli, owner, Path+"/extras", dscispec.ApplicationsNamespace, m.GetComponentName(), true); err != nil {
return err
}
l.Info("apply extra manifests done")

return nil
}
4 changes: 2 additions & 2 deletions components/ray/ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Ray struct {
components.Component `json:""`
}

func (r *Ray) OverrideManifests(ctx context.Context, _ string) error {
func (r *Ray) OverrideManifests(ctx context.Context, _ cluster.Platform) error {
// If devflags are set, update default manifests path
if len(r.DevFlags.Manifests) != 0 {
manifestConfig := r.DevFlags.Manifests[0]
Expand Down Expand Up @@ -69,7 +69,7 @@ func (r *Ray) ReconcileComponent(ctx context.Context, cli client.Client, logger
if enabled {
if r.DevFlags != nil {
// Download manifests and update paths
if err := r.OverrideManifests(ctx, string(platform)); err != nil {
if err := r.OverrideManifests(ctx, platform); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/trustyai/trustyai.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type TrustyAI struct {
components.Component `json:""`
}

func (t *TrustyAI) OverrideManifests(ctx context.Context, _ string) error {
func (t *TrustyAI) OverrideManifests(ctx context.Context, _ cluster.Platform) error {
// If devflags are set, update default manifests path
if len(t.DevFlags.Manifests) != 0 {
manifestConfig := t.DevFlags.Manifests[0]
Expand Down Expand Up @@ -68,7 +68,7 @@ func (t *TrustyAI) ReconcileComponent(ctx context.Context, cli client.Client, lo
if enabled {
if t.DevFlags != nil {
// Download manifests and update paths
if err := t.OverrideManifests(ctx, string(platform)); err != nil {
if err := t.OverrideManifests(ctx, platform); err != nil {
return err
}
}
Expand Down
6 changes: 3 additions & 3 deletions components/workbenches/workbenches.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Workbenches struct {
components.Component `json:""`
}

func (w *Workbenches) OverrideManifests(ctx context.Context, platform string) error {
func (w *Workbenches) OverrideManifests(ctx context.Context, platform cluster.Platform) error {
// Download manifests if defined by devflags
// Go through each manifest and set the overlays if defined
for _, subcomponent := range w.DevFlags.Manifests {
Expand All @@ -56,7 +56,7 @@ func (w *Workbenches) OverrideManifests(ctx context.Context, platform string) er
defaultKustomizePath = subcomponent.SourcePath
defaultKustomizePathSupported = subcomponent.SourcePath
}
if platform == string(cluster.ManagedRhods) || platform == string(cluster.SelfManagedRhods) {
if platform == cluster.ManagedRhods || platform == cluster.SelfManagedRhods {
notebookImagesPathSupported = filepath.Join(deploy.DefaultManifestPath, "jupyterhub", defaultKustomizePathSupported)
} else {
notebookImagesPath = filepath.Join(deploy.DefaultManifestPath, DependentComponentName, defaultKustomizePath)
Expand Down Expand Up @@ -113,7 +113,7 @@ func (w *Workbenches) ReconcileComponent(ctx context.Context, cli client.Client,
if enabled {
if w.DevFlags != nil {
// Download manifests and update paths
if err := w.OverrideManifests(ctx, string(platform)); err != nil {
if err := w.OverrideManifests(ctx, platform); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/addLabelsplugin.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package plugins

import (
"sigs.k8s.io/kustomize/api/builtins" //nolint:staticcheck //Remove after package update
"sigs.k8s.io/kustomize/api/builtins" //nolint:staticcheck // Remove after package update
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/resid"

Expand Down

0 comments on commit 7fd5586

Please sign in to comment.