fluxcd / flux2

Open and extensible continuous delivery solution for Kubernetes. Powered by GitOps Toolkit.
https://fluxcd.io
Apache License 2.0
6.47k stars 599 forks source link

CLI: Add the option to filter 'flux get' output #2922

Open marevers opened 2 years ago

marevers commented 2 years ago

As of now, it is not possible to filter the output of the 'flux get' command. Some examples of usecases:

It would be good to have flags to filter the output, e.g.:

flux get kustomizations --suspended true flux get all --ready false

Or with one flag supporting a key-value pair containing the filter parameters:

flux get all --filter ready=false

These would then only return resources that match the given filter.

hiddeco commented 2 years ago

You can already filter using --status-selector, see https://github.com/fluxcd/flux2/issues/1587 and https://github.com/fluxcd/flux2/pull/1594.

marevers commented 2 years ago

@hiddeco Thank you, I checked the feature but it only seems to support status. That would cover the usecase of for instance getting resources that are not ready, but not getting resources that are suspended.

Status is saved in status.conditions[].type and status.conditions[].status while suspended state seems to be saved in spec.suspend which is most likely why the feature you mentioned does not support it.

Maybe this could then be handled in a separate flag? Or have it conditionally look at spec.suspend if the input is e.g. --status-selector suspend=true. Seeing as being suspended could also be described as being a status.

matejhasul commented 2 years ago

We are missing this feature too. Currently we are using this as a workaround:

for kind in helmreleases kustomizations gitrepositories helmcharts helmrepositories; do
  kubectl get -A $kind -o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name,SUSPENDED:.spec.suspend;
done
cdenneen commented 5 months ago

@hiddeco would also be nice to have something like --status-filter ready!=true which would show false,unknown together. More times than not I'm not looking for the "true" ones but any other ones. I've tried the above as well as ready="false|unknown", ready=false,unknown to see if it was possible already.