Skip to content

Commit

Permalink
add watch for dashboardConfig code from Luca
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenTobin committed Jan 8, 2025
1 parent f4d422f commit dc1497a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions controllers/services/auth/auth_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -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
}

0 comments on commit dc1497a

Please sign in to comment.