Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting ERROR: Unable to create event: 422 from k8s_event #49

Open
zeusng-fast opened this issue Jul 19, 2023 · 1 comment
Open

Getting ERROR: Unable to create event: 422 from k8s_event #49

zeusng-fast opened this issue Jul 19, 2023 · 1 comment

Comments

@zeusng-fast
Copy link

We try to call k8s_event from our Ansible Operator, using v0.5.0 operator-sdk-ansible-util.

- name: Create Kubernetes Event
  k8s_event:
    state: present
    name: test-k8s-event
    namespace: dtest2
    message: "mycluster getting created Event created"
    reason: Testing event creation
    reportingComponent: Reporting components
    source:
      component: Metering components
    appendTimestamp: true
    type: Normal
    involvedObject:
      apiVersion: v2
      kind: MYCluster
      name: "nfdm"
      namespace: dtest2

and receive the following error

TASK [Create Kubernetes Event] ******************************** 
The full traceback is:
  File "/tmp/ansible_k8s_event_payload_emz5w5mf/ansible_k8s_event_payload.zip/ansible_collections/operator_sdk/util/plugins/modules/k8s_event.py", line 283, in execute_module
  File "/usr/local/lib/python3.8/site-packages/kubernetes/dynamic/client.py", line 119, in create
    return self.request('post', path, body=body, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/kubernetes/dynamic/client.py", line 57, in inner
    raise api_exception(e)
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "api_key": null,
            "appendTimestamp": true,
            "ca_cert": null,
            "client_cert": null,
            "client_key": null,
            "context": null,
            "host": null,
            "involvedObject": {
                "apiVersion": "v2",
                "kind": "MYCluster",
                "name": "nfdm",
                "namespace": "dtest2"
            },
            "kubeconfig": null,
            "merge_type": null,
            "message": "mycluster getting created Event created",
            "name": "test-k8s-event.2023-07-19 05:53:16.108007+00:00",
            "namespace": "dtest2",
            "password": null,
            "persist_config": null,
            "proxy": null,
            "reason": "Testing event creation",
            "reportingComponent": "Reporting components",
            "source": {
                "component": "Metering components"
            },
            "state": "present",
            "type": "Normal",
            "username": null,
            "validate_certs": null
        }
    },
    "msg": "Unable to create event: 422\nReason: Unprocessable Entity\nHTTP response headers: HTTPHeaderDict({'Audit-Id': '6f22fb6d-242a-4884-b484-e119547c2d83', 'Cache-Control': 'no-cache, private', 'Content-Length': '484', 'Content-Type': 'application/json', 'Date': 'Wed, 19 Jul 2023 05:53:16 GMT', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'X-Kubernetes-Pf-Flowschema-Uid': 'c2be4a14-8cda-4aab-8a0e-4f6decf987a1', 'X-Kubernetes-Pf-Prioritylevel-Uid': '51d524af-e0da-4476-add1-66e61405e5e0'})\nHTTP response body: b'{\"kind\":\"Status\",\"apiVersion\":\"v1\",\"metadata\":{},\"status\":\"Failure\",\"message\":\"Event \\\\\"test-k8s-event.2023-07-19 05:53:16.108007+00:00\\\\\" is invalid: involvedObject.namespace: Invalid value: \\\\\"\\\\\": does not match event.namespace\",\"reason\":\"Invalid\",\"details\":{\"name\":\"test-k8s-event.2023-07-19 05:53:16.108007+00:00\",\"kind\":\"Event\",\"causes\":[{\"reason\":\"FieldValueInvalid\",\"message\":\"Invalid value: \\\\\"\\\\\": does not match event.namespace\",\"field\":\"involvedObject.namespace\"}]},\"code\":422}\\n'\nOriginal traceback: \n  File \"/usr/local/lib/python3.8/site-packages/kubernetes/dynamic/client.py\", line 55, in inner\n    resp = func(self, *args, **kwargs)\n\n  File \"/usr/local/lib/python3.8/site-packages/kubernetes/dynamic/client.py\", line 270, in request\n    api_response = self.client.call_api(\n\n  File \"/usr/local/lib/python3.8/site-packages/kubernetes/client/api_client.py\", line 348, in call_api\n    return self.__call_api(resource_path, method,\n\n  File \"/usr/local/lib/python3.8/site-packages/kubernetes/client/api_client.py\", line 180, in __call_api\n    response_data = self.request(\n\n  File \"/usr/local/lib/python3.8/site-packages/kubernetes/client/api_client.py\", line 391, in request\n    return self.rest_client.POST(url,\n\n  File \"/usr/local/lib/python3.8/site-packages/kubernetes/client/rest.py\", line 276, in POST\n    return self.request(\"POST\", url,\n\n  File \"/usr/local/lib/python3.8/site-packages/kubernetes/client/rest.py\", line 235, in request\n    raise ApiException(http_resp=r)\n"
}
@piec
Copy link

piec commented Oct 30, 2023

Hi just had the same issue, just remove appendTimestamp: true.

The implementation of appendTimestamp [source] is weird and makes an early return in the function, it doesn't include the involved_obj.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants