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

Malformed JSON response, the 'object' and/or 'type' field is missing in JSON #170

Open
Qubad786 opened this issue Dec 2, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@Qubad786
Copy link

Qubad786 commented Dec 2, 2021

we maintaining this client's fork @ https://github.com/truenas/kubernetes_asyncio – I have faced an issue recently where client is unable to parse out 400 error and instead raise a bare exception.

Steps to reproduce

  1. Create a pod which is stuck in initialization e.g.
apiVersion: v1
kind: Pod
metadata:
  name: busybox-79d6c664ff-zsr9f
spec:
  initContainers:
  - name: bb
    command:
    - sh
    - -c
    - tail -f /dev/null
    image: busybox
    imagePullPolicy: Always
  containers:
  - image: busybox
    imagePullPolicy: Always
    name: busybox
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-zxjnv
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  restartPolicy: Always
  1. Make sure its in PodInitializing:
$ kubectl get po
busybox-79d6c664ff-zsr9f   0/1     Init:0/1           0          27m

$ kubectl logs po/busybox-79d6c664ff-zsr9f -c busybox
Error from server (BadRequest): container "busybox" in pod "busybox-79d6c664ff-zsr9f" is waiting to start: PodInitializing
  1. k8s client snippet that results in a bare exception:
import asyncio
from kubernetes_asyncio import client, config
from kubernetes_asyncio.watch import Watch
from kubernetes_asyncio.client.api_client import ApiClient


async def main():
    await config.load_kube_config()
    api = ApiClient()
    watch = Watch()
    async with watch.stream(
        client.CoreV1Api(api).read_namespaced_pod_log,
        name="busybox-79d6c664ff-zsr9f",
        container="busybox",
        namespace="default"
    ) as stream:
        # v1 = client.CoreV1Api(api)
        print([
            e async for e in stream
        ])

if __name__ == '__main__':
    asyncio.run(main())

---    
Exception: Malformed JSON response, the 'object' and/or 'type' field is missing. JSON: {'kind': 'Status', 'apiVersion': 'v1', 'metadata': {}, 'status': 'Failure', 'message': 'container "busybox" in pod "busybox-79d6c664ff-zsr9f" is waiting to start: PodInitializing', 'reason': 'BadRequest', 'code': 400}

Actual

Exception: Malformed JSON response, the 'object' and/or 'type' field is missing. JSON: {'kind': 'Status', 'apiVersion': 'v1', 'metadata': {}, 'status': 'Failure', 'message': 'container "busybox" in pod "busybox-79d6c664ff-zsr9f" is waiting to start: PodInitializing', 'reason': 'BadRequest', 'code': 400}

Expected

A meaningful exception scheme that can be handled by calling body to extract information and present to the end user

Thanks!

@tomplus
Copy link
Owner

tomplus commented Dec 2, 2021

Thanks for reporting it.

@tomplus tomplus added the bug Something isn't working label Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants