k8s-alerts icon indicating copy to clipboard operation
k8s-alerts copied to clipboard

[FEATURE] Get pods status from k8s api

Open kareem-elsayed opened this issue 4 years ago • 3 comments

We can use the /api/v1/watch/pods endpoint to get and watch the status events for the pods instead of using kubectl tool

kareem-elsayed avatar Jun 02 '20 14:06 kareem-elsayed

You could assign this to me if there's no hurry to implement it.

muhammednagy avatar Jun 02 '20 14:06 muhammednagy

sure @muhammednagy

kareem-elsayed avatar Jun 02 '20 14:06 kareem-elsayed

Hi For now, after first testing how we can deal with /api/v1/watch/pods to fetch the API streaming events Here's the first approach and what do you think @muhammednagy @MohamedMSaeed @keroloswilliam here is the reference for more details https://requests.readthedocs.io/en/master/user/advanced/#streaming-requests

import json
import requests

r = requests.get("http://127.0.0.1:8001/api/v1/watch/pods", stream=True)

# fullback encoding for bya-data
if r.encoding is None:
    r.encoding = 'utf-8'
lines = r.iter_lines(decode_unicode=True)
for line in lines:
    if line:
        # load the bya-json to a string
        data = json.loads(line)

        # dumps the json object into an element
        json_data = json.dumps(data['object']['status'], indent=2)
        print(json_data)

kareem-elsayed avatar Jun 03 '20 13:06 kareem-elsayed