Skip to content

feat(autorag): filter system namespaces from project selector#7380

Open
MatthewAThompson wants to merge 2 commits intoopendatahub-io:mainfrom
MatthewAThompson:autorag-namespace-filtering
Open

feat(autorag): filter system namespaces from project selector#7380
MatthewAThompson wants to merge 2 commits intoopendatahub-io:mainfrom
MatthewAThompson:autorag-namespace-filtering

Conversation

@MatthewAThompson
Copy link
Copy Markdown
Contributor

@MatthewAThompson MatthewAThompson commented Apr 23, 2026

https://redhat.atlassian.net/browse/RHOAIENG-53262

Description

  • Added filterAvailableNamespaces() function to packages/autorag/bff/internal/repositories/namespace.go
  • Filters out system namespaces: openshift-*, kube-*, default, system, openshift, opendatahub
  • Now matches GenAI's filtering behaviour for consistent UX across Gen AI Studio navigation items

How Has This Been Tested?

Number of items returned from the GET /v1/namespaces matches gen-ai:
GET /autorag/api/v1/namespaces
Screenshot 2026-04-23 at 5 06 20 PM

GET /gen-ai/api/v1/namespaces
Screenshot 2026-04-23 at 5 05 14 PM

Compared to automl, for example, which does not filter out any namespaces:
GET /automl/api/v1/namespaces
Screenshot 2026-04-23 at 5 07 34 PM

Test Impact

Added tests in packages/autorag/bff/internal/repositories/namespace_test.go

Request review criteria:

Self checklist (all need to be checked):

  • The developer has manually tested the changes and verified that the changes work
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has added tests or explained why testing cannot be added (unit or cypress tests for related changes)
  • The code follows our Best Practices (React coding standards, PatternFly usage, performance considerations)

If you have UI changes:

  • Included any necessary screenshots or gifs if it was a UI change.
  • Included tags to the UX team if it was a UI/UX change.

After the PR is posted & before it merges:

  • The developer has tested their solution on a cluster by using the image produced by the PR to main

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • System and infrastructure namespaces (such as OpenShift and Kubernetes system namespaces) are now excluded from the available namespaces list, displaying only user-managed namespaces.
  • Tests

    • Comprehensive test coverage added to verify correct filtering of system namespaces and preservation of namespace metadata.

MatthewAThompson and others added 2 commits April 23, 2026 17:01
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>
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 23, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign darachcawley for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

📝 Walkthrough

Walkthrough

The pull request adds namespace filtering to the GetNamespaces function. A new unexported helper filterAvailableNamespaces is introduced that removes Kubernetes and OpenShift system namespaces from the returned list. The filtering excludes four hardcoded namespace names (default, system, openshift, opendatahub) and any namespaces starting with openshift- or kube- prefixes. Comprehensive test coverage validates the filtering behavior across various namespace types and edge cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Issues & Observations

Incompleteness 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: kube-system, kube-node-lease, kube-public, kubernetes-dashboard, and potentially vendor-specific system namespaces. Relying solely on prefix matching for kube- mitigates some risk, but verify this aligns with actual cluster configurations in use.

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 Openshift-* or KUBE-* variants.

No validation of upstream data: The function assumes client.GetNamespaces returns well-formed namespace objects with populated names. If upstream can return nil or zero-value namespaces, the prefix checks may silently pass invalid entries through. Add defensive checks if data source reliability is uncertain.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly and specifically describes the main change: adding namespace filtering for system namespaces in the AutoRAG project selector.
Description check ✅ Passed Description includes issue reference, clear explanation of changes, testing evidence with screenshots, unit tests added, and completed self-checklist items.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between e66d0a2 and 8e480e1.

📒 Files selected for processing (2)
  • packages/autorag/bff/internal/repositories/namespace.go
  • packages/autorag/bff/internal/repositories/namespace_test.go

Comment on lines +37 to +57
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
}
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot Apr 23, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 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 like openshift-* and kube-*.

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.

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.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant