我有一个看起来像这样的 yaml 文件:
apiVersion: v1
entries:
blue-green-toggle:
- description: Used to toggle an application between blue and green
name: blue-green-toggle
version: 1.0.17
apiVersion: v2
- description: Used to toggle an application between blue and green
name: blue-green-toggle
version: 1.0.16
apiVersion: v2
- description: Used to toggle an application between blue and green
name: blue-green-toggle
version: 1.0.15
apiVersion: v2
istio-config:
- description: Used to configure the cluster level settings of istio.
name: istio-config
version: 1.0.4
apiVersion: v2
- description: Used to configure the cluster level settings of istio.
name: istio-config
version: 1.0.1
apiVersion: v2
latest-toggle:
name: latest-toggle
version: 1.0.5
apiVersion: v2
standard-helm-chart:
name: standard-helm-chart
version: 1.1.10
apiVersion: v2
name: standard-helm-chart
version: 2.0.1
apiVersion: v2
name: standard-helm-chart
version: 1.0.34
apiVersion: v2
name: standard-helm-chart
version: 1.0.10
apiVersion: v2
name: standard-helm-chart
version: 1.0.9
apiVersion: v2
generated: 2021-06-22T00:22:33.1554922Z
...
我正在尝试列出以version
开头1.0.
并在该standard-helm-chart
部分中列出的数字。
到目前为止,我已经使用它来获取以下条目standard-helm-chart
:
yq eval '.entries | .standard-arup-helm-chart' index.yaml
那工作得很好。所以然后我尝试只找到version
匹配的行1.0.*
。我阅读了 的选择文档,yq
但它并没有说明当您查看对象而不是字符串时如何匹配。
我试过这个:
yq eval '.entries | .standard-arup-helm-chart | select(. == "1.0.*")' index.yaml
但这失败了。我希望它会这样做,因为它无法将“1.0.*”的字符串与整个对象进行比较。
我也试过:
yq eval '.entries | .standard-arup-helm-chart | select(.version == "1.0.*")' index.yaml
认为这会让yq
我知道我只想看看版本。但它说Error: Cannot index array with 'version'
然后我想我需要尝试一个数组样式的语法:
yq eval '.entries | .standard-arup-helm-chart | select(.[version] == "1.0.*")' index.yaml
但这会因解析错误而失败。
我可以发送什么命令yq
来获取所有以 开头的版本号1.0.
?