Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Validate sub reconcilers on setup #42

Merged
merged 1 commit into from
Nov 14, 2020
Merged

Validate sub reconcilers on setup #42

merged 1 commit into from
Nov 14, 2020

Conversation

scothis
Copy link
Contributor

@scothis scothis commented Nov 13, 2020

Because we use reflection to define callback methods with specific
types, we cannot relay on the go compiler to catch type errors.
Previously, an incompatible type would result in a panic at runtime. If
the method is lightly used, it may take time for it to be invoked and
crash the controller.

Now, the SetupWithManager method will return an appropriate error if the
reconciler is misconfigured (missing required value, wrong types, etc).

Breaking changes:

  • ChildReconciler#ParentType is removed, the value is now passed from
    the the ParentReconciler. ChildReconciler and SyncReconcilers may use
    a struct or compatible interface to represent the parent resource.
  • ChildReconciler#DesiredChild must accept a context as it's first
    argument. The context is used to pass state between sub reconcilers,
    always including will make it easier to retrieve stashed state.

Resolves #40

@codecov
Copy link

codecov bot commented Nov 13, 2020

Codecov Report

Merging #42 (7605514) into main (5eb3b97) will increase coverage by 5.15%.
The diff coverage is 91.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #42      +/-   ##
==========================================
+ Coverage   57.08%   62.24%   +5.15%     
==========================================
  Files          11       11              
  Lines         501      588      +87     
==========================================
+ Hits          286      366      +80     
- Misses        207      214       +7     
  Partials        8        8              
Impacted Files Coverage Δ
reconcilers/reconcilers.go 88.32% <91.66%> (+1.37%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5eb3b97...7605514. Read the comment docs.

Because we use reflection to define callback methods with specific
types, we cannot relay on the go compiler to catch type errors.
Previously, an incompatible type would result in a panic at runtime. If
the method is lightly used, it may take time for it to be invoked and
crash the controller.

Now, the SetupWithManager method will return an appropriate error if the
reconciler is misconfigured (missing required value, wrong types, etc).

Breaking changes:
- ChildReconciler#ParentType is removed, the value is now passed from
  the the ParentReconciler. ChildReconciler and SyncReconcilers may use
  a struct or compatible interface to represent the parent resource.
- ChildReconciler#DesiredChild must accept a context as it's first
  argument. The context is used to pass state between sub reconcilers,
  always including will make it easier to retrieve stashed state.

Signed-off-by: Scott Andrews <andrewssc@vmware.com>
@scothis scothis merged commit 8664770 into vmware-labs:main Nov 14, 2020
@scothis scothis deleted the typecheck branch November 14, 2020 00:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type check reconcilers
1 participant