Skip to content

Commit

Permalink
feat: Add ModelRegistry component (opendatahub-io#775) (opendatahub-i…
Browse files Browse the repository at this point in the history
…o#776)

* feat: Add ModelRegistry component (opendatahub-io#775)

* fix: Fix modelregistry odh overlays path

* fix: fix dsc_create_test tests err nil check

* fix: refactor ModelRegistry.ReconcileComponent for new parameters

* chore: added modelregistry to README.md

* fix: add missing rbac rules for deploymentconfigs and daemonsets

* chore: code lint cleanup

* fix: added check for nil DevFlags in model-registry component

* fix: add nil check for dscispec.DevFlags in model-registry ReconcileComponent

* fix: remove RBAC rules for daemonsets and deploymentconfigs

* fix(chore): fix lint errors in dsc_deletion_test.go
  • Loading branch information
dhirajsb authored Feb 1, 2024
1 parent da15814 commit 112d3f1
Show file tree
Hide file tree
Showing 17 changed files with 319 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ spec:
managementState: Managed
trustyai:
managementState: Managed
modelregistry:
managementState: Managed
```

2. Enable only Dashboard and Workbenches
Expand Down
4 changes: 4 additions & 0 deletions apis/datasciencecluster/v1/datasciencecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/opendatahub-io/opendatahub-operator/v2/components/datasciencepipelines"
"github.com/opendatahub-io/opendatahub-operator/v2/components/kserve"
"github.com/opendatahub-io/opendatahub-operator/v2/components/modelmeshserving"
"github.com/opendatahub-io/opendatahub-operator/v2/components/modelregistry"
"github.com/opendatahub-io/opendatahub-operator/v2/components/ray"
"github.com/opendatahub-io/opendatahub-operator/v2/components/trustyai"
"github.com/opendatahub-io/opendatahub-operator/v2/components/workbenches"
Expand Down Expand Up @@ -67,6 +68,9 @@ type Components struct {

// TrustyAI component configuration.
TrustyAI trustyai.TrustyAI `json:"trustyai,omitempty"`

// ModelRegistry component configuration.
ModelRegistry modelregistry.ModelRegistry `json:"modelregistry,omitempty"`
}

// DataScienceClusterStatus defines the observed state of DataScienceCluster.
Expand Down
1 change: 1 addition & 0 deletions apis/datasciencecluster/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,49 @@ spec:
pattern: ^(Managed|Unmanaged|Force|Removed)$
type: string
type: object
modelregistry:
description: ModelRegistry component configuration.
properties:
devFlags:
description: Add developer fields
properties:
manifests:
description: List of custom manifests for the given component
items:
properties:
contextDir:
default: ""
description: contextDir is the relative path to
the folder containing manifests in a repository
type: string
sourcePath:
default: ""
description: 'sourcePath is the subpath within contextDir
where kustomize builds start. Examples include
any sub-folder or path: `base`, `overlays/dev`,
`default`, `odh` etc'
type: string
uri:
default: ""
description: uri is the URI point to a git repo
with tag/branch. e.g https://github.com/org/repo/tarball/<tag/branch>
type: string
type: object
type: array
type: object
managementState:
description: "Set to one of the following values: \n - \"Managed\"
: the operator is actively managing the component and trying
to keep it active. It will only upgrade the component if
it is safe to do so \n - \"Removed\" : the operator is actively
managing the component and will not install it, or if it
is installed, the operator will try to remove it"
enum:
- Managed
- Removed
pattern: ^(Managed|Unmanaged|Force|Removed)$
type: string
type: object
ray:
description: Ray component configuration.
properties:
Expand Down
29 changes: 29 additions & 0 deletions bundle/manifests/opendatahub-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ metadata:
"modelmeshserving": {
"managementState": "Managed"
},
"modelregistry": {
"managementState": "Removed"
},
"ray": {
"managementState": "Removed"
},
Expand Down Expand Up @@ -980,6 +983,32 @@ spec:
- get
- list
- patch
- apiGroups:
- modelregistry.opendatahub.io
resources:
- modelregistries
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- modelregistry.opendatahub.io
resources:
- modelregistries/finalizers
verbs:
- update
- apiGroups:
- modelregistry.opendatahub.io
resources:
- modelregistries/status
verbs:
- get
- patch
- update
- apiGroups:
- monitoring.coreos.com
resources:
Expand Down
1 change: 1 addition & 0 deletions components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ can be found [here](https://github.com/opendatahub-io/opendatahub-operator/tree/
- [ModelMesh Serving](https://github.com/opendatahub-io/opendatahub-operator/tree/main/components/modelmeshserving)
- [Workbenches](https://github.com/opendatahub-io/opendatahub-operator/tree/main/components/workbenches)
- [TrustyAI](https://github.com/opendatahub-io/opendatahub-operator/tree/main/components/trustyai)
- [ModelRegistry](https://github.com/opendatahub-io/opendatahub-operator/tree/main/components/modelregistry)
87 changes: 87 additions & 0 deletions components/modelregistry/modelregistry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Package modelregistry provides utility functions to config ModelRegistry, an ML Model metadata repository service
package modelregistry

import (
"context"
"path/filepath"

operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
"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/deploy"
)

var (
ComponentName = "model-registry-operator"
Path = deploy.DefaultManifestPath + "/" + ComponentName + "/overlays/odh"
)

// 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(_ string) error {
// If devflags are set, update default manifests path
if len(m.DevFlags.Manifests) != 0 {
manifestConfig := m.DevFlags.Manifests[0]
if err := deploy.DownloadManifests(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(_ context.Context, cli client.Client, _ *rest.Config,
owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, _ bool) error {
var imageParamMap = map[string]string{
"IMAGES_MODELREGISTRY_OPERATOR": "RELATED_IMAGE_ODH_MODELREGISTRY_OPERATOR_IMAGE",
"IMAGES_GRPC_SERVICE": "RELATED_IMAGE_ODH_MODELREGISTRY_GRPC_SERVICE_IMAGE",
"IMAGES_REST_SERVICE": "RELATED_IMAGE_ODH_MODELREGISTRY_REST_SERVICE_IMAGE",
}
enabled := m.GetManagementState() == operatorv1.Managed

platform, err := deploy.GetPlatform(cli)
if err != nil {
return err
}

if enabled {
if m.DevFlags != nil {
// Download manifests and update paths
if err = m.OverrideManifests(string(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, m.SetImageParamsMap(imageParamMap), false); err != nil {
return err
}
}
}
// Deploy ModelRegistry Operator
err = deploy.DeployManifestsFromPath(cli, owner, Path, dscispec.ApplicationsNamespace, m.GetComponentName(), enabled)

return err
}
40 changes: 40 additions & 0 deletions components/modelregistry/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,49 @@ spec:
pattern: ^(Managed|Unmanaged|Force|Removed)$
type: string
type: object
modelregistry:
description: ModelRegistry component configuration.
properties:
devFlags:
description: Add developer fields
properties:
manifests:
description: List of custom manifests for the given component
items:
properties:
contextDir:
default: ""
description: contextDir is the relative path to
the folder containing manifests in a repository
type: string
sourcePath:
default: ""
description: 'sourcePath is the subpath within contextDir
where kustomize builds start. Examples include
any sub-folder or path: `base`, `overlays/dev`,
`default`, `odh` etc'
type: string
uri:
default: ""
description: uri is the URI point to a git repo
with tag/branch. e.g https://github.com/org/repo/tarball/<tag/branch>
type: string
type: object
type: array
type: object
managementState:
description: "Set to one of the following values: \n - \"Managed\"
: the operator is actively managing the component and trying
to keep it active. It will only upgrade the component if
it is safe to do so \n - \"Removed\" : the operator is actively
managing the component and will not install it, or if it
is installed, the operator will try to remove it"
enum:
- Managed
- Removed
pattern: ^(Managed|Unmanaged|Force|Removed)$
type: string
type: object
ray:
description: Ray component configuration.
properties:
Expand Down
26 changes: 26 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,32 @@ rules:
- get
- list
- patch
- apiGroups:
- modelregistry.opendatahub.io
resources:
- modelregistries
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- modelregistry.opendatahub.io
resources:
- modelregistries/finalizers
verbs:
- update
- apiGroups:
- modelregistry.opendatahub.io
resources:
- modelregistries/status
verbs:
- get
- patch
- update
- apiGroups:
- monitoring.coreos.com
resources:
Expand Down
2 changes: 2 additions & 0 deletions config/samples/datasciencecluster_v1_datasciencecluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ spec:
managementState: "Managed"
trustyai:
managementState: "Managed"
modelregistry:
managementState: "Removed"
4 changes: 4 additions & 0 deletions controllers/datasciencecluster/kubebuilder_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ package datasciencecluster
//+kubebuilder:rbac:groups=trustyai.opendatahub.io,resources=trustyaiservices/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=trustyai.opendatahub.io,resources=trustyaiservices/finalizers,verbs=update

//+kubebuilder:rbac:groups=modelregistry.opendatahub.io,resources=modelregistries,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=modelregistry.opendatahub.io,resources=modelregistries/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=modelregistry.opendatahub.io,resources=modelregistries/finalizers,verbs=update

// +kubebuilder:rbac:groups="monitoring.coreos.com",resources=prometheuses/finalizers,verbs=get;create;patch;delete;deletecollection
// +kubebuilder:rbac:groups="monitoring.coreos.com",resources=prometheuses/status,verbs=get;create;patch;delete;deletecollection

Expand Down
3 changes: 2 additions & 1 deletion get_all_manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

GITHUB_URL="https://github.com/"

# component: notebook, dsp, kserve, dashbaord, cf/ray, trustyai, modelmesh.
# component: notebook, dsp, kserve, dashbaord, cf/ray, trustyai, modelmesh, modelregistry.
# in the format of "repo-org:repo-name:branch-name:source-folder:target-folder".
declare -A COMPONENT_MANIFESTS=(
["codeflare"]="opendatahub-io:codeflare-operator:main:config:codeflare"
Expand All @@ -17,6 +17,7 @@ declare -A COMPONENT_MANIFESTS=(
["model-mesh"]="opendatahub-io:modelmesh-serving:release-0.11.0:config:model-mesh"
["odh-model-controller"]="opendatahub-io:odh-model-controller:release-0.11.0:config:odh-model-controller"
["kserve"]="opendatahub-io:kserve:release-v0.11.0:config:kserve"
["modelregistry"]="opendatahub-io:model-registry-operator:main:config:model-registry-operator"
)

# Allow overwriting repo using flags component=repo
Expand Down
4 changes: 4 additions & 0 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/opendatahub-io/opendatahub-operator/v2/components/datasciencepipelines"
"github.com/opendatahub-io/opendatahub-operator/v2/components/kserve"
"github.com/opendatahub-io/opendatahub-operator/v2/components/modelmeshserving"
"github.com/opendatahub-io/opendatahub-operator/v2/components/modelregistry"
"github.com/opendatahub-io/opendatahub-operator/v2/components/ray"
"github.com/opendatahub-io/opendatahub-operator/v2/components/trustyai"
"github.com/opendatahub-io/opendatahub-operator/v2/components/workbenches"
Expand Down Expand Up @@ -173,6 +174,9 @@ func CreateDefaultDSC(cli client.Client, _ deploy.Platform) error {
TrustyAI: trustyai.TrustyAI{
Component: components.Component{ManagementState: operatorv1.Managed},
},
ModelRegistry: modelregistry.ModelRegistry{
Component: components.Component{ManagementState: operatorv1.Removed},
},
},
},
}
Expand Down
Loading

0 comments on commit 112d3f1

Please sign in to comment.