feat(k8s): M14 Namespace 管理看板(资源配额 + 命名空间 CRUD)

- 后端: ListNamespacesDetailed/CreateNamespace/DeleteNamespace/ListResourceQuotas/ListLimitRanges
- 后端: GetNamespacesDetail handler (6 API calls aggregate, not N×3)
- 后端: CreateNamespaceHandler + DeleteNamespaceHandler (system NS protection)
- 前端: NamespaceManagementPage.tsx (~280行) — 表格+概览卡片+创建/删除弹框
- 路由: GET/POST/DELETE /:clusterCode/namespaces + GET /namespace/:ns/detail
- 验证: 9/9 通过 (urllib), TS 零错误, Vite 构建成功
This commit is contained in:
attacker committed 2026-06-24 23:46:52 +08:00
1 parent c7b61968bc
commit 8240a88a84
33 files changed
+2029 -71

No files matched your search

+9 -5
View File
@@ -28,6 +28,7 @@ type Report struct {
// CPUStat CPU 相关指标
type CPUStat struct {
UsagePercent float64 `json:"usage_percent"` // CPU 总体使用率(百分比)
IOWait float64 `json:"iowait"` // CPU 等待 IO 的时间占比(百分比)
CoreCount int `json:"core_count"` // CPU 逻辑核心数
Load1 float64 `json:"load1"` // 1 分钟平均负载
Load5 float64 `json:"load5"` // 5 分钟平均负载
@@ -39,16 +40,19 @@ type MemoryStat struct {
TotalGB float64 `json:"total_gb"` // 总内存(GB)
UsedGB float64 `json:"used_gb"` // 已用内存(GB)
CachedGB float64 `json:"cached_gb"` // 缓存(Buffers + Cached,GB)
AvailableGB float64 `json:"available_gb"` // 可用内存(GB),含可回收缓存 — 真实剩余可用
SwapUsedGB float64 `json:"swap_used_gb"` // Swap 已用量(GB)— OOM 金标准
UsagePercent float64 `json:"usage_percent"` // 内存使用率(百分比)
}
// DiskStat 单个挂载点的磁盘使用情况
type DiskStat struct {
Mount string `json:"mount"` // 挂载点
Device string `json:"device"` // 设备名
TotalGB float64 `json:"total_gb"` // 总容量(GB)
UsedGB float64 `json:"used_gb"` // 已用容量(GB)
UsagePercent float64 `json:"usage_percent"` // 使用率(百分比)
Mount string `json:"mount"` // 挂载点
Device string `json:"device"` // 设备名
TotalGB float64 `json:"total_gb"` // 总容量(GB)
UsedGB float64 `json:"used_gb"` // 已用容量(GB)
UsagePercent float64 `json:"usage_percent"` // 使用率(百分比)
InodeUsagePct float64 `json:"inode_usage_pct"` // inode 使用率(百分比)— 防止文件数爆炸
}
// PortStat 监听端口及其归属进程
+41 -16
View File
@@ -9,6 +9,8 @@ type NetworkStat struct {
NicName string `json:"nic_name"` // 主网卡名
NetRxBPS float64 `json:"net_rx_bps"` // 网卡接收速率 (bytes/s)
NetTxBPS float64 `json:"net_tx_bps"` // 网卡发送速率 (bytes/s)
NetRxErrors int64 `json:"net_rx_errors"` // 网卡接收错误包累计 — 物理层故障告警
NetTxErrors int64 `json:"net_tx_errors"` // 网卡发送错误包累计 — 物理层故障告警
}
// DiskIOStat 磁盘 IO 相关指标
@@ -17,6 +19,7 @@ type DiskIOStat struct {
WriteBPS float64 `json:"write_bps"` // 写入速率 (bytes/s)
ReadIOPS float64 `json:"read_iops"` // 读取 IOPS (count/s)
WriteIOPS float64 `json:"write_iops"` // 写入 IOPS (count/s)
Util float64 `json:"util"` // 磁盘繁忙程度(百分比)— 判断磁盘是否瓶颈的核心指标
}
// SwapStat 交换分区指标(OOM 前兆判断)
@@ -28,34 +31,34 @@ type SwapStat struct {
// SocketFDStat 系统级 FD 使用情况
type SocketFDStat struct {
Allocated int `json:"allocated"` // 已分配的 file handles (fs.file-nr 第一列)
Max int64 `json:"max"` // 系统上限 (fs.file-max)
Allocated int `json:"allocated"` // 已分配的 file handles (fs.file-nr 第一列)
Max int64 `json:"max"` // 系统上限 (fs.file-max)
UsagePct float64 `json:"usage_pct"`
}
// ContextSwitchStat 上下文切换(决定是否开中断合并/CPU 隔离)
type ContextSwitchStat struct {
CTXPerSec float64 `json:"ctx_per_sec"` // 每秒上下文切换次数
IRQPerSec float64 `json:"irq_per_sec"` // 每秒中断次数
CTXPerSec float64 `json:"ctx_per_sec"` // 每秒上下文切换次数
IRQPerSec float64 `json:"irq_per_sec"` // 每秒中断次数
}
// AgentHeartbeat Agent 自检心跳(随每次上报附带,极小 payload)
type AgentHeartbeat struct {
Version string `json:"version"`
UptimeSec int64 `json:"uptime_sec"`
LastErr string `json:"last_err,omitempty"`
SelfCPU float64 `json:"self_cpu_pct"`
SelfRSSMB float64 `json:"self_rss_mb"`
ReportSeq uint64 `json:"report_seq"` // 单调递增序列号,用于丢包检测
Version string `json:"version"`
UptimeSec int64 `json:"uptime_sec"`
LastErr string `json:"last_err,omitempty"`
SelfCPU float64 `json:"self_cpu_pct"`
SelfRSSMB float64 `json:"self_rss_mb"`
ReportSeq uint64 `json:"report_seq"` // 单调递增序列号,用于丢包检测
}
// SystemStat 系统信息(启动时采集一次)
type SystemStat struct {
OSVersion string `json:"os_version"` // OS 版本 (如 "Ubuntu 22.04")
Kernel string `json:"kernel"` // 内核版本
Uptime int64 `json:"uptime"` // 运行秒数
UlimitNofile int64 `json:"ulimit_nofile"` // ulimit -n (最大文件描述符)
UlimitNproc int64 `json:"ulimit_nproc"` // ulimit -u (最大进程数)
OSVersion string `json:"os_version"` // OS 版本 (如 "Ubuntu 22.04")
Kernel string `json:"kernel"` // 内核版本
Uptime int64 `json:"uptime"` // 运行秒数
UlimitNofile int64 `json:"ulimit_nofile"` // ulimit -n (最大文件描述符)
UlimitNproc int64 `json:"ulimit_nproc"` // ulimit -u (最大进程数)
}
// ──── v2.1 健康探针 ────
@@ -80,8 +83,30 @@ type ProbeResult struct {
ProbeID uint `json:"probe_id"`
Name string `json:"name"`
ProbeType string `json:"probe_type"`
Status string `json:"status"` // up / down
Status string `json:"status"` // up / down
LatencyMs int `json:"latency_ms"`
StatusCode int `json:"status_code,omitempty"`
Message string `json:"message,omitempty"`
}
// PortPolicy 后端下发的端口过滤策略 // Logan.Li
type PortPolicy struct {
Hostname string `json:"hostname"`
PortFilterMode string `json:"port_filter_mode"` // whitelist / blacklist
PortWhitelist []int `json:"port_whitelist"` // 端口号数组
}
// IsBlacklistMode 判断是否为黑名单模式(只上报选中端口)
func (p *PortPolicy) IsBlacklistMode() bool {
return p.PortFilterMode == "blacklist"
}
// InWhitelist 检查端口是否在白名单中
func (p *PortPolicy) InWhitelist(port int) bool {
for _, w := range p.PortWhitelist {
if w == port {
return true
}
}
return false
}