""" API endpoints для управления Kubernetes Автор: Сергей Антропов Сайт: https://devops.org.ru """ from fastapi import APIRouter, Request, HTTPException from fastapi.responses import HTMLResponse, JSONResponse from fastapi.templating import Jinja2Templates from pathlib import Path from typing import List, Dict from app.core.config import settings from app.core.make_executor import MakeExecutor router = APIRouter() templates_path = Path(__file__).parent.parent.parent.parent / "templates" templates = Jinja2Templates(directory=str(templates_path)) executor = MakeExecutor() @router.get("/k8s", response_class=HTMLResponse) async def k8s_page(request: Request): """Страница управления Kubernetes""" return templates.TemplateResponse( "pages/k8s/index.html", {"request": request} ) @router.get("/api/v1/k8s/clusters", response_class=HTMLResponse) async def get_k8s_clusters(): """API endpoint для получения списка K8s кластеров""" try: # Попытка получить кластеры через kind result = executor.execute("kind get clusters", capture_output=True) if result.returncode == 0 and result.stdout.strip(): clusters = [c.strip() for c in result.stdout.strip().split('\n') if c.strip()] if clusters: html = '
' for cluster in clusters: html += f'' html += '
Имя кластераДействия
{cluster}
' return html # Если кластеров нет или kind не установлен return """

Kubernetes кластеры не найдены

Используйте команду make k8s create kubernetes для создания кластера через Kind.

""" except Exception as e: return f"""
Ошибка при получении списка кластеров: {str(e)}
Убедитесь, что Kind установлен и доступен
"""