Skip to content

fix(project-controller): honour the manual-override label on external namespaces - #201

Merged
noiyemini merged 2 commits into
kai-scheduler:mainfrom
blacksoxx:fix-external-namespace-manual-override
Nov 11, 2026
Merged

noiyemini merged 2 commits into
kai-scheduler:mainfrom
blacksoxx:fix-external-namespace-manual-override

Conversation

@blacksoxx

@blacksoxx blacksoxx commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

labelExternalNamespaceForProject re-applied the project label and the enforce-scheduler annotation to a namespace referenced through spec.namespace even when that namespace carried the manual-override label, so an administrator's override was undone on every Project reconciliation (and scheduler enforcement re-enabled when spec.enforceKaiScheduler is true). The handler now returns early for an overridden namespace, the way handleExistingNamespace already does for the namespaces the controller creates. The check that rejects a namespace labelled for another Project runs first, so an overridden namespace cannot be claimed by a second Project either.

One behaviour change on the way: a project label that is present but empty is now treated as missing and set to the project's name, as the handler already does for the namespaces the controller creates; before, an empty label was left empty.

Five new cases in namespace_resource_handler_test.go: an overridden namespace stays without the project label and the annotation, an overridden namespace keeps enforce-scheduler: "false" under a Project with enforceKaiScheduler: true, an overridden namespace labelled for another Project is still rejected, removing the override resumes syncing (label and annotation written on the next reconcile), and an empty project label gets the project's name. The override cases fail on main and pass here; go test ./pkg/project-controller/... and make validate pass (Go 1.26.8, macOS arm64, fake client only, not run on a cluster).

Related issues

Fixes #197

Checklist

  • Self-reviewed the complete diff
  • Added or updated tests where needed
  • Updated user and developer documentation where needed
  • Ran make validate
  • Added a changelog fragment for a behavior change, or explained why none is needed
  • Confirmed new third-party code retains provenance and licensing

Breaking changes

None. A namespace without the override label is handled exactly as before.

Additional notes

The issue asks for a backport to v0.18; happy to open it against v0.18 once this is merged.

… namespaces

The external namespace handler re-applied the project label and the
enforce-scheduler annotation to a namespace referenced through
spec.namespace even when the namespace carried the manual-override
label, so an administrator's override was undone on every Project
reconciliation. The handler now returns early for an overridden
namespace, the way handleExistingNamespace already does for the
namespaces this controller creates. A namespace that belongs to another
Project is still rejected first.

Fixes kai-scheduler#197

Signed-off-by: Youssef Omar Bouden <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 8, 2026 13:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@noiyemini noiyemini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, the fix looks good. Two test cases to add, please:

  1. Removing the override resumes syncing, which the issue asks for. Set the override, reconcile, remove the label, reconcile again, and expect the project label and annotation to be written.
  2. A project label that's present but empty gets the project's name, since that behavior changed in this PR.

// Labels the namespace to mark it as kai namespace
projectNameLabel, found := existingNamespace.Labels[config.Get().NamespaceProjectLabelKey]
if !found {
if projectNameLabel == "" {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Treating an empty label as missing is a good catch. It matches what the controller already does for the namespaces it creates. Could you mention it in the PR description?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, the description now has a paragraph on the empty label being treated as missing.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

Total coverage: 81.4% -> 81.4% (delta 0.00%)

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/kai-scheduler/kai-resource-management/pkg/project-controller/handlers 80.50% (+0.07%) 👍
Coverage details

Compared to commit aef0fec (run #42475855666)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/kai-scheduler/kai-resource-management/pkg/project-controller/handlers/namespace_resource_handler.go 83.33% (+0.57%) 90 (+3) 75 (+3) 15 👍

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:

  • github.com/kai-scheduler/kai-resource-management/pkg/project-controller/handlers/handlers_test/namespace_resource_handler_test.go

… label on external namespaces

Signed-off-by: Youssef Omar Bouden <[email protected]>
@blacksoxx

Copy link
Copy Markdown
Contributor Author

Thanks @noiyemini. Both cases are in
0f3a601: removing the override and reconciling again writes the project label and the enforce annotation, and an empty project label gets the project's name. Handler tests pass locally; the description mentions the empty-label change.

@blacksoxx

Copy link
Copy Markdown
Contributor Author

Thanks @noiyemini!

@noiyemini
noiyemini merged commit 3b5dbe4 into kai-scheduler:main Nov 11, 2026
16 of 18 checks passed
@blacksoxx

Copy link
Copy Markdown
Contributor Author

Thanks @SiorMeir and @noiyemini!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Project controller ignores the manual-override label on external namespaces

4 participants