┌─────────────────────────────────────────────────────────────────────┐ │ Control Loop (Every 5 seconds) │ └─────────────────────────────────────────────────────────────────────┘ │ ▼ ┌──────────────────────────────────────────────┐ │ 1. Discover Pods on Node │ │ - Watch Kubernetes API │ │ - Filter by node name │ │ - Extract labels & annotations │ └──────────────────┬───────────────────────────┘ │ ▼ ┌──────────────────────────────────────────────┐ │ 2. Classify Workloads │ │ - Read pod labels │ │ - Group by: latency-critical, batch, │ │ default │ └──────────────────┬───────────────────────────┘ │ ▼ ┌──────────────────────────────────────────────┐ │ 3. Collect Metrics │ │ - CPU usage per class (from cgroups) │ │ - P95/P99 latency per class │ │ (scrape from app /metrics) │ │ - Current cpu.weight per class │ │ - Runqueue length (contention proxy) │ └──────────────────┬───────────────────────────┘ │ ▼ ┌──────────────────────────────────────────────┐ │ 4. Build State Vector │ │ - Aggregate metrics │ │ - Normalize values │ │ - Include previous action │ └──────────────────┬───────────────────────────┘ │ ▼ ┌──────────────────────────────────────────────┐ │ 5. Query RL Optimizer (gRPC) │ │ - Send State │ │ - Receive Action │ │ - Timeout: 100ms │ └──────────────────┬───────────────────────────┘ │ ▼ ┌──────────────────────────────────────────────┐ │ 6. Validate Action (Safety Layer) │ │ - Check weight bounds (100-10000) │ │ - Check rate limits │ │ - Validate delta from current │ └──────────────────┬───────────────────────────┘ │ ▼ ┌────────────────┐ │ Valid Action? │ └────────┬───────┘ │ ┌────────────┴────────────┐ │ │ Yes No │ │ ▼ ▼ ┌──────────────────────┐ ┌──────────────────┐ │ 7. Execute Action │ │ 7. Skip Action │ │ - Update cgroups │ │ - Log reason │ │ - Log action │ └──────────────────┘ └──────────┬───────────┘ │ ▼ ┌──────────────────────────────────────────────┐ │ 8. Wait & Collect New State (2 seconds) │ │ - Allow metrics to reflect change │ │ - Collect post-action state │ └──────────┬───────────────────────────────────┘ │ ▼ ┌──────────────────────────────────────────────┐ │ 9. Calculate Reward │ │ - Latency improvement │ │ - SLA violations penalty │ │ - Oscillation penalty │ └──────────┬───────────────────────────────────┘ │ ▼ ┌──────────────────────────────────────────────┐ │ 10. Send Feedback to RL (gRPC) │ │ - Previous state │ │ - Action taken │ │ - Reward received │ │ - New state │ └──────────┬───────────────────────────────────┘ │ ▼ ┌──────────────────────────────────────────────┐ │ 11. Check for Degradation │ │ - Compare P99 with snapshot │ │ - If >20% increase → Rollback │ └──────────┬───────────────────────────────────┘ │ ▼ ┌──────────────────────────────────────────────┐ │ 12. Update Metrics │ │ - Export to Prometheus │ │ - Update action counters │ └──────────┬───────────────────────────────────┘ │ ▼ [Wait 5 seconds] │ └─────── Loop ────────┘