kube-back
메인 인덱스 | bob-yamong
실행 골격
main.py는 FastAPI를 root_path=/api/v2로 띄우고, CORS, correlation id middleware, timing middleware를 붙입니다.
- lifespan에서
uuid-ossp extension을 생성하고 logging을 초기화합니다.
uvicorn.run("main:app", **server_config.__dict__)가 실제 실행 경로입니다.
tests/api/는 HTTP 동작을, tests/integration/은 Alembic 기반 DB 검증을 담당합니다.
라우팅 흐름
service/__init__.py는 service/*/*_route.py를 importlib로 자동 로딩해 router를 조립합니다.
cluster, node, pod, container, policy, config, log, stream 모듈이 각각 전용 prefix를 가집니다.
service/stream/stream_route.py는 KAFKA_BROKERS가 있을 때 EventManager("lsm_topic")를 시작하고, /stream/heartbeat와 /stream/lsm을 SSE로 제공합니다.
service/log/log_route.py는 EventManager("lsm")를 연결해 로그 조회와 /log/lsm_stream 스트림을 제공합니다.
service/container/container_route.py, service/pod/pod_route.py, service/node/node_route.py, service/cluster/cluster_route.py는 각 리소스의 CRUD와 리스트/상세 조회를 분리합니다.
service/policy/policy_route.py와 service/config/config_route.py는 정책과 설정의 CRUD를 담당합니다.
데이터 모델
- 핵심 테이블은
ApiKeys, ConfigProperty, LdapUsers, ManagedUsers, NetworkFlows, Permissions, Policies, Teams입니다.
- 클러스터 계층은
Cluster, Namespace, Nodes, Pods, Containers, Deployment, KubeEvent로 이어집니다.
- 정책 관계는
PoliciesTags, PolicyControl, PolicyNetworkMonitor, PolicyTracepoint, TeamsPermissions가 담당합니다.
database/models.py에는 assetsview 테이블 정의도 포함됩니다.
이벤트와 로깅
utils/kafka/queueEventManager.py는 KafkaConsumer/KafkaProducer를 감싸고 topic별 subscriber, start/stop, send_message를 제공합니다.
utils/sse/sseManager.py는 topic별 asyncio.Queue를 관리해 SSE 클라이언트로 메시지를 뿌립니다.
utils/logging/logger.py는 LOG_DIR의 monitor.log에 회전 로그를 남기고, 콘솔에도 같은 포맷으로 출력합니다.
검증 자산
tests/api/asset_test/는 실제 API 경로를 순차 호출하는 시나리오 테스트를 담고 있습니다.
tests/integration/conftest.py는 alembic upgrade head를 먼저 적용한 뒤 DB 세션 fixture를 만듭니다.
의존성
requirements.txt에는 alembic, pytest, kafka-python-ng, psycopg2-binary, sse-starlette, timing-asgi, asgi-correlation-id, uvicorn이 들어갑니다.