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

Support to watch/own object not known when the operator starts, but only after a component has been enabled. #1385

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ linters-settings:
# also allow generics
- generic
- EventHandler # for ToOwner
- predicate.Predicate
- client.Object
revive:
rules:
- name: dot-imports
Expand Down
31 changes: 13 additions & 18 deletions bundle/manifests/opendatahub-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -501,14 +501,6 @@ spec:
- console.openshift.io
resources:
- consolelinks
verbs:
- create
- delete
- get
- patch
- apiGroups:
- console.openshift.io
resources:
- odhquickstarts
verbs:
- create
Expand Down Expand Up @@ -624,15 +616,6 @@ spec:
- dashboard.opendatahub.io
resources:
- acceleratorprofiles
verbs:
- create
- delete
- get
- list
- patch
- apiGroups:
- dashboard.opendatahub.io
resources:
- odhapplications
- odhdocuments
verbs:
Expand Down Expand Up @@ -800,7 +783,6 @@ spec:
resources:
- servicemeshcontrolplanes
- servicemeshmemberrolls
- servicemeshmembers
- servicemeshmembers/finalizers
verbs:
- create
Expand All @@ -810,6 +792,19 @@ spec:
- update
- use
- watch
- apiGroups:
- maistra.io
resources:
- servicemeshmembers
verbs:
- create
- delete
- get
- list
- patch
- update
- use
- watch
- apiGroups:
- modelregistry.opendatahub.io
resources:
Expand Down
31 changes: 13 additions & 18 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,6 @@ rules:
- console.openshift.io
resources:
- consolelinks
verbs:
- create
- delete
- get
- patch
- apiGroups:
- console.openshift.io
resources:
- odhquickstarts
verbs:
- create
Expand Down Expand Up @@ -376,15 +368,6 @@ rules:
- dashboard.opendatahub.io
resources:
- acceleratorprofiles
verbs:
- create
- delete
- get
- list
- patch
- apiGroups:
- dashboard.opendatahub.io
resources:
- odhapplications
- odhdocuments
verbs:
Expand Down Expand Up @@ -552,7 +535,6 @@ rules:
resources:
- servicemeshcontrolplanes
- servicemeshmemberrolls
- servicemeshmembers
- servicemeshmembers/finalizers
verbs:
- create
Expand All @@ -562,6 +544,19 @@ rules:
- update
- use
- watch
- apiGroups:
- maistra.io
resources:
- servicemeshmembers
verbs:
- create
- delete
- get
- list
- patch
- update
- use
- watch
- apiGroups:
- modelregistry.opendatahub.io
resources:
Expand Down
2 changes: 1 addition & 1 deletion controllers/components/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (s *componentHandler) Init(platform cluster.Platform) error {
return nil
}

