将 Worker 发现、路由画像、容量与执行传输抽象为平台无关接口,新增 Kubernetes 和静态容量适配器,并以 shadow 模式接入生产配置。 实现网络与容量评分、路由防抖、池队列、同步 Worker 租约、一次性执行令牌,以及提交状态不明时禁止重复分配的安全语义。 新增 0105 兼容迁移、管理接口、指标、OpenAPI 和回归测试。已执行全量 Go 测试、go vet、OpenAPI、迁移安全、Compose 与 Kustomize 验证。
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package capacitycontroller
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
)
|
|
|
|
// StaticAdapter proves that capacity coordination does not require Kubernetes.
|
|
// It reports configured fixed replicas and intentionally ignores scale writes.
|
|
type StaticAdapter struct {
|
|
mu sync.RWMutex
|
|
replicas map[string]int
|
|
}
|
|
|
|
var _ OrchestratorAdapter = (*StaticAdapter)(nil)
|
|
|
|
func NewStaticAdapter(initial map[string]int) *StaticAdapter {
|
|
copyOfInitial := make(map[string]int, len(initial))
|
|
for poolID, replicas := range initial {
|
|
copyOfInitial[poolID] = replicas
|
|
}
|
|
return &StaticAdapter{replicas: copyOfInitial}
|
|
}
|
|
|
|
func (adapter *StaticAdapter) PoolState(_ context.Context, poolID, _ string) (PoolInfrastructureState, error) {
|
|
adapter.mu.RLock()
|
|
replicas := adapter.replicas[poolID]
|
|
adapter.mu.RUnlock()
|
|
return PoolInfrastructureState{
|
|
PoolID: poolID, CurrentReplicas: replicas,
|
|
AllocatableMemoryBytes: 1 << 60, WorkerRequestMemoryBytes: 1,
|
|
AllocatableMilliCPU: 1 << 50, WorkerRequestMilliCPU: 1,
|
|
}, nil
|
|
}
|
|
|
|
func (adapter *StaticAdapter) ScalePool(context.Context, string, string, int) error {
|
|
return nil
|
|
}
|
|
|
|
func (adapter *StaticAdapter) SetInstanceTerminationPriority(context.Context, string, int) error {
|
|
return nil
|
|
}
|