kubernetes_asyncio
kubernetes_asyncio copied to clipboard
Malformed JSON response, the 'object' and/or 'type' field is missing in JSON
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
- 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
- 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
- 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!
Thanks for reporting it.