-
Notifications
You must be signed in to change notification settings - Fork 33
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
Update controller code to use the controller-runtime helper function to create or update resources #730
Conversation
64fa644
to
083ceff
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #730 +/- ##
==========================================
+ Coverage 71.02% 73.84% +2.81%
==========================================
Files 28 28
Lines 2071 1908 -163
==========================================
- Hits 1471 1409 -62
+ Misses 459 381 -78
+ Partials 141 118 -23
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
d9ce0e1
to
5e4bb58
Compare
@kubewarden/kubewarden-developers I take this opportunity to verify some of the policy controller flaky test that we can see in the main branch. I could hit this test failing regularly in this branch. Therefore, I've started by reorganizing the tests to be independent. This way I can run the problematic test individually. That's why, you can see another test reorganization in the policy controller tests. ;) |
5e4bb58
to
6723672
Compare
e7218af
to
a23f394
Compare
@kubewarden/kubewarden-developers I've split this PR into two. The second one, #731, has the test reorganization that I did while working on this change. As the tests added in this PR require the changes on #731, this PR is based on that changes. Thus, #731 should be merge before. Moving this PR to block until we merge #731. Once it's merged, I'll rebase this on top of main again and we will have a cleaner diff. |
35ef552
to
fdcdc08
Compare
fdcdc08
to
5e5c6c6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, LGTM.
Great work!
The reconciler code looks very simple now and we got rid of all the custom logic.
Just left some minor comments.
@@ -200,7 +125,7 @@ func (policyConfigEntryMap PolicyConfigEntryMap) ToClusterAdmissionPolicyReconci | |||
return res | |||
} | |||
|
|||
func (r *Reconciler) createPoliciesMap(admissionPolicies []policiesv1.Policy) PolicyConfigEntryMap { | |||
func (r *Reconciler) CreatePoliciesMap(admissionPolicies []policiesv1.Policy) PolicyConfigEntryMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not need to be public, as it is not used elsewhere.
We could call it something like buildPoliciesMap
since the current name can be ambiguous (one could think that a Create
action is performed by a client in this function).
Also, this doesn't need to be a method, by using just a function we could simplify the unit test in the future, when we get rid/refactor of the other unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was using this function in the integration tests. But I've ended not using and generating the data to check the result there instead.
}, timeout, pollInterval).Should(Succeed()) | ||
}) | ||
|
||
It("when the requests are updated should update the PolicyServer pod with the new requests", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe rephrase (It)"should update the PolicyServer pod with the new requests when the requests are updated"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also moved the test to the context about updating policy servers. I believe it better to keep this test there. It's testing policy server updates.
bad974a
to
1b54aee
Compare
@fabriziosestito I've addressed your comments. Can you review it again? Thanks! |
Updates the kubebuilder statements to build the RBAC roles in the controller to be in sync with the roles used in the Helm charts. Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
Updates the reconciliation code to use the controller-runtime helper functions thats abstracts the logic to decide if the resource should be created or updated. Therefore, our code can be simplified and it is not necessary custom code to detect if the source should be updated or not. Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
Updates the controller to use the controller-runtime help function CreateOrUpdate to reconcile the validation and mutating webhooks. Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
As now the controller uses the controller-runtime helper function to create and update resources, the unit tests that validate our custom code has been removed. But it's still necessary to validate the behaviour of the controller. Therefore, this commit adds a bunch of integration test to cover the same verification done by the previous unit tests. Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
Turns some methods in the reconciler used in the policy server configmap creation into functions. These function does not need access to information from the reconciler struct. Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
Updates the integration tests grouping all the Policy Server creation tests in a context. Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
1b54aee
to
204d2bc
Compare
Increases the timeout to run test because Github workers can be slow. Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a really nice cleanup! 👏
Description
This PR updates the controller code responsible to update the policy server resources to use the controller-runtime
CreateOrUpdate
helper function to abstract the logic of detecting if the resource should be created or updated. Making the code more simple and easy to maintain.During this process the unit tests testing the removed code have been removed as well. Which bring us to the spin off PR of this one, the integration tests reorganization #731 . The old tests have been reorganized to describe better the context of what the tests are validating. As well as updating the whole policy server controller tests to be independent as suggested by the Ginkgo documentation. After that, to ensure that the controller continue to works as before a bunch of integrations tests have been added covering the removed unit tests
NOTE: I've not added test to cover the metrics configurations yet. I'll add a future PR to cover that. I do not want to wait more in this PR to get some feedback from the team.This is not necessary anymore. I've added tests for the metrics and tracing configuration here as well.Fix #723
Test
make test
Additional information