feat: добавлена пометка типа операции (Build/Push) в истории сборок Dockerfile
- Добавлена колонка 'Тип' во все таблицы истории сборок - Для push операций отображается registry вместо платформ - Сохранение пользователя при создании push лога - Исправлена ошибка с logger в push_docker_image endpoint - Улучшено отображение истории сборок с визуальными индикаторами
This commit is contained in:
62
app/api/v1/endpoints/k8s.py
Normal file
62
app/api/v1/endpoints/k8s.py
Normal file
@@ -0,0 +1,62 @@
|
||||
"""
|
||||
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 = '<div class="table-responsive"><table class="table table-hover"><thead><tr><th>Имя кластера</th><th>Действия</th></tr></thead><tbody>'
|
||||
for cluster in clusters:
|
||||
html += f'<tr><td><code>{cluster}</code></td><td><button class="btn btn-sm btn-outline-primary">Детали</button></td></tr>'
|
||||
html += '</tbody></table></div>'
|
||||
return html
|
||||
|
||||
# Если кластеров нет или kind не установлен
|
||||
return """
|
||||
<div class="text-center py-5">
|
||||
<i class="fas fa-cube fa-3x text-muted mb-3"></i>
|
||||
<p class="text-muted mb-2">Kubernetes кластеры не найдены</p>
|
||||
<p class="text-muted small">
|
||||
Используйте команду <code>make k8s create kubernetes</code> для создания кластера через Kind.
|
||||
</p>
|
||||
</div>
|
||||
"""
|
||||
except Exception as e:
|
||||
return f"""
|
||||
<div class="alert alert-warning">
|
||||
<i class="fas fa-exclamation-triangle me-2"></i>
|
||||
<strong>Ошибка при получении списка кластеров:</strong> {str(e)}
|
||||
<br><small class="text-muted">Убедитесь, что Kind установлен и доступен</small>
|
||||
</div>
|
||||
"""
|
||||
Reference in New Issue
Block a user