Skip to content

Implementation of Namespace Filtering with Cache Optimization for KAgent Controller #299

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

Merged
merged 16 commits into from
May 5, 2025

Conversation

sbx0r
Copy link
Contributor

@sbx0r sbx0r commented Apr 30, 2025

/resolves #298

@sbx0r sbx0r force-pushed the feat/298/namespace-filtering branch 2 times, most recently from b9862f0 to 8a4f6bc Compare April 30, 2025 12:03
@sbx0r sbx0r marked this pull request as ready for review May 1, 2025 20:51
@sbx0r sbx0r requested review from EItanya and ilackarms as code owners May 1, 2025 20:51
@sbx0r sbx0r force-pushed the feat/298/namespace-filtering branch from db1ba6f to da42a30 Compare May 1, 2025 23:16
Copy link
Contributor

@EItanya EItanya left a comment

Choose a reason for hiding this comment

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

Looks good overall, just some questions

# -- Namespaces the controller should watch.
# If empty, the controller will watch all namespaces (subject to RBAC permissions).
# @default -- [] (watches all namespaces)
watchNamespaces: []
Copy link
Contributor

Choose a reason for hiding this comment

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

At a high level why would these ever need to be different?

Copy link
Contributor Author

@sbx0r sbx0r May 2, 2025

Choose a reason for hiding this comment

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

for example:
caching on [ns1,ns2,ns3]
filtering on:

  • agents to the [ns1, ns2, ns3]
  • tools to the [ns1, ns2]

just for future improvements.
one for cache optimization (for bigger clusters)
other one is recommended for security layer and more specific filtering
https://sdk.operatorframework.io/docs/building-operators/golang/operator-scope/#watching-resources-in-a-set-of-namespaces

Copy link
Contributor Author

@sbx0r sbx0r May 4, 2025

Choose a reason for hiding this comment

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

After deeper research i've decided to delete predicates and all surrounding logic.
Only namespace watch will persist for now.
The additional layer of predicates may be helpful (but not necessarily) during the RBAC module implementation. For now it only makes a noise and complicates the codebase

@sbx0r sbx0r force-pushed the feat/298/namespace-filtering branch 10 times, most recently from f1f6683 to a042b8c Compare May 4, 2025 08:08
@sbx0r sbx0r requested a review from EItanya May 4, 2025 08:09
@sbx0r sbx0r force-pushed the feat/298/namespace-filtering branch from a042b8c to 60de072 Compare May 4, 2025 08:15
Comment on lines 67 to 68
{{- $_ := set $nsSet .Release.Namespace "" }}
Copy link
Contributor

Choose a reason for hiding this comment

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

So I think there's actually a bug here. In the controller, the only way to watch all namespaces is by making sure this list is empty, but this function ensures that there's always at least one value in the list, aka the release namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right!
I've forgot to commit change for it 😫

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that the better solution overall is to ONLY watch the release namespace by default, but I also don't want to break existing users. Ideally in the future we could offer an option where the user can use namespace scoped RBAC instead of cluster scoped, but that's definitely out of scope for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

solved!
Thanks a lot for this finding!

@sbx0r sbx0r force-pushed the feat/298/namespace-filtering branch from 5aed6fd to c38f4c4 Compare May 4, 2025 22:22
EItanya
EItanya previously approved these changes May 4, 2025
@sbx0r
Copy link
Contributor Author

sbx0r commented May 4, 2025

@EItanya WAIT!

@EItanya EItanya dismissed their stale review May 4, 2025 22:39

Was told to wait

@sbx0r
Copy link
Contributor Author

sbx0r commented May 4, 2025

Sorry for the alert.
Everything’s fine as far as you keep your CRs in the release namespace.
To support multiple namespaces, I’ll need to update the model — but that’s something I was already aware of (#232 -- see here).

After merging this PR, I’ll start working on multi-namespace CR handling. It’ll require changes to the data models and updates across all layers of the system (app/controller/UI).

@EItanya
Copy link
Contributor

EItanya commented May 4, 2025

Would you mind creating a quick design in the issue so we're all on the same page?

Copy link
Contributor

@EItanya EItanya left a comment

Choose a reason for hiding this comment

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

LGTM

}

return validNamespaces
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm going to approve, but in a follow-up please move these functions and tests into a different package.

@EItanya EItanya merged commit 89712d5 into kagent-dev:main May 5, 2025
9 checks passed
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.

[FEATURE] Implementation of Namespace Filtering with Cache Optimization for KAgent Controller
2 participants