I'm trying to get the list of my Kubernetes cluster nodes based on some condition i.e. if Taint exists or not. I have 3 node cluster (1 master and 2 worker). I need to get the 2 worker node names as the taint is on master node. I'm stuck here as I'm getting the opposite result i.e. able to get the node with taint (master). Please assist to help me to put ! operator so that I can get only nodes without any taints.
This is my JSONPath query till now:-
vagrant@mykubemaster:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
mykubemaster Ready control-plane,master 12d v1.20.1
mykubenode01 Ready <none> 12d v1.20.1
mykubenode02 Ready <none> 12d v1.20.1
vagrant@mykubemaster:~$ kubectl get nodes -o=jsonpath='{$.items[?(@.spec.taints)].metadata.name}'
mykubemastervagrant@mykubemaster:~$
Kubernetes/kubectl is using a Go JSONPath implementation that (sadly) does not support path filter expressions with a negation; in fact, many implementations do not support syntax like:
$[?(!(@.key==42))]
See this extensive comparisons: