Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added shared registries namespace property in model registry dsc component, fixes RHOAIENG-12335 #1221

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ resources:
path: github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1
version: v1
webhooks:
defaulting: true
validation: true
webhookVersion: v1
version: "3"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ spec:
managementState: Managed
modelregistry:
managementState: Managed
registriesNamespace: "odh-model-registries"
ray:
managementState: Managed
trainingoperator:
Expand Down
11 changes: 11 additions & 0 deletions apis/datasciencecluster/v1/datasciencecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/opendatahub-io/opendatahub-operator/v2/components/trainingoperator"
"github.com/opendatahub-io/opendatahub-operator/v2/components/trustyai"
"github.com/opendatahub-io/opendatahub-operator/v2/components/workbenches"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
)

Expand Down Expand Up @@ -86,6 +87,12 @@ type Components struct {
TrainingOperator trainingoperator.TrainingOperator `json:"trainingoperator,omitempty"`
}

// ComponentsStatus defines the custom status of DataScienceCluster components.
type ComponentsStatus struct {
// ModelRegistry component status
ModelRegistry *status.ModelRegistryStatus `json:"modelregistry,omitempty"`
}

// DataScienceClusterStatus defines the observed state of DataScienceCluster.
type DataScienceClusterStatus struct {
// Phase describes the Phase of DataScienceCluster reconciliation state
Expand All @@ -105,6 +112,10 @@ type DataScienceClusterStatus struct {
// List of components with status if installed or not
InstalledComponents map[string]bool `json:"installedComponents,omitempty"`

// Expose component's specific status
// +optional
Components ComponentsStatus `json:"components,omitempty"`

// Version and release type
Release cluster.Release `json:"release,omitempty"`
}
Expand Down
22 changes: 22 additions & 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 @@ -443,7 +443,21 @@ spec:
- Removed
pattern: ^(Managed|Unmanaged|Force|Removed)$
type: string
registriesNamespace:
default: odh-model-registries
description: Namespace for model registries to be installed,
configurable only once when model registry is enabled, defaults
to "odh-model-registries"
maxLength: 63
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$
type: string
type: object
x-kubernetes-validations:
- message: RegistriesNamespace is immutable when model registry
is Managed
rule: (self.managementState != 'Managed') || (oldSelf.registriesNamespace
== '') || (oldSelf.managementState != 'Managed')|| (self.registriesNamespace
== oldSelf.registriesNamespace)
ray:
description: Ray component configuration.
properties:
Expand Down Expand Up @@ -633,6 +647,16 @@ spec:
status:
description: DataScienceClusterStatus defines the observed state of DataScienceCluster.
properties:
components:
description: Expose component's specific status
properties:
modelregistry:
description: ModelRegistry component status
properties:
registriesNamespace:
type: string
type: object
type: object
conditions:
description: Conditions describes the state of the DataScienceCluster
resource.
Expand Down
23 changes: 22 additions & 1 deletion bundle/manifests/opendatahub-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ metadata:
"managementState": "Managed"
},
"modelregistry": {
"managementState": "Managed"
"managementState": "Managed",
"registriesNamespace": "odh-model-registries"
},
"ray": {
"managementState": "Managed"
Expand Down Expand Up @@ -1215,6 +1216,26 @@ spec:
component: opendatahub-operator
version: 2.17.0
webhookdefinitions:
- admissionReviewVersions:
- v1
containerPort: 443
deploymentName: opendatahub-operator-controller-manager
failurePolicy: Fail
generateName: mutate.operator.opendatahub.io
rules:
- apiGroups:
- datasciencecluster.opendatahub.io
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- datascienceclusters
sideEffects: None
targetPort: 9443
type: MutatingAdmissionWebhook
webhookPath: /mutate-opendatahub-io-v1
- admissionReviewVersions:
- v1
containerPort: 443
Expand Down
23 changes: 17 additions & 6 deletions components/modelregistry/modelregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,33 @@ import (
const DefaultModelRegistryCert = "default-modelregistry-cert"

var (
ComponentName = "model-registry-operator"
Path = deploy.DefaultManifestPath + "/" + ComponentName + "/overlays/odh"
ComponentName = "model-registry-operator"
DefaultModelRegistriesNamespace = "odh-model-registries"
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",
// ).
ModelRegistriesNamespace = "odh-model-registries"
)

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

// ModelRegistry struct holds the configuration for the ModelRegistry component.
// The property `registriesNamespace` is immutable when `managementState` is `Managed`

// +kubebuilder:object:generate=true
// +kubebuilder:validation:XValidation:rule="(self.managementState != 'Managed') || (oldSelf.registriesNamespace == '') || (oldSelf.managementState != 'Managed')|| (self.registriesNamespace == oldSelf.registriesNamespace)",message="RegistriesNamespace is immutable when model registry is Managed"
//nolint:lll

type ModelRegistry struct {
components.Component `json:""`

// Namespace for model registries to be installed, configurable only once when model registry is enabled, defaults to "odh-model-registries"
// +kubebuilder:default="odh-model-registries"
// +kubebuilder:validation:Pattern="^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$"
// +kubebuilder:validation:MaxLength=63
RegistriesNamespace string `json:"registriesNamespace,omitempty"`
zdtsw marked this conversation as resolved.
Show resolved Hide resolved
}

func (m *ModelRegistry) OverrideManifests(ctx context.Context, _ cluster.Platform) error {
Expand Down Expand Up @@ -109,17 +120,17 @@ func (m *ModelRegistry) ReconcileComponent(ctx context.Context, cli client.Clien

// Create model registries namespace
// We do not delete this namespace even when ModelRegistry is Removed or when operator is uninstalled.
ns, err := cluster.CreateNamespace(ctx, cli, ModelRegistriesNamespace)
ns, err := cluster.CreateNamespace(ctx, cli, m.RegistriesNamespace)
if err != nil {
return err
}
l.Info("created model registry namespace", "namespace", ModelRegistriesNamespace)
l.Info("created model registry namespace", "namespace", m.RegistriesNamespace)
// create servicemeshmember here, for now until post MVP solution
err = enrollToServiceMesh(ctx, cli, dscispec, ns)
if err != nil {
return err
}
l.Info("created model registry servicemesh member", "namespace", ModelRegistriesNamespace)
l.Info("created model registry servicemesh member", "namespace", m.RegistriesNamespace)
} else {
err := m.removeDependencies(ctx, cli, dscispec)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,21 @@ spec:
- Removed
pattern: ^(Managed|Unmanaged|Force|Removed)$
type: string
registriesNamespace:
default: odh-model-registries
description: Namespace for model registries to be installed,
configurable only once when model registry is enabled, defaults
to "odh-model-registries"
maxLength: 63
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?)?$
type: string
type: object
x-kubernetes-validations:
- message: RegistriesNamespace is immutable when model registry
is Managed
rule: (self.managementState != 'Managed') || (oldSelf.registriesNamespace
== '') || (oldSelf.managementState != 'Managed')|| (self.registriesNamespace
== oldSelf.registriesNamespace)
ray:
description: Ray component configuration.
properties:
Expand Down Expand Up @@ -633,6 +647,16 @@ spec:
status:
description: DataScienceClusterStatus defines the observed state of DataScienceCluster.
properties:
components:
description: Expose component's specific status
properties:
modelregistry:
description: ModelRegistry component status
properties:
registriesNamespace:
type: string
type: object
type: object
conditions:
description: Conditions describes the state of the DataScienceCluster
resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ spec:
managementState: "Managed"
modelregistry:
managementState: "Managed"
registriesNamespace: "odh-model-registries"
7 changes: 7 additions & 0 deletions config/webhook/kustomizeconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ nameReference:
- kind: Service
version: v1
fieldSpecs:
- kind: MutatingWebhookConfiguration
group: admissionregistration.k8s.io
path: webhooks/clientConfig/service/name
- kind: ValidatingWebhookConfiguration
group: admissionregistration.k8s.io
path: webhooks/clientConfig/service/name

namespace:
- kind: MutatingWebhookConfiguration
group: admissionregistration.k8s.io
path: webhooks/clientConfig/service/namespace
create: true
- kind: ValidatingWebhookConfiguration
group: admissionregistration.k8s.io
path: webhooks/clientConfig/service/namespace
Expand Down
26 changes: 26 additions & 0 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: mutating-webhook-configuration
webhooks:
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /mutate-opendatahub-io-v1
failurePolicy: Fail
name: mutate.operator.opendatahub.io
rules:
- apiGroups:
- datasciencecluster.opendatahub.io
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- datascienceclusters
sideEffects: None
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: validating-webhook-configuration
Expand Down
12 changes: 12 additions & 0 deletions controllers/datasciencecluster/datasciencecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
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/components/datasciencepipelines"
"github.com/opendatahub-io/opendatahub-operator/v2/components/modelregistry"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
annotations "github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/annotations"
Expand Down Expand Up @@ -316,6 +317,8 @@ func (r *DataScienceClusterReconciler) reconcileSubComponent(ctx context.Context
}
err = component.ReconcileComponent(ctx, r.Client, r.Log, instance, r.DataScienceCluster.DSCISpec, platform, installedComponentValue)

// TODO: replace this hack with a full refactor of component status in the future

if err != nil {
// reconciliation failed: log errors, raise event and update status accordingly
instance = r.reportError(err, instance, "failed to reconcile "+componentName+" on DataScienceCluster")
Expand Down Expand Up @@ -343,6 +346,15 @@ func (r *DataScienceClusterReconciler) reconcileSubComponent(ctx context.Context
} else {
status.RemoveComponentCondition(&saved.Status.Conditions, componentName)
}

// TODO: replace this hack with a full refactor of component status in the future
if mr, isMR := component.(*modelregistry.ModelRegistry); isMR {
if enabled {
saved.Status.Components.ModelRegistry = &status.ModelRegistryStatus{RegistriesNamespace: mr.RegistriesNamespace}
} else {
saved.Status.Components.ModelRegistry = nil
}
}
})
if err != nil {
instance = r.reportError(err, instance, "failed to update DataScienceCluster status after reconciling "+componentName)
Expand Down
5 changes: 5 additions & 0 deletions controllers/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,8 @@ func SetComponentCondition(conditions *[]conditionsv1.Condition, component strin
func RemoveComponentCondition(conditions *[]conditionsv1.Condition, component string) {
conditionsv1.RemoveStatusCondition(conditions, conditionsv1.ConditionType(component+ReadySuffix))
}

// ModelRegistryStatus struct holds the status for the ModelRegistry component.
type ModelRegistryStatus struct {
RegistriesNamespace string `json:"registriesNamespace,omitempty"`
}
Loading
Loading