mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-02 18:16:53 +09:00
The binder re-checks what admission checked, and cozystack-api shows the remaining budget a later order is checked against; computing these in three places would let them disagree. The model is pure, so each caller builds a snapshot from its own cache. GPU budgets cap the whole subtree of the tenant that declares them, walked over the namespace ancestry and independent of the tenant quota pools. A raw GPU key blocks a class until the same tenant also declares a GPU key, and then caps devices and raw-name pods together. Pod usage follows the scheduler's arithmetic, sidecars included, so the binder never books a unit a raw-name pod holds. A node takes binds only when it is schedulable, Ready and carries no NoSchedule or NoExecute taint the pod does not tolerate; the unschedulable, not-ready and unreachable taints are left to the first two checks, and a taint never counts as a cordon. Gt and Lt tolerations do not count, since the scheduler ignores them where their feature gate is off. Template device names are derived from the VMI and shortened with a hash when the VMI name leaves no room, so they stay valid subdomains. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <f@lex.la>
41 lines
1.5 KiB
Go
41 lines
1.5 KiB
Go
/*
|
|
Copyright 2026 The Cozystack Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
// Package model is the GPU logic shared by the binder, the admission
|
|
// webhooks and cozystack-api: the phase table, quota keys, the tenant
|
|
// ancestor walk, budgets, entitlement, capacity and node eligibility. It
|
|
// holds no client; callers build a Snapshot from their own caches.
|
|
package model
|
|
|
|
import gpuv1alpha1 "github.com/cozystack/cozystack/api/gpu/v1alpha1"
|
|
|
|
// HoldsGPUs reports whether a device in phase p holds units on a node.
|
|
func HoldsGPUs(p gpuv1alpha1.GPUDevicePhase) bool {
|
|
return p == gpuv1alpha1.GPUDeviceBound || p == gpuv1alpha1.GPUDeviceAttached
|
|
}
|
|
|
|
// CountsAgainstBudget reports whether a device in phase p counts against
|
|
// GPU budgets. A Lost device counts so that its rebind never fails a
|
|
// budget check.
|
|
func CountsAgainstBudget(p gpuv1alpha1.GPUDevicePhase) bool {
|
|
return HoldsGPUs(p) || p == gpuv1alpha1.GPUDeviceLost
|
|
}
|
|
|
|
// InUsageRecords reports whether a device in phase p has a usage record.
|
|
func InUsageRecords(p gpuv1alpha1.GPUDevicePhase) bool {
|
|
return HoldsGPUs(p)
|
|
}
|