Skip to content

Commit

Permalink
feat: introduces features fluent interface
Browse files Browse the repository at this point in the history
Extracts the fluent interface for Features from PR opendatahub-io#605. This allows other components to configure cluster resources using this interface before the original PR gets merged.

No changes to the reconcile logic have been introduced.
  • Loading branch information
bartoszmajsak committed Oct 25, 2023
1 parent f8a23a5 commit 7ca9617
Show file tree
Hide file tree
Showing 42 changed files with 12,101 additions and 161 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ endef
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
# TODO: enable below when we do webhook
# $(CONTROLLER_GEN) rbac:roleName=controller-manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=controller-manager-role crd paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=controller-manager-role crd:ignoreUnexportedFields=true paths="./..." output:crd:artifacts:config=config/crd/bases
$(call fetch-external-crds,github.com/openshift/api,route/v1)
$(call fetch-external-crds,github.com/openshift/api,user/v1)

Expand Down Expand Up @@ -308,6 +308,8 @@ toolbox: ## Create a toolbox instance with the proper Golang and Operator SDK ve
toolbox create opendatahub-toolbox --image localhost/opendatahub-toolbox:latest

# Run tests.
TEST_SRC=./controllers/... ./tests/integration/features/...

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
Expand All @@ -318,7 +320,7 @@ test: unit-test e2e-test

.PHONY: unit-test
unit-test: envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./controllers/... -v -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $(TEST_SRC) -v -coverprofile cover.out

.PHONY: e2e-test
e2e-test: ## Run e2e tests for the controller
Expand Down
47 changes: 46 additions & 1 deletion apis/dscinitialization/v1/dscinitialization_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,51 @@ type DSCInitializationList struct {
Items []DSCInitialization `json:"items"`
}

// FeatureTracker is a cluster-scoped resource for tracking objects
// created through Features API for Data Science Platform.
// It's primarily used as owner reference for resources created across namespaces so that they can be
// garbage collected by Kubernetes when they're not needed anymore.
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster
type FeatureTracker struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec FeatureTrackerSpec `json:"spec,omitempty"`
Status FeatureTrackerStatus `json:"status,omitempty"`
}

func (s *FeatureTracker) ToOwnerReference() metav1.OwnerReference {
return metav1.OwnerReference{
APIVersion: s.APIVersion,
Kind: s.Kind,
Name: s.Name,
UID: s.UID,
}
}

// FeatureTrackerSpec defines the desired state of FeatureTracker.
type FeatureTrackerSpec struct {
}

// FeatureTrackerStatus defines the observed state of FeatureTracker.
type FeatureTrackerStatus struct {
}

// +kubebuilder:object:root=true

// FeatureTrackerList contains a list of FeatureTracker.
type FeatureTrackerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []FeatureTracker `json:"items"`
}

func init() {
SchemeBuilder.Register(&DSCInitialization{}, &DSCInitializationList{})
SchemeBuilder.Register(
&DSCInitialization{},
&DSCInitializationList{},
&FeatureTracker{},
&FeatureTrackerList{},
)
}
89 changes: 89 additions & 0 deletions apis/dscinitialization/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
@@ -0,0 +1,51 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: featuretrackers.dscinitialization.opendatahub.io
spec:
group: dscinitialization.opendatahub.io
names:
kind: FeatureTracker
listKind: FeatureTrackerList
plural: featuretrackers
singular: featuretracker
scope: Cluster
versions:
- name: v1
schema:
openAPIV3Schema:
description: FeatureTracker is a cluster-scoped resource for tracking objects
created through Features API for Data Science Platform. It's primarily used
as owner reference for resources created across namespaces so that they
can be garbage collected by Kubernetes when they're not needed anymore.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: FeatureTrackerSpec defines the desired state of FeatureTracker.
type: object
status:
description: FeatureTrackerStatus defines the observed state of FeatureTracker.
type: object
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: null
storedVersions: null
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ metadata:
categories: AI/Machine Learning, Big Data
certified: "False"
containerImage: quay.io/opendatahub/opendatahub-operator:v2.1.0
createdAt: "2023-8-23T00:00:00Z"
createdAt: "2023-10-25T18:45:11Z"
olm.skipRange: '>=1.0.0 <2.0.0'
operatorframework.io/initialization-resource: |-
{
Expand Down Expand Up @@ -117,7 +117,7 @@ metadata:
}
}
}
operators.operatorframework.io/builder: operator-sdk-v1.24.1
operators.operatorframework.io/builder: operator-sdk-v1.32.0
operators.operatorframework.io/internal-objects: '[dscinitialization.opendatahub.io]'
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/opendatahub-io/opendatahub-operator
Expand Down Expand Up @@ -158,6 +158,9 @@ spec:
displayName: Conditions
path: conditions
version: v1
- kind: FeatureTracker
name: featuretrackers.dscinitialization.opendatahub.io
version: v1
description: "The Open Data Hub is a machine-learning-as-a-service platform built
on Red Hat's Kubernetes-based OpenShift® Container Platform. Open Data Hub integrates
multiple AI/ML open source components into one operator that can easily be downloaded
Expand Down
2 changes: 1 addition & 1 deletion bundle/metadata/annotations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ annotations:
operators.operatorframework.io.bundle.package.v1: opendatahub-operator
operators.operatorframework.io.bundle.channels.v1: fast
operators.operatorframework.io.bundle.channel.default.v1: fast
operators.operatorframework.io.metrics.builder: operator-sdk-v1.24.1
operators.operatorframework.io.metrics.builder: operator-sdk-v1.32.0
operators.operatorframework.io.metrics.mediatype.v1: metrics+v1
operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v3

