feat: add !=, == support for namespace field selector #15098
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #13468
Motivation
Currently, argo-workflows only supports the '=' operator for the field selector
metadata.namespacewhen listing workflows. This limitation restricts the flexibility of our queries, particularly when users wish to exclude specific namespaces from their results. The goal of this PR is to expand support to include the '==' and '!=' operators formetadata.namespace, aligning our capabilities with native Kubernetes functionality. This enhancement allows users to perform exclusion queries (e.g., "list all workflows except those in the 'test' namespace"), improving overall system usability.Modifications
ListOptions Expansion:
ListOptionsstruct inserver/utilsto include a newNamespaceFilterfield to store the operator type.BuildListOptions Enhancement:
BuildListOptionsfunction to parsemetadata.namespace==andmetadata.namespace!=.!=sets the correct filter type and==behaves consistent with=.Database Selector Update:
BuildArchivedWorkflowSelectorandBuildWorkflowSelectorinpersist/sqldbto handle theNamespaceFilter.namespace != ?) to support theNotEqualsfilter in the archive.Workflow Server Authorization:
ListWorkflowsinserver/workflow/workflow_server.goto handle authorization for namespace exclusion.metadata.namespace!=is used, the user must have cluster-wide list permissions. If they do not, the request is denied immediately. This mirrorskubectlbehavior and prevents potential security issues where excluding a namespace might imply access to all others.Verification
Unit Testing:
server/utils/list_options_test.goto cover parsing of the new operators and conflict detection.server/workflowarchive/archived_workflow_server_test.goto verify that the new options are correctly passed to the repository layer.E2E Testing:
test/e2e/argo_server_test.go.argo list --field-selector metadata.namespace!=<ns>returns the correct workflows for authorized users.Example audit log from local testing:
{ "kind": "Event", "apiVersion": "audit.k8s.io/v1", "level": "Metadata", "auditID": "f8a139b4-9201-4dee-b57b-15e095887f79", "stage": "ResponseComplete", "requestURI": "/apis/argoproj.io/v1alpha1/workflows?fieldSelector=metadata.namespace%21%3Dargo-test-2\u0026labelSelector=%21workflows.argoproj.io%2Fcontroller-instanceid", "verb": "list", "user": { "username": "system:admin", "groups": [ "system:masters", "system:authenticated" ] }, "sourceIPs": [ "192.168.107.3" ], "userAgent": "argo/v0.0.0 (darwin/amd64) kubernetes/$Format/argo-workflows/latest+6fb2b9f.dirty argo-api-client", "objectRef": { "resource": "workflows", "apiGroup": "argoproj.io", "apiVersion": "v1alpha1" }, "responseStatus": { "metadata": {}, "code": 200 }, "requestReceivedTimestamp": "2025-12-03T10:34:35.475997Z", "stageTimestamp": "2025-12-03T10:34:35.483591Z", "annotations": { "authorization.k8s.io/decision": "allow", "authorization.k8s.io/reason": "" } }