【发布时间】:2021-07-13 23:16:58
【问题描述】:
我有一个数据结构(由 kubectl 提供),格式如下,与集群中的一些自定义资源定义相关。当列表元素的.status.conditions 列表的条件为.type == "Ready" 和.status == "False" 时,我想使用jq 或类似的方法返回.items[x].metadata.name。
“业务案例”是“获取任何尚未准备好的自定义资源。”
我感觉数据的结构使这变得困难,但我想知道是否可以使用jq。
非常感谢任何帮助!
{
"apiVersion": "v1",
"items": [
{
"metadata": {
"name": "return-me"
},
"spec": {
"region": "ap-southeast-2"
},
"status": {
"conditions": [
{
"message": "Some Condition A",
"reason": "Supported",
"status": "True",
"type": "IsSupported"
},
{
"message": "Some Condition B",
"reason": "Shared",
"status": "True",
"type": "IsShared"
},
{
"message": "Some Condition C",
"reason": "Accepted",
"status": "False",
"type": "IsAccepted"
},
{
"status": "True",
"type": "OthersReady"
},
{
"status": "False",
"type": "Ready"
}
]
}
},
{
"metadata": {
"name": "dont-return-me"
},
"spec": {
"region": "ap-northeast-1"
},
"status": {
"conditions": [
{
"message": "Some Condition A",
"reason": "Supported",
"status": "True",
"type": "IsSupported"
},
{
"message": "Some Condition B",
"reason": "Shared",
"status": "True",
"type": "IsShared"
},
{
"message": "Some Condition C",
"reason": "Accepted",
"status": "False",
"type": "IsAccepted"
},
{
"status": "True",
"type": "OthersReady"
},
{
"status": "True",
"type": "Ready"
}
]
}
},
],
"kind": "List",
"metadata": {
"resourceVersion": "",
"selfLink": ""
}
}
【问题讨论】: