I am working in OCP trying to access the following information from the yaml output generated by oc get nodes my-node -o yaml using the -o jsonpath {} feature.
i.e. The full yaml output
apiVersion: v1
kind: Node
metadata:
annotations:
k8s.ovn.org/gateway-mtu-support: "false"
k8s.ovn.org/host-addresses: '["10.19.45.59","192.168.122.228","2620:52:0:132d:2017:5303:e319:1543"]'
k8s.ovn.org/l3-gateway-config: '{"default":{"mode":"shared","interface-id":"br-ex_worker-226","mac-address":"10:70:fd:0a:69:44","ip-addresses":["192.168.122.228/24"],"ip-address":"192.168.122.228/24","next-hops":["192.168.122.1"],"next-hop":"192.168.122.1","node-port-enable":"true","vlan-id":"0"}}'
k8s.ovn.org/node-chassis-id: 72a8f396-fafa-4158-8fc6-5b2066bebb65
k8s.ovn.org/node-gateway-router-lrp-ifaddr: '{"ipv4":"100.64.0.5/16"}'
I want to access "next-hop" and "ip-address" from k8s.ovn.org/l3-gateway-config.
However when I try the following that I would expect to work here:
oc get nodes $HOSTNAME_BMH_NODE_2 -o jsonpath={.metadata.annotations['k8s.ovn.org/l3-gateway-config']}
I get the error invalid array index k8s.ovn.org/l3-gateway-config
How can I access this data using jsonpath? Is it failing to do the '.' or / or something else? I tried escaping these characters with a leading \ to no avail
You need to escape all instances of
.in the key. So given:The following should work:
Using my local cluster, I have:
And I can successfully run: