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

Resource factories #160

Closed
scothis opened this issue Nov 30, 2021 · 3 comments
Closed

Resource factories #160

scothis opened this issue Nov 30, 2021 · 3 comments
Labels

Comments

@scothis
Copy link
Contributor

scothis commented Nov 30, 2021

The resource factories used by reconciler test suites were created as a way to reduce the boiler plate for resources under test. These factories served their purpose, but suffer from a couple flaws:

  1. it's too hard to create a factory for a new type
  2. the provided factories cover a minimal subset of the k8s api (see 1)

I'd like to deprecate the existing factories in favor of encouraging users to define resources how they see fit. For example, https://github.com/scothis/dies follows in the spirit of reconciler runtime's factories while seeking to provide support for all common built-it k8s resources, and provides tools for generating wrappers for new types.

This migration should be broken down into a series of steps:

  1. mark the existing factories as deprecated
  2. update consumers of the rtesting.Factory interface to use runtime.Object (or client.Object if needed)
  3. (optional) update existing factories to implement runtime.Object to make them compatible
  4. release these changes
  5. ...
  6. remove the factories

Inside the reconciler runtime test harnesses, any bare use of a runtime.Object resource should always call .DeepCopyObject() to unwrap a factory type (if any). We largely already do this to avoid accidental mutation between test cases and to unwrap the existing factory types.

The immediate impact to most users would be that they'd need to update the test cases from defending []rtesting.Factory to []runtime.Object. Creators of custom type would need update them to implement runtime.Object or call .CreateObject() on each factory to convert the factory type to a runtime.Object.

The longer impact is that consumers of the factory types would either need to fork the types into their own repo, or convert to a different factory type (like https://github.com/scothis/dies)

@scothis
Copy link
Contributor Author

scothis commented Nov 30, 2021

cc @edwardecook @jhvhs @shashwathi @gmrodgers @Samze who have contributed to this package

@scothis
Copy link
Contributor Author

scothis commented Dec 2, 2021

Steps 1, 2 and 3 are now implemented. I ended up going with client.Object and made each of the existing factories implement the Object interface so they can continue to be used without breaking.

Users will need to update their test suite types from rtesting.Factory -> client.Object, like in this file 995d17a#diff-8ec33940c40b0250a55ef72716ce41d7cb95b8f752edf9e3b44cae90404ddd2e

Leaving this issue open until we remove the factory types in a later release

scothis added a commit that referenced this issue Jan 3, 2022
This completes the removal of the factory types that were deprecated in
v0.4.0. dies.dev dies are now used as a replacement.

Refs #160

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

scothis commented Jan 3, 2022

The factories were removed in #175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant