Documentation
¶
Overview ¶
Package util holds small, dependency-free helpers shared across Nebula's control plane and provider adapters.
Index ¶
- Constants
- func AcceleratorPool(accelerator string, count int32) string
- func AcceleratorRequest(pod *corev1.Pod) (accelerator string, count int32, err error)
- func ClaimName(namespace, name string) string
- func PodReservation(pod *corev1.Pod) (cpuCores float64, memoryMiB int)
- func SplitAcceleratorPool(pool string) (accelerator string, count int32)
- func SplitEgressTargets(entries []string) (cidrs, domains []string)
Constants ¶
const NvidiaGPUResource corev1.ResourceName = "nvidia.com/gpu"
NvidiaGPUResource is the extended-resource key a GPU count is expressed under. It mirrors the ecosystem-standard nvidia.com/gpu so a Pod's accelerator count drives both the scheduler's fit check (against the virtual node's advertised capacity) and provisioning from a single number.
Variables ¶
This section is empty.
Functions ¶
func AcceleratorPool ¶
AcceleratorPool is the canonical identity of the accelerator POOL a request targets: the type and count joined as "type:count" (e.g. "H100:8"). It is the key the failover blocklist records/queries and the value the NodeClaim reports, chosen over the provider's resolved SKU id because a single launch may span several interchangeable instance types (AWS's fleet) — the pool identity stays truthful whichever alternate lands, and it keeps distinct (type, count) pairs on distinct keys so an H100:8 shortage never disqualifies H100:1. Returns "" for a CPU-only request (empty type), which has no accelerator pool.
func AcceleratorRequest ¶
AcceleratorRequest reads a Pod's accelerator request: the TYPE from the AcceleratorTypeLabel and the COUNT from the container's nvidia.com/gpu resource. This is the single source of truth for the request grammar, shared by the placement controller and the provider adapters.
It returns:
- ("", 0, nil) no GPU type requested => a CPU-only workload.
- (type, count, nil) a GPU workload; count defaults to 1 when the type is set but no nvidia.com/gpu resource is present, so authors can request a single GPU with just the label.
The type is returned verbatim (case is normalized downstream by the provider catalog's MapAccelerator). An error is returned only for a genuinely contradictory request: an explicit nvidia.com/gpu count with no GPU type.
func ClaimName ¶
ClaimName is the instance-identity token Nebula encodes into a provider instance's name/tag so List/Terminate can find it later without a durable id. It is a PURE function of the workload's namespace and name, so whoever knows the Pod (the virtual kubelet) or the claim's PodRef (the teardown backstop) derives the same token. Keep this the single source of truth — both depend on producing identical values.
Normally a plain "namespace-name" join, kept verbatim: it is the historical format (already-tagged instances keep matching) and it is readable in kubectl output.
A NodeClaim name is a DNS subdomain, capped at maxClaimNameLen, and a long namespace plus long Pod name can exceed it — then the join is un-creatable and the Pod is never placed. Only in that case do we truncate and append a hash of the canonical "namespace/name" key. "/" is illegal in both, so the hashed input is unambiguous and two pairs that truncate to the same prefix still differ.
func PodReservation ¶
PodReservation reads the workload's CPU and memory RESERVATION in the units provider.PriceRequest quotes: fractional physical cores and MiB. Requests, falling back to limits, and 0 for either when neither is set — which a provider reads as "your default", so a priced 0 is a floor, not a claim that nothing was reserved.
Reservation and not the limit, because a provider metering CPU/memory apart from the accelerator (Modal) bills what was held for the workload; a burstable Pod's ceiling is not what shows up on the invoice.
The FIRST container only, matching the single-workload-container shape the whole provisioning path assumes (see modal.sandboxSpecFromPod). Returns (0, 0) for a Pod with no containers.
func SplitAcceleratorPool ¶
SplitAcceleratorPool is the inverse of AcceleratorPool: it recovers the type and count from a "type:count" pool identity. For readers that hold only the joined form — NodeClaimSpec.Accelerator — and need the two apart, as metrics labels do so both "every H100 size" and "every 8-GPU request" stay aggregatable.
("", 0) for an empty pool (a CPU-only claim) and for anything not in the grammar, so a hand-edited claim degrades to "no accelerator" rather than minting a garbage label value.
func SplitEgressTargets ¶
SplitEgressTargets sorts an EgressPolicy.Targets list into prefixes and domain names. Which kind an entry is can be decided by parsing, so a pool declares one list (users think "let it reach S3 and huggingface", not "which field is this") and adapters that take the two separately split here rather than each rolling its own.
Types ¶
This section is empty.