Skip to content

Commit

Permalink
Remove generics for ComponentReconciler and ComponentReconcilerBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Nov 5, 2024
1 parent c8df75f commit 19a39bd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion controllers/components/dashboard/dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
func NewComponentReconciler(ctx context.Context, mgr ctrl.Manager) error {
componentName := computeComponentName()

_, err := reconciler.ComponentReconcilerFor[*componentsv1.Dashboard](mgr, componentsv1.DashboardInstanceName, &componentsv1.Dashboard{}).
_, err := reconciler.ComponentReconcilerFor(mgr, componentsv1.DashboardInstanceName, &componentsv1.Dashboard{}).
// operands - owned
Owns(&corev1.ConfigMap{}).
Owns(&corev1.Secret{}).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (

// NewComponentReconciler creates a ComponentReconciler for the Dashboard API.
func NewComponentReconciler(ctx context.Context, mgr ctrl.Manager) error {
_, err := reconciler.ComponentReconcilerFor[*componentsv1.ModelRegistry](
_, err := reconciler.ComponentReconcilerFor(
mgr,
componentsv1.ModelRegistryInstanceName,
&componentsv1.ModelRegistry{},
Expand Down
2 changes: 1 addition & 1 deletion controllers/components/ray/ray_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
)

func NewComponentReconciler(ctx context.Context, mgr ctrl.Manager) error {
_, err := reconciler.ComponentReconcilerFor[*componentsv1.Ray](
_, err := reconciler.ComponentReconcilerFor(
mgr,
componentsv1.RayInstanceName,
&componentsv1.Ray{},
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/reconciler/component_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ComponentReconciler struct {
instanceFactory func() (components.ComponentObject, error)
}

func NewComponentReconciler[T components.ComponentObject](ctx context.Context, mgr manager.Manager, name string) (*ComponentReconciler, error) {
func NewComponentReconciler(ctx context.Context, mgr manager.Manager, name string, object components.ComponentObject) (*ComponentReconciler, error) {
oc, err := odhClient.NewFromManager(ctx, mgr)
if err != nil {
return nil, err
Expand All @@ -57,8 +57,8 @@ func NewComponentReconciler[T components.ComponentObject](ctx context.Context, m
name: name,
m: odhManager.New(mgr),
instanceFactory: func() (components.ComponentObject, error) {
t := reflect.TypeOf(*new(T)).Elem()
res, ok := reflect.New(t).Interface().(T)
t := reflect.TypeOf(object).Elem()
res, ok := reflect.New(t).Interface().(components.ComponentObject)
if !ok {
return res, fmt.Errorf("unable to construct instance of %v", t)
}
Expand Down
30 changes: 15 additions & 15 deletions pkg/controller/reconciler/component_reconciler_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

type forInput struct {
object client.Object
object components.ComponentObject
options []builder.ForOption
}

Expand All @@ -37,7 +37,7 @@ type ownInput struct {
options []builder.OwnsOption
}

type ComponentReconcilerBuilder[T components.ComponentObject] struct {
type ComponentReconcilerBuilder struct {
mgr ctrl.Manager
input forInput
watches []watchInput
Expand All @@ -49,8 +49,8 @@ type ComponentReconcilerBuilder[T components.ComponentObject] struct {
finalizers []actions.Fn
}

func ComponentReconcilerFor[T components.ComponentObject](mgr ctrl.Manager, ownerName string, object T, opts ...builder.ForOption) *ComponentReconcilerBuilder[T] {
crb := ComponentReconcilerBuilder[T]{
func ComponentReconcilerFor(mgr ctrl.Manager, ownerName string, object components.ComponentObject, opts ...builder.ForOption) *ComponentReconcilerBuilder {
crb := ComponentReconcilerBuilder{
mgr: mgr,
ownerName: ownerName,
input: forInput{
Expand All @@ -62,22 +62,22 @@ func ComponentReconcilerFor[T components.ComponentObject](mgr ctrl.Manager, owne
return &crb
}

func (b *ComponentReconcilerBuilder[T]) WithComponentName(componentName string) *ComponentReconcilerBuilder[T] {
func (b *ComponentReconcilerBuilder) WithComponentName(componentName string) *ComponentReconcilerBuilder {
b.componentName = componentName
return b
}

func (b *ComponentReconcilerBuilder[T]) WithAction(value actions.Fn) *ComponentReconcilerBuilder[T] {
func (b *ComponentReconcilerBuilder) WithAction(value actions.Fn) *ComponentReconcilerBuilder {
b.actions = append(b.actions, value)
return b
}

func (b *ComponentReconcilerBuilder[T]) WithFinalizer(value actions.Fn) *ComponentReconcilerBuilder[T] {
func (b *ComponentReconcilerBuilder) WithFinalizer(value actions.Fn) *ComponentReconcilerBuilder {
b.finalizers = append(b.finalizers, value)
return b
}

func (b *ComponentReconcilerBuilder[T]) Watches(object client.Object, opts ...builder.WatchesOption) *ComponentReconcilerBuilder[T] {
func (b *ComponentReconcilerBuilder) Watches(object client.Object, opts ...builder.WatchesOption) *ComponentReconcilerBuilder {
b.watches = append(b.watches, watchInput{
object: object,
eventHandler: handlers.ToOwner(),
Expand All @@ -87,7 +87,7 @@ func (b *ComponentReconcilerBuilder[T]) Watches(object client.Object, opts ...bu
return b
}

func (b *ComponentReconcilerBuilder[T]) WatchesH(object client.Object, eventHandler handler.EventHandler, opts ...builder.WatchesOption) *ComponentReconcilerBuilder[T] {
func (b *ComponentReconcilerBuilder) WatchesH(object client.Object, eventHandler handler.EventHandler, opts ...builder.WatchesOption) *ComponentReconcilerBuilder {
b.watches = append(b.watches, watchInput{
object: object,
eventHandler: eventHandler,
Expand All @@ -97,7 +97,7 @@ func (b *ComponentReconcilerBuilder[T]) WatchesH(object client.Object, eventHand
return b
}

func (b *ComponentReconcilerBuilder[T]) WatchesGVK(gvk schema.GroupVersionKind, eventHandler handler.EventHandler, opts ...builder.WatchesOption) *ComponentReconcilerBuilder[T] {
func (b *ComponentReconcilerBuilder) WatchesGVK(gvk schema.GroupVersionKind, eventHandler handler.EventHandler, opts ...builder.WatchesOption) *ComponentReconcilerBuilder {
u := unstructured.Unstructured{}
u.SetGroupVersionKind(gvk)

Expand All @@ -110,7 +110,7 @@ func (b *ComponentReconcilerBuilder[T]) WatchesGVK(gvk schema.GroupVersionKind,
return b
}

func (b *ComponentReconcilerBuilder[T]) WatchesM(object client.Object, fn handler.MapFunc, opts ...builder.WatchesOption) *ComponentReconcilerBuilder[T] {
func (b *ComponentReconcilerBuilder) WatchesM(object client.Object, fn handler.MapFunc, opts ...builder.WatchesOption) *ComponentReconcilerBuilder {
b.watches = append(b.watches, watchInput{
object: object,
eventHandler: handler.EnqueueRequestsFromMapFunc(fn),
Expand All @@ -120,7 +120,7 @@ func (b *ComponentReconcilerBuilder[T]) WatchesM(object client.Object, fn handle
return b
}

func (b *ComponentReconcilerBuilder[T]) Owns(object client.Object, opts ...builder.OwnsOption) *ComponentReconcilerBuilder[T] {
func (b *ComponentReconcilerBuilder) Owns(object client.Object, opts ...builder.OwnsOption) *ComponentReconcilerBuilder {
b.owns = append(b.owns, ownInput{
object: object,
options: slices.Clone(opts),
Expand All @@ -129,12 +129,12 @@ func (b *ComponentReconcilerBuilder[T]) Owns(object client.Object, opts ...build
return b
}

func (b *ComponentReconcilerBuilder[T]) WithEventFilter(p predicate.Predicate) *ComponentReconcilerBuilder[T] {
func (b *ComponentReconcilerBuilder) WithEventFilter(p predicate.Predicate) *ComponentReconcilerBuilder {
b.predicates = append(b.predicates, p)
return b
}

func (b *ComponentReconcilerBuilder[T]) Build(ctx context.Context) (*ComponentReconciler, error) {
func (b *ComponentReconcilerBuilder) Build(ctx context.Context) (*ComponentReconciler, error) {
name := b.componentName
if name == "" {
kinds, _, err := b.mgr.GetScheme().ObjectKinds(b.input.object)
Expand All @@ -149,7 +149,7 @@ func (b *ComponentReconcilerBuilder[T]) Build(ctx context.Context) (*ComponentRe
name = strings.ToLower(name)
}

r, err := NewComponentReconciler[T](ctx, b.mgr, name)
r, err := NewComponentReconciler(ctx, b.mgr, name, b.input.object)
if err != nil {
return nil, fmt.Errorf("failed to create reconciler for component %s: %w", name, err)
}
Expand Down

0 comments on commit 19a39bd

Please sign in to comment.