feat(autorag): filter system namespaces from project selector#7380
feat(autorag): filter system namespaces from project selector#7380MatthewAThompson wants to merge 2 commits intoopendatahub-io:mainfrom
Conversation
Add namespace filtering to AutoRAG BFF to match GenAI behaviour. Filters out system namespaces (openshift-*, kube-*, default, system, openshift, opendatahub) to show only user-accessible projects in the project selector dropdown. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add comprehensive unit tests for filterAvailableNamespaces() function: - Test filtering of openshift-* and kube-* prefixed namespaces - Test filtering of exact match system namespaces (default, system, openshift, opendatahub) - Test that user namespaces are preserved - Test edge cases (empty list, all system namespaces) - Test that metadata and annotations are preserved - Test mixed system and user namespace scenarios All 9 test cases pass. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
📝 WalkthroughWalkthroughThe pull request adds namespace filtering to the Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Issues & ObservationsIncompleteness of excluded namespace list: The hardcoded exclusion list covers four specific names plus two prefix patterns, but Kubernetes has additional system namespaces not captured here. Missing from explicit exclusion: String matching brittleness: The function performs case-sensitive exact name matching and prefix matching. Clarify whether namespace naming conventions guarantee case consistency in your environment, or whether case-insensitive comparison should be applied to avoid accidentally exposing No validation of upstream data: The function assumes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/autorag/bff/internal/repositories/namespace.go`:
- Around line 37-57: Update filterAvailableNamespaces to include the missing
RHOAI exclusions and move it to a shared helper: add the exact namespace names
("redhat-ods-applications", "redhat-ods-operator", "redhat-ods-monitoring",
"rhods-notebooks") to the excludedExact set in filterAvailableNamespaces and
extend the prefix check (currently testing "openshift-" and "kube-") to also
skip any name with the "redhat-ods-" prefix; then factor the function out of
packages/autorag/bff/internal/repositories/namespace.go and the duplicate in
packages/gen-ai/bff/internal/repositories/namespace.go into a single shared
package (e.g., packages/shared/bff/namespace) and update callers to import and
use the shared filterAvailableNamespaces.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Central YAML (inherited), Organization UI (inherited)
Review profile: CHILL
Plan: Enterprise
Run ID: 02552e4d-9e4a-4c63-8cd0-7eb8e5695e38
📒 Files selected for processing (2)
packages/autorag/bff/internal/repositories/namespace.gopackages/autorag/bff/internal/repositories/namespace_test.go
| func filterAvailableNamespaces(namespaces []corev1.Namespace) []corev1.Namespace { | ||
| excludedExact := map[string]struct{}{ | ||
| "default": {}, | ||
| "system": {}, | ||
| "openshift": {}, | ||
| "opendatahub": {}, | ||
| } | ||
|
|
||
| filtered := make([]corev1.Namespace, 0, len(namespaces)) | ||
| for _, ns := range namespaces { | ||
| name := ns.Name | ||
| if strings.HasPrefix(name, "openshift-") || strings.HasPrefix(name, "kube-") { | ||
| continue | ||
| } | ||
| if _, excluded := excludedExact[name]; excluded { | ||
| continue | ||
| } | ||
| filtered = append(filtered, ns) | ||
| } | ||
| return filtered | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Confirm gen-ai's namespace filter set so we can see what autorag is trying to mirror,
# and surface any other packages already doing the same filtering.
fd -t f 'namespace.go' packages/ | xargs -I{} sh -c 'echo "=== {} ==="; cat {}'
echo "--- hits for redhat-ods / application-namespace ---"
rg -nP --type=go -C2 'redhat-ods|application-namespace|opendatahub.io/application-namespace'Repository: opendatahub-io/odh-dashboard
Length of output: 14085
Add missing RHOAI system namespace filters and extract filterAvailableNamespaces to shared helper.
Duplicate filter logic already exists in packages/gen-ai/bff/internal/repositories/namespace.go. Extract filterAvailableNamespaces to a shared package (e.g., packages/shared/bff/namespace) to avoid maintenance drift.
More critically, the hardcoded exclusion set is incomplete for RHOAI deployments. It will leak system namespaces into the user-facing selector:
- Missing
redhat-ods-*prefix and exact matches:redhat-ods-applications,redhat-ods-operator,redhat-ods-monitoring,rhods-notebooks. These are all part of the RHOAI distribution and should be excluded by default, just likeopenshift-*andkube-*.
Add these to excludedExact and prefix filters:
excludedExact := map[string]struct{}{
"default": {},
"system": {},
"openshift": {},
"opendatahub": {},
"redhat-ods-applications": {},
"redhat-ods-operator": {},
"redhat-ods-monitoring": {},
"rhods-notebooks": {},
}
// ... existing code ...
if strings.HasPrefix(name, "openshift-") || strings.HasPrefix(name, "kube-") || strings.HasPrefix(name, "redhat-ods-") {
continue
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/autorag/bff/internal/repositories/namespace.go` around lines 37 -
57, Update filterAvailableNamespaces to include the missing RHOAI exclusions and
move it to a shared helper: add the exact namespace names
("redhat-ods-applications", "redhat-ods-operator", "redhat-ods-monitoring",
"rhods-notebooks") to the excludedExact set in filterAvailableNamespaces and
extend the prefix check (currently testing "openshift-" and "kube-") to also
skip any name with the "redhat-ods-" prefix; then factor the function out of
packages/autorag/bff/internal/repositories/namespace.go and the duplicate in
packages/gen-ai/bff/internal/repositories/namespace.go into a single shared
package (e.g., packages/shared/bff/namespace) and update callers to import and
use the shared filterAvailableNamespaces.
There was a problem hiding this comment.
Code de-duplication efforts across the platform are still under exploration/discussion, and is outside of the scope of this PR.
Regarding the hardcoded exclusion set, the intention is to align behaviour with gen-ai, and redhat-ods-* namespaces are not filtered out there, so we shouldn't introduce a discrepancy here.
There was a problem hiding this comment.
@MatthewAThompson, understood on both points — the parity-first approach with gen-ai is a clear and intentional design constraint, and the screenshots confirm the 86-item alignment is achieved. I'll withdraw the suggestion.
📝 Learnings were identified and not saved (knowledge base disabled). Enable
https://redhat.atlassian.net/browse/RHOAIENG-53262
Description
filterAvailableNamespaces()function to packages/autorag/bff/internal/repositories/namespace.goHow Has This Been Tested?
Number of items returned from the GET /v1/namespaces matches gen-ai:

GET /autorag/api/v1/namespacesGET /gen-ai/api/v1/namespacesCompared to automl, for example, which does not filter out any namespaces:

GET /automl/api/v1/namespacesTest Impact
Added tests in packages/autorag/bff/internal/repositories/namespace_test.go
Request review criteria:
Self checklist (all need to be checked):
If you have UI changes:
After the PR is posted & before it merges:
mainSummary by CodeRabbit
Release Notes
Bug Fixes
Tests