Let’s say we have several nodes, and we want to know the names that have taints . . .

Andres Caro:
let’s say we have several nodes, and we want to know the names that have taints on them, the following command would do the job:
k get no -o jsonpath='{.items[?(@.spec.taints[*].key)].metadata.name}'

But how to do the opposite? (filter the nodes that don’t have taints on them)

What I did is adding the ! before the @ to negate the filter, but I’m getting an error:

error: error parsing jsonpath {.items[?(!@.spec.taints[*].key)].metadata.name}, unrecognized character in action: U+0021 '!'

What is the right approach to do it?

Pranay:
I am not sure how to do this using just kubectl/jsonpath - but sometime in exam they will ask like this but they don’t care how you get the answer , you can do it manually as well (some time) (for example see the sample question I posted on kubernetes channel by CNCF - they solved it live on stage just by looking at cluster manually :slightly_smiling_face: )

One way I will do if I have access to bash/linux and kubectl is like this :

controlplane $ kubectl get nodes
NAME               STATUS   ROLES    AGE   VERSION
k3d-k8s-agent-0    Ready    <none>   13m   v1.19.3+k3s2
k3d-k8s-agent-1    Ready    <none>   13m   v1.19.3+k3s2
k3d-k8s-server-0   Ready    master   13m   v1.19.3+k3s2

controlplane $ kubectl describe nodes | tr -s ' ' | grep -B 30 "Taints: <none>" | grep "Name:" | cut -d ":" -f2 | xargs
k3d-k8s-agent-0 k3d-k8s-agent-1

This might not be exactly what you were looking for but it gets things done :slightly_smiling_face:

Andres Caro:
They don’t care how you get the answer?, It is for sure or you suppose that?

Andres Caro:
You are a pipeline master! :sunglasses:

Claudio:
@Andres Caro … I also have the same query as you… are we just assuming that they dont care how we get the answer ?? … unless they specifically ask for output in a specific format,ie: json

Andres Caro:
@Pranay Based on your solution, I have come with the following:

controlplane $ k get no -o custom-columns='NODE:.metadata.name','TAINTS:.spec.taints[*].effect' | grep -i none | cut -d ' ' -f1
node01