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

Apply go 1.18 generics across reconciler-runtime #349

Merged
merged 5 commits into from Apr 5, 2023

Conversation

scothis
Copy link
Contributor

@scothis scothis commented Mar 29, 2023

This is a major breaking change that will affect all users of reconciler-runtime. There does not appear to be a way to transparently apply generics to an existing API that allows users to opt-in over time.

User defined functions are now compile-time type checked, and IDEs will be able to offer completion for method signatures. At runtime these functions are directly invoked and are no longer called by reflection. Runtime type checking has been removed.

Changes:

  • All existing deprecations are removed
  • All Reconcilers and SubReconcilers now operate on generic types of client.Object.
  • All reconciler Type/ChildType/ChildListType fields are now optional. They are only required if the generic type is an interface, or to define the apiVersion/kind for an Unstructured type.
  • SyncReconciler#Sync and #Finalize methods are split into two fields, one that is _WithResult and the default method which only returns an error.

Resolves #163

This is a major breaking change that will affect all users of
reconciler-runtime. There does not appear to be a way to transparently
apply generics to an existing API that allows users to opt-in over time.

User defined functions are now compile-time type checked, and IDEs will
be able to offer completion for method signatures. At runtime these
functions are directly invoked and are no longer called by reflection.
Runtime type checking has been removed.

Changes:

- All existing deprecations are removed
- All Reconcilers and SubReconcilers now operate on generic types of
  client.Object.
- All reconciler Type/ChildType/ChildListType fields are now optional.
  They are only required if the generic type is an interface, or to
  define the apiVersion/kind for an Unstructured type.
- SyncReconciler#Sync and #Finalize methods are split into two fields,
  one that is _WithResult and the default method which only returns an
  error.

Signed-off-by: Scott Andrews <andrewssc@vmware.com>
@codecov
Copy link

codecov bot commented Mar 29, 2023

Codecov Report

Patch coverage: 76.35% and project coverage change: -2.28 ⚠️

Comparison is base (5d30393) 60.36% compared to head (4b22f4d) 58.08%.

❗ Current head 4b22f4d differs from pull request most recent head deb9b67. Consider uploading reports for the commit deb9b67 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #349      +/-   ##
==========================================
- Coverage   60.36%   58.08%   -2.28%     
==========================================
  Files          17       14       -3     
  Lines        2210     1954     -256     
==========================================
- Hits         1334     1135     -199     
+ Misses        798      741      -57     
  Partials       78       78              
Impacted Files Coverage Δ
reconcilers/enqueuer.go 0.00% <0.00%> (ø)
testing/client.go 54.97% <ø> (+1.16%) ⬆️
testing/reconciler.go 0.00% <0.00%> (ø)
testing/subreconciler.go 0.00% <0.00%> (ø)
reconcilers/reconcilers.go 75.69% <80.53%> (-2.94%) ⬇️
reconcilers/webhook.go 90.29% <81.25%> (-2.50%) ⬇️
testing/config.go 87.44% <100.00%> (-0.06%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@scothis
Copy link
Contributor Author

scothis commented Mar 29, 2023

Updated the service binding runtime to use this branch scothis/servicebinding-runtime#113

The Type field for CastResource is completely redundant with the generic
types. We can also go a step further and avoid converting the resource
when the CastType is an interface, because we know all concrete types
are already compatible and only need to be cast, saving a lot of
overhead.

Signed-off-by: Scott Andrews <andrewssc@vmware.com>
Signed-off-by: Scott Andrews <andrewssc@vmware.com>
Copy link
Member

@rashedkvm rashedkvm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Collaborator

@mamachanko mamachanko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After test-driving this branch with our kit, I approve 👍🏻

Great work, @scothis

This means that the value of Resource and ExpectedResource must be the
same type as the reconciler handles.

No longer can a die be passed directly and unwrapped inside the test.
While this behavior was extremely convenient, it created expectations
that may not be true in other cases and depends on DeepCopyObject on the
die returning a different type than the method was called on.

Signed-off-by: Scott Andrews <andrewssc@vmware.com>
@scothis scothis marked this pull request as ready for review April 4, 2023 18:43
@scothis scothis merged commit eaa26f9 into vmware-labs:main Apr 5, 2023
1 check passed
@scothis scothis deleted the generics branch April 5, 2023 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explore: how can go generic can benefit reconcilers
4 participants