func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object { //nolint:ireturn
func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object {
dashboardAnnotations := make(map[string]string)

switch dsc.Spec.Components.Dashboard.ManagementState {
Expand Down
17 changes: 15 additions & 2 deletions controllers/components/dashboard/dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"

componentsv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster/gvk"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/render"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/render/kustomize"
Expand Down Expand Up @@ -57,10 +57,16 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
// By default, a predicated for changed generation is added by the Owns()
// method, however for deployments, we also need to retrieve status info
// hence we need a dedicated predicate to react to replicas status change
Owns(&appsv1.Deployment{}, builder.WithPredicates(resources.NewDeploymentPredicate())).
Owns(&appsv1.Deployment{}, reconciler.WithPredicates(resources.NewDeploymentPredicate())).
// operands - openshift
Owns(&routev1.Route{}).
Owns(&consolev1.ConsoleLink{}).
// Those APIs are provided by the component itself hence they should
// be watched dynamically
OwnsGVK(gvk.AcceleratorProfile, reconciler.Dynamic()).
OwnsGVK(gvk.OdhApplication, reconciler.Dynamic()).
OwnsGVK(gvk.OdhDocument, reconciler.Dynamic()).
OwnsGVK(gvk.OdhQuickStart, reconciler.Dynamic()).
lburgazzoli marked this conversation as resolved.
Show resolved Hide resolved
// operands - watched
//
// By default the Watches functions adds:
Expand All @@ -71,6 +77,13 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
// set to the current owner
//
Watches(&extv1.CustomResourceDefinition{}).
// The OdhDashboardConfig resource is expected to be created by the operator
// but then owned by the user so we only re-create it with factory values if
// it gets deleted
WatchesGVK(gvk.OdhDashboardConfig,
reconciler.Dynamic(),
reconciler.WithPredicates(resources.Deleted()),
).
// actions
WithAction(initialize).
WithAction(devFlags).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *componentHandler) Init(platform cluster.Platform) error {
return nil
}

func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object { //nolint:ireturn
func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object {
dataSciencePipelinesAnnotations := make(map[string]string)

switch dsc.Spec.Components.DataSciencePipelines.ManagementState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"

componentsv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
Expand Down Expand Up @@ -64,7 +63,7 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
Owns(&corev1.ServiceAccount{}).
Owns(&corev1.Service{}).
Owns(&monitoringv1.ServiceMonitor{}).
Owns(&appsv1.Deployment{}, builder.WithPredicates(resources.NewDeploymentPredicate())).
Owns(&appsv1.Deployment{}, reconciler.WithPredicates(resources.NewDeploymentPredicate())).
Owns(&securityv1.SecurityContextConstraints{}).
Watches(&extv1.CustomResourceDefinition{}). // call ForLabel() + new predicates
// Add datasciencepipelines-specific actions
Expand Down
2 changes: 1 addition & 1 deletion controllers/components/kueue/kueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *componentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) ope
return dsc.Spec.Components.Kueue.ManagementState
}

func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object { //nolint:ireturn
func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object {
kueueAnnotations := make(map[string]string)
switch dsc.Spec.Components.Kueue.ManagementState {
case operatorv1.Managed, operatorv1.Removed:
Expand Down
3 changes: 1 addition & 2 deletions controllers/components/kueue/kueue_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"

componentsv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
Expand Down Expand Up @@ -59,7 +58,7 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
Owns(&promv1.PrometheusRule{}).
Owns(&admissionregistrationv1.MutatingWebhookConfiguration{}).
Owns(&admissionregistrationv1.ValidatingWebhookConfiguration{}).
Owns(&appsv1.Deployment{}, builder.WithPredicates(resources.NewDeploymentPredicate())).
Owns(&appsv1.Deployment{}, reconciler.WithPredicates(resources.NewDeploymentPredicate())).
Watches(&extv1.CustomResourceDefinition{}). // call ForLabel() + new predicates
// Add Kueue-specific actions
WithAction(initialize).
Expand Down
2 changes: 1 addition & 1 deletion controllers/components/modelregistry/modelregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *componentHandler) Init(_ cluster.Platform) error {
return nil
}

func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object { //nolint:ireturn
func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object {
componentAnnotations := make(map[string]string)

switch dsc.Spec.Components.ModelRegistry.ManagementState {
Expand Down
16 changes: 5 additions & 11 deletions controllers/components/modelregistry/modelregistry_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"

componentsv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster/gvk"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/render"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/render/kustomize"
Expand All @@ -53,10 +53,7 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
Owns(&rbacv1.ClusterRoleBinding{}).
Owns(&corev1.Service{}).
Owns(&corev1.ServiceAccount{}).
Owns(
&appsv1.Deployment{},
builder.WithPredicates(resources.NewDeploymentPredicate()),
).
Owns(&appsv1.Deployment{}, reconciler.WithPredicates(resources.NewDeploymentPredicate())).
Owns(&admissionregistrationv1.MutatingWebhookConfiguration{}).
Owns(&admissionregistrationv1.ValidatingWebhookConfiguration{}).
Watches(&corev1.Namespace{}).
Expand All @@ -66,12 +63,9 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
// in sync with the manifests, we should also create an additional watcher
Watches(&rbacv1.ClusterRole{}).
// This component adds a ServiceMeshMember resource to the registries
// namespaces that must be left even if the component is removed, hence
// we can't own.
//
// TODO: add dynamic watching for gvk.ServiceMeshMember if it make sense
// https://issues.redhat.com/browse/RHOAIENG-15170
//
// namespaces that may not be known when the controller is started, hence
// it should be watched dynamically
WatchesGVK(gvk.ServiceMeshMember, reconciler.Dynamic()).
// actions
WithAction(checkPreConditions).
WithAction(initialize).
Expand Down
2 changes: 1 addition & 1 deletion controllers/components/ray/ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *componentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) ope
return dsc.Spec.Components.Ray.ManagementState
}

func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object { //nolint:ireturn
func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object {
rayAnnotations := make(map[string]string)
switch dsc.Spec.Components.Ray.ManagementState {
case operatorv1.Managed, operatorv1.Removed:
Expand Down
3 changes: 1 addition & 2 deletions controllers/components/ray/ray_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"

componentsv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
Expand All @@ -51,7 +50,7 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
Owns(&rbacv1.Role{}).
Owns(&rbacv1.RoleBinding{}).
Owns(&corev1.ServiceAccount{}).
Owns(&appsv1.Deployment{}, builder.WithPredicates(resources.NewDeploymentPredicate())).
Owns(&appsv1.Deployment{}, reconciler.WithPredicates(resources.NewDeploymentPredicate())).
Owns(&securityv1.SecurityContextConstraints{}).
Watches(&extv1.CustomResourceDefinition{}). // call ForLabel() + new predicates
// Add Ray-specific actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *componentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) ope
return dsc.Spec.Components.TrainingOperator.ManagementState
}

func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) k8sclient.Object { //nolint:ireturn
func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) k8sclient.Object {
trainingoperatorAnnotations := make(map[string]string)
switch dsc.Spec.Components.TrainingOperator.ManagementState {
case operatorv1.Managed, operatorv1.Removed:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"

componentsv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
Expand All @@ -49,7 +48,7 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
Owns(&rbacv1.ClusterRoleBinding{}).
Owns(&rbacv1.ClusterRole{}).
Owns(&corev1.ServiceAccount{}).
Owns(&appsv1.Deployment{}, builder.WithPredicates(resources.NewDeploymentPredicate())).
Owns(&appsv1.Deployment{}, reconciler.WithPredicates(resources.NewDeploymentPredicate())).
Watches(&extv1.CustomResourceDefinition{}). // call ForLabel() + new predicates
// Add TrainingOperator-specific actions
WithAction(initialize).
Expand Down
2 changes: 1 addition & 1 deletion controllers/components/trustyai/trustyai.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *componentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) ope
return dsc.Spec.Components.TrustyAI.ManagementState
}

func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object { //nolint:ireturn
func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object {
trustyaiAnnotations := make(map[string]string)
switch dsc.Spec.Components.TrustyAI.ManagementState {
case operatorv1.Managed, operatorv1.Removed:
Expand Down
3 changes: 1 addition & 2 deletions controllers/components/trustyai/trustyai_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"

componentsv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
Expand All @@ -50,7 +49,7 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
Owns(&rbacv1.Role{}).
Owns(&rbacv1.RoleBinding{}).
Owns(&corev1.Service{}).
Owns(&appsv1.Deployment{}, builder.WithPredicates(resources.NewDeploymentPredicate())).
Owns(&appsv1.Deployment{}, reconciler.WithPredicates(resources.NewDeploymentPredicate())).
Watches(&extv1.CustomResourceDefinition{}). // call ForLabel() + new predicates
// Add TrustyAI-specific actions
WithAction(initialize).
Expand Down
8 changes: 4 additions & 4 deletions controllers/datasciencecluster/kubebuilder_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ package datasciencecluster

/* Only for RHODS */
// +kubebuilder:rbac:groups="user.openshift.io",resources=users,verbs=list;watch;patch;delete;get
// +kubebuilder:rbac:groups="console.openshift.io",resources=consolelinks,verbs=create;get;patch;delete
// +kubebuilder:rbac:groups="user.openshift.io",resources=groups,verbs=get;create;list;watch;patch;delete
// +kubebuilder:rbac:groups="console.openshift.io",resources=consolelinks,verbs=create;get;patch;list;delete;watch

// Ray
// +kubebuilder:rbac:groups=components.opendatahub.io,resources=rays,verbs=get;list;watch;create;update;patch;delete
Expand All @@ -138,9 +139,7 @@ package datasciencecluster
// +kubebuilder:rbac:groups="console.openshift.io",resources=odhquickstarts,verbs=create;get;patch;list;delete;watch
// +kubebuilder:rbac:groups="dashboard.opendatahub.io",resources=odhdocuments,verbs=create;get;patch;list;delete;watch
// +kubebuilder:rbac:groups="dashboard.opendatahub.io",resources=odhapplications,verbs=create;get;patch;list;delete;watch
// +kubebuilder:rbac:groups="dashboard.opendatahub.io",resources=acceleratorprofiles,verbs=create;get;patch;list;delete
// +kubebuilder:rbac:groups="user.openshift.io",resources=groups,verbs=get;create;list;watch;patch;delete
// +kubebuilder:rbac:groups="console.openshift.io",resources=consolelinks,verbs=create;get;patch;delete
// +kubebuilder:rbac:groups="dashboard.opendatahub.io",resources=acceleratorprofiles,verbs=create;get;patch;list;delete;watch

// ModelRegistry
// +kubebuilder:rbac:groups=components.opendatahub.io,resources=modelregistries,verbs=get;list;watch;create;update;patch;delete
Expand All @@ -149,6 +148,7 @@ package datasciencecluster
// +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;get
// +kubebuilder:rbac:groups=maistra.io,resources=servicemeshmembers,verbs=get;list;watch;create;update;patch;delete

// Kueue
// +kubebuilder:rbac:groups=components.opendatahub.io,resources=kueues,verbs=get;list;watch;create;update;patch;delete
Expand Down
6 changes: 6 additions & 0 deletions pkg/cluster/gvk/gvk.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ var (
Kind: "OdhDocument",
}

AcceleratorProfile = schema.GroupVersionKind{
Group: "dashboard.opendatahub.io",
Version: "v1",
Kind: "AcceleratorProfile",
}

OdhQuickStart = schema.GroupVersionKind{
Group: "console.openshift.io",
Version: "v1",
Expand Down
Loading