vmware-labs / yaml-jsonpath

JSONPath implementation for the gopkg.in/yaml.v3 node API
Other
49 stars 12 forks source link

Cannot use filters outside of arrays #48

Closed ahuffman closed 3 years ago

ahuffman commented 3 years ago

As a user, I would like to be able to use JSONPath filters to recursively search for a particular value on yaml nodes that are not only limited to arrays/sequence nodes.

An example of this would be when a user would like to look up all instances of a value in a kubernetes manifest, so that all instances of that value can be replaced.

Consider the following query and Kubernetes manifest: $..[?(@ == "dns-udp")]

---
apiVersion: v1
kind: Service
metadata:
  name: bind-udp
  namespace: tanzu-dns
  labels:
    app.kubernetes.io/name: external-dns
  annotations:
    # NOTE: this only works on 1.19.1+vmware.1+, but not prior
    ## This annotation will be ignored on other cloud providers
    service.beta.kubernetes.io/aws-load-balancer-type: nlb
spec:
  selector:
    app.kubernetes.io/name: external-dns
  type: LoadBalancer
  ports:
    - name: dns-udp
      port: 53
      protocol: UDP
      targetPort: dns-udp
status: {}

I would like the yamlNodes returned which should contain the values:

[
  "dns-udp",
  "dns-udp"
]