如果 k8s 的 jsonpath 缺少 AND 条件,如何执行 2 个过滤器

Ale*_*lex 8 jsonpath kubernetes

我需要找到所有副本仍在启动的 st。为此,我需要根据 2 个条件过滤 sts 项目:

  • 每个项目必须有一个.status.readyReplicas属性
  • 每个readyReplicas属性必须与中的值不同replicas

我尝试的结果出现错误:

$ kubectl get sts -o=jsonpath='{range .items[?(@.status.readyReplicas && @.status.readyReplicas!=@.status.replicas)]}{.}{.metadata.name}{"\t"}{.status.readyReplicas}{"/"}{.status.replicas}{"\n"}{end}'
error: error parsing jsonpath {range .items[?(@.status.readyReplicas && @.status.readyReplicas!=@.status.replicas)]}{.}{.metadata.name}{"\t"}{.status.readyReplicas}{"/"}{.status.replicas}{"\n"}{end}, unrecognized character in action: U+0026 '&'

$ kubectl get sts -o=jsonpath='{range .items[?(@.status.readyReplicas AND @.status.readyReplicas!=@.status.replicas)]}{.}{.metadata.name}{"\t"}{.status.readyReplicas}{"/"}{.status.replicas}{"\n"}{end}'
error: error executing jsonpath "{range .items[?(@.status.readyReplicas AND @.status.readyReplicas!=@.status.replicas)]}{.}{.metadata.name}{\"\\t\"}{.status.readyReplicas}{\"/\"}{.status.replicas}{\"\\n\"}{end}": Error executing template: unrecognized identifier AND. Printing more information for debugging the template: ...
Run Code Online (Sandbox Code Playgroud)

使用逗号在数组上的 JsonPath AND 运算符上建议的解决方案也不起作用:

$ k get sts -o=jsonpath='{range .items[?(@.status.readyReplicas), ?(@.status.readyReplicas!=@.status.replicas)]}{.}{.metadata.name}{"\t"}{.status.readyReplicas}{"/"}{.status.replicas}{"\n"}{end}'
error: error parsing jsonpath {range .items[?(@.status.readyReplicas), ?(@.status.readyReplicas!=@.status.replicas)]}{.}{.metadata.name}{"\t"}{.status.readyReplicas}{"/"}{.status.replicas}{"\n"}{end}, unclosed array expect ]
Run Code Online (Sandbox Code Playgroud)

我正在寻找 k8s 的 jsonpath 本机解决方案,而不是 等的解决方法jq。感谢您的帮助。