Skip to content

Commit

Permalink
feat: introduces features fluent interface (#668)
Browse files Browse the repository at this point in the history
Extracts the fluent interface for Features from PR #605. This allows other components to configure cluster resources using this approach before the original PR gets merged.
  • Loading branch information
bartoszmajsak authored Nov 1, 2023
1 parent eaa564e commit adb6658
Show file tree
Hide file tree
Showing 47 changed files with 1,979 additions and 157 deletions.
2 changes: 1 addition & 1 deletion Dockerfiles/bundle.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
LABEL operators.operatorframework.io.bundle.package.v1=opendatahub-operator
LABEL operators.operatorframework.io.bundle.channels.v1=fast
LABEL operators.operatorframework.io.bundle.channel.default.v1=fast
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.24.1
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.32.0
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3

Expand Down
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
19 changes: 17 additions & 2 deletions bundle/manifests/opendatahub-operator.clusterserviceversion.yaml
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-30T14:38:57Z"
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 Expand Up @@ -807,6 +810,18 @@ spec:
- get
- patch
- update
- apiGroups:
- dscinitialization.opendatahub.io
resources:
- featuretrackers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- events.k8s.io
resources:
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
14 changes: 7 additions & 7 deletions components/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"strings"

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

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

routev1 "github.com/openshift/api/route/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var (
Expand Down Expand Up @@ -88,7 +88,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 +99,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 +187,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
Loading

0 comments on commit adb6658

Please sign in to comment.