kubewarden / kubewarden-controller

Manage admission policies in your Kubernetes cluster with ease
https://kubewarden.io
Apache License 2.0
181 stars 30 forks source link

fix: do not overwrite PolicyServer annotations and labels #750

Closed flavio closed 1 month ago

flavio commented 1 month ago

Prior to this commit, our CreateOrPatch function overwrote the Deployment annotations and labels.

This is a problem, because Kubernetes internally uses an annotation to keep track of the Deployment revision.

Because of our behaviour, the controller ended up removing the annotation deployment.kubernetes.io/revision. But after a while the Kubernetes reconcilers added it back. Leading to a back and forth between our controller and the Kubernetes ones.

This also manifested itself inside of our e2e tests, which sometimes failed with this message:

error: desired revision (24) is different from the running revision (0)

The 0 revision is a special value which is assigned by kubectl when the annotation field is NOT found.

This commit prevents annotations and labels to be overwritten. Labels are not strictly related with the issue we found inside of the e2e tests, but there are indeed some labels that are added by helm that we should not be messing with.

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 72.36%. Comparing base (a27076e) to head (92f2a54).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #750 +/- ## ========================================== - Coverage 74.00% 72.36% -1.64% ========================================== Files 28 28 Lines 1804 1806 +2 ========================================== - Hits 1335 1307 -28 - Misses 353 379 +26 - Partials 116 120 +4 ``` | [Flag](https://app.codecov.io/gh/kubewarden/kubewarden-controller/pull/750/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kubewarden) | Coverage Δ | | |---|---|---| | [integration-tests](https://app.codecov.io/gh/kubewarden/kubewarden-controller/pull/750/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kubewarden) | `60.02% <100.00%> (-1.79%)` | :arrow_down: | | [unit-tests](https://app.codecov.io/gh/kubewarden/kubewarden-controller/pull/750/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kubewarden) | `50.19% <100.00%> (+0.07%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kubewarden#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.