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

Split controllers and webhooks into separate packages #3310

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

danail-branekov
Copy link
Member

@danail-branekov danail-branekov commented May 30, 2024

Is there a related GitHub Issue?

#3304

What is this change about?

Having controllers in separate packages allows having a suite per a
controller. This has several benefits:

  • The suite setup is significantly simpler - it does not have to wire
    all the controllers/webhooks. Instead, the setup wires only the
    controller/webhook that is being tested
  • Not wiring all the controllers in the test env reduces the noise of
    unrelated controllers/webhooks. This allows tests to not care about
    creating "valid" dependent objects, they only create dependent
    objects with properties that are just relevant to the
    controller/webhook under test
  • Tests are no longer required to take side effects from neighbour
    controllers/webhooks into consideration
  • Instead of relying on a state change of a dependent object caused by a
    neightbour controller, the test could simply set the desired state of
    the dependent object. This makes the test simpler and easy to reason
    about

This change follows several patterns:

  1. Move existing controllers and webhooks and their tests into separatepackages
  2. Come up with a minimal testenv suite that makes the tests happy
  3. Rename controller types by removing their type prefix (as it is contained in the package already). For example, CFAppReconciler is renamed to just Reconciler
  4. Related file names have their resource name removed, for example cfapp_controller.go is renamed to controller.go

In the process of the refactoring above, tests are refactored:

  • Overall simplification
  • Prefer creating literals with the data only needed by the test vs using an utility function that creates a monster object with lots of unnecessary data

Does this PR introduce a breaking change?

No

Acceptance Steps

tests passing

Tag your pair, your PM, and/or team

@cloudfoundry/wg-cf-on-k8s

@danail-branekov danail-branekov force-pushed the issues/3304-split-controller-tests-workloads branch from aa2d881 to 0c1c260 Compare May 31, 2024 08:52
Having controllers in separate packages allows having a suite per a
controller. This has several benefits:
* The suite setup is significantly simpler - it does not have to wire
  all the controllers/webhooks. Instead, the setup wires only the
  controller/webhook that is being tested
* Not wiring all the controllers in the test env reduces the noise of
  unrelated controllers/webhooks. This allows tests to not care about
  creating "valid" dependent objects, they only create dependent
  objects with properties that are just relevant to the
  controller/webhook under test
* Tests are no longer required to take side effects from neighbour
  controllers/webhooks into consideration
* Instead of relying on a state change of a dependent object caused by a
  neightbour controller, the test could simply set the desired state of
  the dependent object. This makes the test simpler and easy to reason
  about

fixes #3304
@danail-branekov danail-branekov force-pushed the issues/3304-split-controller-tests-workloads branch from 0c1c260 to 329ee72 Compare May 31, 2024 08:55
@danail-branekov danail-branekov merged commit 7220354 into main Jun 4, 2024
10 of 11 checks passed
@danail-branekov danail-branekov deleted the issues/3304-split-controller-tests-workloads branch June 4, 2024 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants