feat(controller): allow custom labels on PolicyServer resources#1699
feat(controller): allow custom labels on PolicyServer resources#1699flavio wants to merge 4 commits intokubewarden:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds user-configurable metadata to PolicyServer-managed workloads, enabling custom discovery/selection via labels and supporting additional annotations while ensuring controller/system metadata wins on conflicts. This addresses the inability to persistently add labels/annotations to the PolicyServer Deployment/Pods (Fixes #651).
Changes:
- Introduces
spec.labelsto PolicyServer and wires it into the generated Deployment metadata and Pod template labels with system-label precedence. - Propagates
spec.annotationsonto the Deployment ObjectMeta (and continues using it for Pod template annotations). - Updates CRD schemas and generated CRD docs to include the new
labelsfield (plus DeepCopy updates).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/controller/policyserver_controller_deployment.go | Merges user spec.labels/spec.annotations into Deployment metadata and Pod template labels. |
| internal/controller/policyserver_controller_test.go | Adds tests asserting custom label/annotation propagation and precedence behavior. |
| api/policies/v1/policyserver_types.go | Adds PolicyServerSpec.Labels field with documentation. |
| api/policies/v1/zz_generated.deepcopy.go | Updates deepcopy generation for the new Labels map. |
| config/crd/bases/policies.kubewarden.io_policyservers.yaml | Extends CRD schema to include spec.labels. |
| charts/kubewarden-crds/templates/policies.kubewarden.io_policyservers.yaml | Mirrors CRD schema update in Helm CRDs chart. |
| docs/crds/CRD-docs-for-docs-repo.md | Documents new labels field in generated CRD docs (markdown). |
| docs/crds/CRD-docs-for-docs-repo.adoc | Documents new labels field in generated CRD docs (asciidoc). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1699 +/- ##
==========================================
- Coverage 82.11% 77.04% -5.07%
==========================================
Files 129 172 +43
Lines 16961 21505 +4544
==========================================
+ Hits 13927 16569 +2642
- Misses 3034 4724 +1690
- Partials 0 212 +212
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add spec.labels and propagate spec.annotations to the Deployment ObjectMeta and Pod template. System labels always take precedence over user-defined ones. Fixes kubewarden#651 Signed-off-by: Flavio Castelli <fcastelli@suse.com> Assisted-by: Claude Sonnet 4.6
9d14016 to
5d19003
Compare
…n each reconcile Mutating the existing maps in-place meant stale user-defined labels and annotations were never removed when deleted from spec. Replaced with fresh map construction so removals are reflected immediately. Adds a regression test covering the removal scenario. Signed-off-by: Flavio Castelli <fcastelli@suse.com> Assisted-by: Claude Sonnet 4.6
jvanz
left a comment
There was a problem hiding this comment.
Overall, LGTM. I just have a small suggestion
Take feedback from code review Signed-off-by: Flavio Castelli <fcastelli@suse.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ss reconciles Rebuilding the Deployment ObjectMeta annotations map from scratch on each reconcile was deleting annotations added by Kubernetes controllers (e.g. deployment.kubernetes.io/revision) and external tooling, causing reconcile churn as those controllers re-added them. Switch to a tracking-annotation approach: the controller records which annotation/label keys it owns (kubewarden.io/managed-annotation-keys and kubewarden.io/managed-label-keys) and only removes keys that were previously managed but have since been deleted from spec. All other annotations/labels set by Kubernetes or third-party tooling are left untouched. Adds a regression test asserting that externally-added Deployment annotations survive a reconcile that removes a user-defined annotation from spec. Signed-off-by: Flavio Castelli <fcastelli@suse.com> Assisted-by: Claude Sonnet 4.6
Add spec.labels and propagate spec.annotations to the Deployment ObjectMeta and Pod template. System labels always take precedence
over user-defined ones.
Fixes #651
I was cleaning up my notification when I found this GH issue. I just tossed my AI agent at that since it was an easy task.