From dc1497ade0ef77b13bdaf0c2ffbbfeac1d3ff597 Mon Sep 17 00:00:00 2001 From: Steven Tobin Date: Wed, 8 Jan 2025 12:24:56 +0000 Subject: [PATCH] add watch for dashboardConfig code from Luca --- controllers/services/auth/auth_controller.go | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/controllers/services/auth/auth_controller.go b/controllers/services/auth/auth_controller.go index 25086765700..c1bce1d1140 100644 --- a/controllers/services/auth/auth_controller.go +++ b/controllers/services/auth/auth_controller.go @@ -22,11 +22,23 @@ import ( rbacv1 "k8s.io/api/rbac/v1" ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/predicate" + componentsApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1" serviceApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/services/v1alpha1" + "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/template" + "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/handlers" + "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/predicates" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/reconciler" + "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/types" + "github.com/opendatahub-io/opendatahub-operator/v2/pkg/resources" +) + +const ( + odhDashboardConfigCRDName = "odhdashboardconfigs.opendatahub.io" ) // NewServiceReconciler creates a ServiceReconciler for the Auth API. @@ -37,6 +49,18 @@ func NewServiceReconciler(ctx context.Context, mgr ctrl.Manager) error { Owns(&rbacv1.ClusterRole{}). Owns(&rbacv1.Role{}). Owns(&rbacv1.RoleBinding{}). + WatchesGVK(gvk.Dashboard). + WatchesGVK( + gvk.CustomResourceDefinition, + reconciler.WithEventHandler(handlers.ToNamed(serviceApi.AuthInstanceName)), + reconciler.WithPredicates(predicate.NewPredicateFuncs(func(object client.Object) bool { + return object.GetName() == odhDashboardConfigCRDName + }))). + WatchesGVK( + gvk.OdhDashboardConfig, + reconciler.Dynamic(shouldWatchDashboardConfig), + reconciler.WithEventHandler(handlers.ToNamed(serviceApi.AuthInstanceName)), + reconciler.WithPredicates(predicates.DefaultPredicate)). // actions WithAction(initialize). WithAction(template.NewAction( @@ -56,3 +80,17 @@ func NewServiceReconciler(ctx context.Context, mgr ctrl.Manager) error { return nil } + +func shouldWatchDashboardConfig(ctx context.Context, request *types.ReconciliationRequest) bool { + d := resources.GvkToUnstructured(gvk.Dashboard) + if err := request.Client.Get(ctx, client.ObjectKey{Name: componentsApi.DashboardInstanceName}, d); err != nil { + return false + } + + c := resources.GvkToUnstructured(gvk.CustomResourceDefinition) + if err := request.Client.Get(ctx, client.ObjectKey{Name: odhDashboardConfigCRDName}, c); err != nil { + return false + } + + return true +}