fix(project-controller): keep namespace labels the project-controller does not own #172
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
Could you add Issue and Author to the changelog fragment so you're credited in the release notes?
Thanks @noiyemini, and for reproducing both cases on a live cluster. Added in 7a2d963.
<!-- code-coverage-report-comment -->
Total coverage: 81.4% -> 81.4% (delta 0.00%)
Merging this branch changes the coverage (1 decrease, 1 increase)
| Impacted Packages | Coverage Δ | :robot: |
|-------------------|------------|---------|
| github.com/kai-scheduler/kai-resource-management/pkg/project-controller/handlers | 80.51% (+0.10%) | :thumbsup: |
| github.com/kai-scheduler/kai-resource-management/pkg/project-controller/webhooks/validation | 95.24% (-0.22%) | :thumbsdown: |
<details>
<summary>Coverage details</summary>
<sub>Compared to commit d83a53c (run #40174683562)</sub>
| Changed File | Coverage Δ | Total | Covered | Missed | :robot: |
|--------------|------------|-------|---------|--------|---------|
| github.com/kai-scheduler/kai-resource-management/pkg/project-controller/handlers/namespace_resource_handler.go | 82.76% (+0.83%) | 87 (+4) | 72 (+4) | 15 | :thumbsup: |
_Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code._
Changed unit test files:
</details>
Approved these changes.
Approved these changes.
LGTM. Thanks @blacksoxx
Thanks @noiyemini, @SiorMeir and @gshaibi for the reviews and the merge.
noiyemini
blacksoxx
Description
handleExistingNamespacereplacedmetadata.labelswith the project and version labels on every update, because the object sent toUpdateis built fresh from the Project and only annotations were carried over from the existing namespace. Flippingspec.enforceKaiScheduler, or adopting a pre-created namespace, therefore removed Pod Security Admission labels, NetworkPolicy selector labels and any other label set by someone else. Existing labels are now merged in the same way as annotations: every key the handler does not set itself is kept.Related issues
Fixes #171
Checklist
make validateBreaking changes
None. The handler's own labels and the enforce-scheduler annotation are written exactly as before; only labels it never set are no longer removed.
Additional notes
Two new specs in
namespace_resource_handler_test.go, next to the existing annotation one: a flippedEnforceKaiSchedulerand the adoption of a pre-created namespace, both with apod-security.kubernetes.io/enforce: restrictedlabel that must survive. Both fail on main.Ran locally (Go 1.26.8, macOS arm64):
go test ./pkg/project-controller/handlers/...(2 packages pass),golangci-lint run ./pkg/project-controller/...(0 issues). The e2e suite was not run.