Expand Down
7 changes: 4 additions & 3 deletions components/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package dashboard
import (
"context"
"fmt"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"path/filepath"
"strings"

Expand Down Expand Up @@ -88,7 +89,7 @@ func (d *Dashboard) ReconcileComponent(cli client.Client, owner metav1.Object, d
}

if platform == deploy.OpenDataHub || platform == "" {
err := common.UpdatePodSecurityRolebinding(cli, []string{"odh-dashboard"}, dscispec.ApplicationsNamespace)
err := cluster.UpdatePodSecurityRolebinding(cli, dscispec.ApplicationsNamespace, "odh-dashboard")
if err != nil {
return err
}
Expand All @@ -99,7 +100,7 @@ func (d *Dashboard) ReconcileComponent(cli client.Client, owner metav1.Object, d
}

if platform == deploy.SelfManagedRhods || platform == deploy.ManagedRhods {
err := common.UpdatePodSecurityRolebinding(cli, []string{"rhods-dashboard"}, dscispec.ApplicationsNamespace)
err := cluster.UpdatePodSecurityRolebinding(cli, dscispec.ApplicationsNamespace, "rhods-dashboard")
if err != nil {
return err
}
Expand Down Expand Up @@ -187,7 +188,7 @@ func (d *Dashboard) applyRhodsSpecificConfigs(cli client.Client, owner metav1.Ob
return fmt.Errorf("failed to set dashboard OVMS from %s: %w", PathOVMS, err)
}

if err := common.CreateSecret(cli, "anaconda-ce-access", namespace); err != nil {
if err := cluster.CreateSecret(cli, "anaconda-ce-access", namespace); err != nil {
return fmt.Errorf("failed to create access-secret for anaconda: %w", err)
}

Expand Down
6 changes: 2 additions & 4 deletions components/kserve/kserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package kserve

import (
"fmt"

"path/filepath"
"strings"

dsci "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/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -122,8 +121,7 @@ func (k *Kserve) ReconcileComponent(cli client.Client, owner metav1.Object, dsci

// For odh-model-controller
if enabled {
err := common.UpdatePodSecurityRolebinding(cli, []string{"odh-model-controller"}, dscispec.ApplicationsNamespace)
if err != nil {
if err := cluster.UpdatePodSecurityRolebinding(cli, dscispec.ApplicationsNamespace, "odh-model-controller"); err != nil {
return err
}
// Update image parameters for odh-maodel-controller
Expand Down
11 changes: 7 additions & 4 deletions components/modelmeshserving/modelmeshserving.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

dsci "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/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -93,8 +93,11 @@ func (m *ModelMeshServing) ReconcileComponent(cli client.Client, owner metav1.Ob
return err
}

err := common.UpdatePodSecurityRolebinding(cli, []string{"modelmesh", "modelmesh-controller", "odh-prometheus-operator", "prometheus-custom"}, dscispec.ApplicationsNamespace)
if err != nil {
if err := cluster.UpdatePodSecurityRolebinding(cli, dscispec.ApplicationsNamespace,
"modelmesh",
"modelmesh-controller",
"odh-prometheus-operator",
"prometheus-custom"); err != nil {
return err
}
// Update image parameters
Expand All @@ -112,7 +115,7 @@ func (m *ModelMeshServing) ReconcileComponent(cli client.Client, owner metav1.Ob

// For odh-model-controller
if enabled {
err := common.UpdatePodSecurityRolebinding(cli, []string{"odh-model-controller"}, dscispec.ApplicationsNamespace)
err := cluster.UpdatePodSecurityRolebinding(cli, dscispec.ApplicationsNamespace, "odh-model-controller")
if 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 @@ -2,12 +2,12 @@
package workbenches

import (
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"path/filepath"
"strings"

dsci "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/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -111,14 +111,14 @@ func (w *Workbenches) ReconcileComponent(cli client.Client, owner metav1.Object,
}

if platform == deploy.SelfManagedRhods || platform == deploy.ManagedRhods {
err := common.CreateNamespace(cli, "rhods-notebooks")
err := cluster.CreateNamespace(cli, "rhods-notebooks")
if err != nil {
// no need to log error as it was already logged in createOdhNamespace
return err
}
}
// Update Default rolebinding
err = common.UpdatePodSecurityRolebinding(cli, []string{"notebook-controller-service-account"}, dscispec.ApplicationsNamespace)
err = cluster.UpdatePodSecurityRolebinding(cli, dscispec.ApplicationsNamespace, "notebook-controller-service-account")
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 7ca9617

Please sign in to comment.