1

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:~$
vinod827
  • 1,123
  • 1
  • 21
  • 45
  • Testing for the absence of a property isn't specified in JSON Path traditionally. Kubernetes might have some support for it, so I'll leave it to those experts. You may find https://github.com/ietf-wg-jsonpath/draft-ietf-jsonpath-jsonpath/issues/17 of interest. – gregsdennis Jan 10 '21 at 23:16
  • There is a very rich expression language available to you as [`-o go-template=`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#get); have you considered using that? – mdaniel Jan 11 '21 at 02:29

1 Answers1

4

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:

wp78de
  • 18,207
  • 7
  • 43
  • 71