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

chore: remove generics from Reconcier and use PlatformObject as base object type #1514

Merged
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
28 changes: 14 additions & 14 deletions pkg/controller/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
)

// Reconciler provides generic reconciliation functionality for ODH objects.
type Reconciler[T common.PlatformObject] struct {
type Reconciler struct {
Client *odhClient.Client
Scheme *runtime.Scheme
Actions []actions.Fn
Expand All @@ -39,25 +39,25 @@

name string
m *odhManager.Manager
instanceFactory func() (T, error)
instanceFactory func() (common.PlatformObject, error)
}

// NewReconciler creates a new reconciler for the given type.
func NewReconciler[T common.PlatformObject](mgr manager.Manager, name string, object T) (*Reconciler[T], error) {
func NewReconciler[T common.PlatformObject](mgr manager.Manager, name string, object T) (*Reconciler, error) {

Check warning on line 46 in pkg/controller/reconciler/reconciler.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/reconciler/reconciler.go#L46

Added line #L46 was not covered by tests
oc, err := odhClient.NewFromManager(mgr)
if err != nil {
return nil, err
}

cc := Reconciler[T]{
cc := Reconciler{

Check warning on line 52 in pkg/controller/reconciler/reconciler.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/reconciler/reconciler.go#L52

Added line #L52 was not covered by tests
Client: oc,
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("controllers").WithName(name),
Recorder: mgr.GetEventRecorderFor(name),
Release: cluster.GetRelease(),
name: name,
m: odhManager.New(mgr),
instanceFactory: func() (T, error) {
instanceFactory: func() (common.PlatformObject, error) {

Check warning on line 60 in pkg/controller/reconciler/reconciler.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/reconciler/reconciler.go#L60

Added line #L60 was not covered by tests
t := reflect.TypeOf(object).Elem()
res, ok := reflect.New(t).Interface().(T)
if !ok {
Expand All @@ -71,31 +71,31 @@
return &cc, nil
}

func (r *Reconciler[T]) GetRelease() cluster.Release {
func (r *Reconciler) GetRelease() cluster.Release {

Check warning on line 74 in pkg/controller/reconciler/reconciler.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/reconciler/reconciler.go#L74

Added line #L74 was not covered by tests
return r.Release
}

func (r *Reconciler[T]) GetLogger() logr.Logger {
func (r *Reconciler) GetLogger() logr.Logger {

Check warning on line 78 in pkg/controller/reconciler/reconciler.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/reconciler/reconciler.go#L78

Added line #L78 was not covered by tests
return r.Log
}

func (r *Reconciler[T]) AddOwnedType(gvk schema.GroupVersionKind) {
func (r *Reconciler) AddOwnedType(gvk schema.GroupVersionKind) {

Check warning on line 82 in pkg/controller/reconciler/reconciler.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/reconciler/reconciler.go#L82

Added line #L82 was not covered by tests
r.m.AddGVK(gvk, true)
}

func (r *Reconciler[T]) Owns(obj client.Object) bool {
func (r *Reconciler) Owns(obj client.Object) bool {

Check warning on line 86 in pkg/controller/reconciler/reconciler.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/reconciler/reconciler.go#L86

Added line #L86 was not covered by tests
return r.m.Owns(obj.GetObjectKind().GroupVersionKind())
}

func (r *Reconciler[T]) AddAction(action actions.Fn) {
func (r *Reconciler) AddAction(action actions.Fn) {

Check warning on line 90 in pkg/controller/reconciler/reconciler.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/reconciler/reconciler.go#L90

Added line #L90 was not covered by tests
r.Actions = append(r.Actions, action)
}

func (r *Reconciler[T]) AddFinalizer(action actions.Fn) {
func (r *Reconciler) AddFinalizer(action actions.Fn) {

Check warning on line 94 in pkg/controller/reconciler/reconciler.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/reconciler/reconciler.go#L94

Added line #L94 was not covered by tests
r.Finalizer = append(r.Finalizer, action)
}

func (r *Reconciler[T]) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {

Check warning on line 98 in pkg/controller/reconciler/reconciler.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/reconciler/reconciler.go#L98

Added line #L98 was not covered by tests
l := log.FromContext(ctx)
l.Info("reconcile")

Expand All @@ -121,7 +121,7 @@
return ctrl.Result{}, nil
}

func (r *Reconciler[T]) delete(ctx context.Context, res client.Object) error {
func (r *Reconciler) delete(ctx context.Context, res common.PlatformObject) error {

Check warning on line 124 in pkg/controller/reconciler/reconciler.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/reconciler/reconciler.go#L124

Added line #L124 was not covered by tests
l := log.FromContext(ctx)
l.Info("delete")

Expand Down Expand Up @@ -162,7 +162,7 @@
return nil
}

func (r *Reconciler[T]) apply(ctx context.Context, res client.Object) error {
func (r *Reconciler) apply(ctx context.Context, res common.PlatformObject) error {

Check warning on line 165 in pkg/controller/reconciler/reconciler.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/reconciler/reconciler.go#L165

Added line #L165 was not covered by tests
l := log.FromContext(ctx)
l.Info("apply")

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/reconciler/reconciler_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
return b.Owns(resources.GvkToUnstructured(gvk), opts...)
}

func (b *ReconcilerBuilder[T]) Build(_ context.Context) (*Reconciler[T], error) {
func (b *ReconcilerBuilder[T]) Build(_ context.Context) (*Reconciler, error) {

Check warning on line 195 in pkg/controller/reconciler/reconciler_support.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/reconciler/reconciler_support.go#L195

Added line #L195 was not covered by tests
if b.errors != nil {
return nil, b.errors
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type ReconciliationRequest struct {
*odhClient.Client

Manager *manager.Manager
Instance client.Object
Instance common.PlatformObject
DSCI *dsciv1.DSCInitialization
Release cluster.Release
Manifests []ManifestInfo
Expand Down
Loading