argoproj / argo-workflows

Workflow Engine for Kubernetes
https://argo-workflows.readthedocs.io/
Apache License 2.0
14.84k stars 3.17k forks source link

Field selectors should support all native k8s operators #13468

Open DGoldfayn opened 4 weeks ago

DGoldfayn commented 4 weeks ago

Summary

What change needs making?

Currently in the field-selector function there are a lot of limitations compared to native kubectl.

https://github.com/argoproj/argo-workflows/blob/89f2ed1d041d2f555d646ee02b77c7e1dc2bda10/server/utils/list_options.go#L77

For instance, metadata.name or metadata.namespace only work with = and are converted into a simple name lookup.

The k8s package as far as I know already allows for a similar approach as labels.Requirements, where you can use the full range of kubectl field-selectors.

https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/

The function should be updated to allow for instance the usage of operators like !=

Use Cases

When would you use this?

Currently we want to use the argo cli to stop a list of ongoing workflows using a combination of criteria such as:

argo stop --field-selector "metadata.name!=workflow_name" -l workflows.argoproj.io/workflow-template!=some_template"

If we omit the --field-selector flag this works flawlessly, with it it returns the following error:

FATA[2024-08-14T15:36:43.802Z] rpc error: code = InvalidArgument desc = unsupported requirement metadata.name!=workflow_name


Message from the maintainers:

Love this feature request? Give it a 👍. We prioritise the proposals with the most 👍.

agilgur5 commented 4 weeks ago

metadata.name or metadata.namespace

To clarify for anyone that stumbles upon this, these are the only two fields allowed on custom resources, c.f. https://github.com/kubernetes/kubernetes/issues/53459 (related: https://github.com/argoproj/argo-workflows/issues/11555#issuecomment-1676990143)

The function should be updated to allow for instance the usage of operators like !=

I think supporting more operators should be possible though. I've reworded the title to be more specific on that

See also https://github.com/argoproj/argo-workflows/discussions/8500#discussioncomment-2647456