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

feat: use owner reference with policy server resources. #720

Merged
merged 4 commits into from
May 9, 2024

Conversation

jvanz
Copy link
Member

@jvanz jvanz commented Apr 15, 2024

Description

Updates the controller to set owner references for all the resources created to make the policy server works. Which includes: service, configmap, deployment and secret. Therefore, we can remove the reconciliation loop code to remove this resources when the user deletes the policy server and rely on Kubernetes garbage collector to do the job.

Fix #660

Test

make test
# manual testing with tilt
tilt up --stream
# install and uninstall policy server

@jvanz jvanz self-assigned this Apr 15, 2024
@jvanz jvanz force-pushed the issue660-owner-references branch from 7103329 to 3abe65b Compare April 15, 2024 19:02
Copy link

codecov bot commented Apr 15, 2024

Codecov Report

Attention: Patch coverage is 65.95745% with 32 lines in your changes are missing coverage. Please review.

Project coverage is 73.17%. Comparing base (86ef275) to head (f80c28b).

Files Patch % Lines
internal/pkg/admission/policy-server-ca-secret.go 69.69% 17 Missing and 3 partials ⚠️
internal/pkg/admission/policy-server-deployment.go 55.55% 3 Missing and 5 partials ⚠️
internal/pkg/admission/policy-server-configmap.go 0.00% 1 Missing and 1 partial ⚠️
internal/pkg/admission/policy-server-service.go 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #720      +/-   ##
==========================================
+ Coverage   72.85%   73.17%   +0.32%     
==========================================
  Files          28       28              
  Lines        1908     1812      -96     
==========================================
- Hits         1390     1326      -64     
+ Misses        397      370      -27     
+ Partials      121      116       -5     
Flag Coverage Δ
integration-tests 61.03% <56.38%> (-0.18%) ⬇️
unit-tests 50.19% <62.76%> (+4.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jvanz jvanz force-pushed the issue660-owner-references branch 2 times, most recently from 99ad0f1 to 83049a3 Compare April 16, 2024 17:30
@jvanz jvanz marked this pull request as ready for review April 16, 2024 17:30
@jvanz jvanz requested a review from a team as a code owner April 16, 2024 17:31
@jvanz jvanz force-pushed the issue660-owner-references branch 3 times, most recently from 9b77c8a to cbaa416 Compare April 17, 2024 17:54
@jvanz jvanz force-pushed the issue660-owner-references branch 2 times, most recently from 341b80c to bf14af1 Compare April 26, 2024 17:27
@jvanz
Copy link
Member Author

jvanz commented Apr 26, 2024

This PR is based on top of #730. Waiting for that PR to get merged before moving this to pending review.

@jvanz jvanz force-pushed the issue660-owner-references branch from bf14af1 to d36cf05 Compare May 7, 2024 02:50
@jvanz jvanz requested review from flavio and a team and removed request for a team and flavio May 7, 2024 11:34
@jvanz jvanz force-pushed the issue660-owner-references branch 4 times, most recently from dc14e60 to 933d2fe Compare May 7, 2024 17:47
jvanz added 2 commits May 7, 2024 14:49
Updates the base CRDs generated after some recent dependencies updates.

Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
Updates the controller to set owner references for all the resources
created to make the policy server works. Which includes: service,
configmap, deployment and secret. Therefore, we can remove the
reconciliation loop code to remove this resources when the user deletes
the policy server and rely on Kubernetes garbage collector to do the
job.

Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
@jvanz jvanz force-pushed the issue660-owner-references branch from 933d2fe to 5563f3d Compare May 7, 2024 17:50
@jvanz
Copy link
Member Author

jvanz commented May 7, 2024

@kubewarden/kubewarden-developers the integration tests are failing but I do not think this is related to the changes here. It looks like something different. I'm moving this PR to be reviewed by the team while I investigate the issue. It may take some time because I cannot reproduce this in my local branch. 🤞

@jvanz jvanz requested a review from flavio May 7, 2024 21:28
@jvanz jvanz requested a review from a team May 7, 2024 21:28
@jvanz jvanz force-pushed the issue660-owner-references branch from 5563f3d to dd3cd07 Compare May 7, 2024 21:45

const port = "8181"

func TestCAAndCertificateCreationInAHttpsServer(t *testing.T) {
Copy link
Member

@viccuad viccuad May 8, 2024

Choose a reason for hiding this comment

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

Should we drop this test? Are we missing a test that checks for the cert creation on call to fetchOrInitializePolicyServerCASecret()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair enough, I've re added this test in the internal/pkg/admission/policy-server-ca-secret_test.go file. ;)

Copy link
Member

@viccuad viccuad left a comment

Choose a reason for hiding this comment

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

LGTM, just one question about the cert test refactor.

jvanz added 2 commits May 8, 2024 16:40
Uses the controller-runtime helper function CreateOrUpdate to reconcile
the secrets storing the certificates used by policy server.

Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
Some tests needs to update resources in order to properly test resource
deletion. However, this needs to happen inside an Eventually call to
ensure that the test will update the latest version of the resource.
Otherwise, it will fail.

Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
@jvanz jvanz force-pushed the issue660-owner-references branch from dd3cd07 to f80c28b Compare May 8, 2024 19:42
@jvanz jvanz requested a review from viccuad May 8, 2024 19:44
Copy link
Member

@flavio flavio left a comment

Choose a reason for hiding this comment

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

LGTM, I left one minor comment

@@ -163,11 +163,13 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
Copy link
Member

Choose a reason for hiding this comment

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

Where is this coming from?

Copy link
Member Author

Choose a reason for hiding this comment

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

This came from a recent update in the apimachinery package. As we use label selector objects in the policy spec, the CRDs will be updated with the latest changes there as well. I've added a commit here to fix that in our main branch and avoid generating noise every time that we run the controller locally.

If you think is better, I can open another PR just for that update in the CRDs.

@jvanz jvanz merged commit f562dbe into kubewarden:main May 9, 2024
8 of 9 checks passed
@jvanz jvanz deleted the issue660-owner-references branch May 9, 2024 20:38
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.

Increase the usage of metadata.ownerReferences
3 participants