|
1 | 1 | import os |
2 | 2 | import subprocess |
3 | 3 | import tempfile |
| 4 | +import datetime |
4 | 5 |
|
5 | 6 | import orjson |
6 | 7 |
|
@@ -87,3 +88,36 @@ async def list_iterator(): |
87 | 88 | yield name.split('/', 1)[1] |
88 | 89 | else: |
89 | 90 | raise Exception(output) |
| 91 | + |
| 92 | + |
| 93 | +def parse_pod_status(pod): |
| 94 | + creation_timestamp = pod['metadata']['creationTimestamp'] |
| 95 | + image = pod['spec']['containers'][0]['image'] |
| 96 | + image_tag = image.split(':')[-1] if ':' in image else 'latest' |
| 97 | + status_phase = pod['status']['phase'] |
| 98 | + return { |
| 99 | + 'creation_timestamp': creation_timestamp, |
| 100 | + 'image_tag': image_tag, |
| 101 | + 'status_phase': status_phase, |
| 102 | + } |
| 103 | + |
| 104 | + |
| 105 | +async def components_status(): |
| 106 | + res = { |
| 107 | + 'cache': {}, |
| 108 | + 'edge': {}, |
| 109 | + 'operator': [], |
| 110 | + } |
| 111 | + for pod in orjson.loads(await async_subprocess_check_output( |
| 112 | + 'kubectl', '-n', 'cdn-cache', 'get', 'pods', '-o', 'json' |
| 113 | + ))['items']: |
| 114 | + res['cache'].setdefault(pod['metadata']['name'].split('-')[0], []).append(parse_pod_status(pod)) |
| 115 | + for pod in orjson.loads(await async_subprocess_check_output( |
| 116 | + 'kubectl', '-n', 'cdn-edge', 'get', 'pods', '-o', 'json' |
| 117 | + ))['items']: |
| 118 | + res['edge'].setdefault(pod['metadata']['name'].split('-')[2], []).append(parse_pod_status(pod)) |
| 119 | + for pod in orjson.loads(await async_subprocess_check_output( |
| 120 | + 'kubectl', '-n', 'cwm-cdn-operator-system', 'get', 'pods', '-o', 'json' |
| 121 | + ))['items']: |
| 122 | + res['operator'].append(parse_pod_status(pod)) |
| 123 | + return res |
0 commit comments