Add new frontend pages for the multi-tenant OCDP platform: - Charts page (/charts): Browse Harbor OCI registries to list Helm chart repositories and versions, with deploy modal to launch charts on selected clusters - Monitoring page (/monitoring): Display cluster metrics (CPU/Memory/GPU usage) and per-node details with resource utilization bars - Chart References page (/chart-references): CRUD for chart metadata references - Values Templates page (/templates): CRUD for Helm values templates with version history and rollback support - Sidebar: Add Charts navigation, update Storage and Templates links - api.ts: Add all API client functions (clusterApi, registryApi, instanceApi, monitoringApi, storageApi, chartReferenceApi, valuesTemplateApi, workspaceApi, userApi) with full TypeScript types Note: deploy flow and values template rollback not yet end-to-end tested.
79 lines
1.7 KiB
Go
79 lines
1.7 KiB
Go
package entity
|
||
|
||
import (
|
||
"time"
|
||
)
|
||
|
||
// ResourceType 资源类型
|
||
type ResourceType string
|
||
|
||
const (
|
||
ResourceCPU ResourceType = "cpu"
|
||
ResourceGPU ResourceType = "gpu"
|
||
ResourceGPUMemory ResourceType = "gpu_memory"
|
||
)
|
||
|
||
// WorkspaceQuota 工作空间配额实体
|
||
type WorkspaceQuota struct {
|
||
ID string
|
||
WorkspaceID string
|
||
ResourceType ResourceType
|
||
HardLimit float64 // 硬限制(0表示无限制)
|
||
SoftLimit float64 // 软限制(警告阈值)
|
||
Used float64 // 当前使用量
|
||
CreatedAt time.Time
|
||
UpdatedAt time.Time
|
||
}
|
||
|
||
// NewWorkspaceQuota 创建新配额
|
||
func NewWorkspaceQuota(workspaceID string, resourceType ResourceType, hardLimit, softLimit float64) *WorkspaceQuota {
|
||
now := time.Now()
|
||
return &WorkspaceQuota{
|
||
WorkspaceID: workspaceID,
|
||
ResourceType: resourceType,
|
||
HardLimit: hardLimit,
|
||
SoftLimit: softLimit,
|
||
Used: 0,
|
||
CreatedAt: now,
|
||
UpdatedAt: now,
|
||
}
|
||
}
|
||
|
||
// CanAllocate 检查是否可以分配指定资源量
|
||
func (q *WorkspaceQuota) CanAllocate(amount float64) bool {
|
||
if q.HardLimit == 0 {
|
||
return true // 无限制
|
||
}
|
||
return q.Used+amount <= q.HardLimit
|
||
}
|
||
|
||
// Allocate 分配资源
|
||
func (q *WorkspaceQuota) Allocate(amount float64) {
|
||
q.Used += amount
|
||
q.UpdatedAt = time.Now()
|
||
}
|
||
|
||
// Release 释放资源
|
||
func (q *WorkspaceQuota) Release(amount float64) {
|
||
q.Used -= amount
|
||
if q.Used < 0 {
|
||
q.Used = 0
|
||
}
|
||
q.UpdatedAt = time.Now()
|
||
}
|
||
|
||
// IsOverLimit 检查是否超过硬限制
|
||
func (q *WorkspaceQuota) IsOverLimit() bool {
|
||
if q.HardLimit == 0 {
|
||
return false
|
||
}
|
||
return q.Used > q.HardLimit
|
||
}
|
||
|
||
// IsOverSoftLimit 检查是否超过软限制
|
||
func (q *WorkspaceQuota) IsOverSoftLimit() bool {
|
||
if q.SoftLimit == 0 {
|
||
return false
|
||
}
|
||
return q.Used > q.SoftLimit
|
||
} |