首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用ansible-算子生成Kubernetes CR的提取状态

用ansible-算子生成Kubernetes CR的提取状态
EN

Stack Overflow用户
提问于 2022-03-18 08:37:45
回答 1查看 149关注 0票数 -1

我对json查询还不熟悉。status.conditions[ansibleResult].type提取面临的困难

我定义并创建了一个CRD,它是由在后台运行ansible的operator获取的。一旦CR被运营商-sdk接受和处理,我将更新CRD以提供相关的状态。

json中的CR输出如下所示。

代码语言:javascript
运行
复制
{
    "apiVersion": "vault.cpe.oraclecloud.com/v1alpha1",
    "kind": "OciVaultKeys",
    "metadata": {
        "annotations": {
            "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"vault.cpe.oraclecloud.com/v1alpha1\",\"kind\":\"OciVaultKeys\",\"metadata\":{\"annotations\":{},\"name\":\"operator-key-broken\",\"namespace\":\"tms\"},\"spec\":{\"freeformTags\":[{\"key\":\"Type\",\"value\":\"Optional-Values-Added\"}],\"ociVaultKeyName\":\"operator-key-broken\",\"ociVaultKeyShapeAlgorithm\":\"RSA\",\"ociVaultKeyShapeLength\":32,\"ociVaultName\":\"ocivault-sample-12\"}}\n"
        },
        "creationTimestamp": "2022-03-18T07:43:03Z",
        "finalizers": [
            "vault.cpe.oraclecloud.com/finalizer"
        ],
        "generation": 1,
        "name": "operator-key-broken",
        "namespace": "tms",
        "resourceVersion": "717880023",
        "selfLink": "/apis/vault.cpe.oraclecloud.com/v1alpha1/namespaces/tms/ocivaultkeys/operator-key-broken",
        "uid": "0d634e72-f592-48e0-be9b-ebfa017b2dfe"
    },
    "spec": {
        "freeformTags": [
            {
                "key": "Type",
                "value": "Optional-Values-Added"
            }
        ],
        "ociVaultKeyName": "operator-key-broken",
        "ociVaultKeyShapeAlgorithm": "RSA",
        "ociVaultKeyShapeLength": 32,
        "ociVaultName": "ocivault-sample-12"
    },
    "status": {
        "conditions": [
            {
                "lastTransitionTime": "2022-03-18T07:43:27Z",
                "message": "",
                "reason": "",
                "status": "False",
                "type": "Successful"
            },
            {
                "lastTransitionTime": "2022-03-18T08:26:08Z",
                "message": "Running reconciliation",
                "reason": "Running",
                "status": "False",
                "type": "Running"
            },
            {
                "ansibleResult": {
                    "changed": 0,
                    "completion": "2022-03-18T08:26:24.217728",
                    "failures": 1,
                    "ok": 14,
                    "skipped": 1
                },
                "lastTransitionTime": "2022-03-18T08:26:25Z",
                "message": "The task includes an option with an undefined variable. The error was: No first item, sequence was empty.\n\nThe error appears to be in '/home/opc/cpe-workstation/mr_folder/workspace-2/osvc-kubernetes-operators/oci-services/roles/ocivaultkeys/tasks/fetch_vault_details_oci.yml': line 12, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: DEBUG | Fetch Vault Details | Extract Vault OCID n service_endpoint in source region\n  ^ here\n",
                "reason": "Failed",
                "status": "True",
                "type": "Failure"
            }
        ]
    }
}

我希望可靠地提取status.conditions[].type (用于ansibleResult元素)。

CRD定义摘录如下

代码语言:javascript
运行
复制
  - name: v1alpha1
    served: true
    storage: true
    additionalPrinterColumns:
      - description: 'Status of the OCI Vault Key'
        jsonPath: .status.conditions[-1].type
        name: STATUS
        type: string
        priority: 0

CRD正在寻找一个要提取的jsonPath表达式。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-18 17:40:21

请试如下:

kubectl get ocivaultkeys operator-key-broken -o jsonpath='{.status.conditions[?(@.ansibleResult)].type}'

预期产出:Failure

jsonpath帮助

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71524310

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档