def compose_container_data(self, container_id, container_spec, container_status, spec, status, labels): # TODO:是否有更好方式处理下面数据 return { 'volumes': [{ 'hostPath': info.get('name', ''), 'mountPath': info.get('mountPath', ''), 'readOnly': info.get('readOnly', '') } for info in container_spec.get('volumeMounts') or []], 'ports': container_spec.get('ports') or [], 'command': { 'command': container_spec.get('command', ''), 'args': ' '.join(container_spec.get('args', '')) }, 'network_mode': spec.get('dnsPolicy', ''), 'labels': [{ 'key': key, 'val': val } for key, val in labels.items()], 'resources': container_spec.get('resources', {}), 'health_check': container_spec.get('livenessProbe', {}), 'readiness_check': container_spec.get('readinessProbe', {}), 'host_ip': status.get('hostIP', ''), 'container_ip': status.get('podIP', ''), 'host_name': spec.get('nodeName', ''), 'container_name': container_status.get('name', ''), 'container_id': container_id, 'image': utils.image_handler(container_status.get('image', '')), # 先保留env, 因为前端还没有适配 'env_args': container_spec.get('env', []) }
def get_task_group_info_base(self, data, namespace=None): """获取pod信息""" ret_data = {} for info in data: info_data = info.get("data", {}) task_group_name = info_data.get("metadata", {}).get("name") for info in info_data.get("containerStatuses", []): info["image"] = image_handler(info.get("image", "")) # 处理状态 ret_data[task_group_name] = { "name": task_group_name, "namespace": namespace, "status": info_data.get("status"), "type": "taskgroup", "container_list": info_data.get("containerStatuses", []), "message": info_data.get("message", ""), "start_time": info_data.get("startTime", ""), "pod_ip": info_data.get("podIP", ""), "host_ip": info_data.get("hostIP", ""), } return ret_data