Commit Graph
10 Commits
Author SHA1 Message Date
Aleksei Sviridkin 1485122e04 test(reservation): drop the shipped-declaration test
The test read packages/system/*-rd/cozyrds/*.yaml as raw files and
required one document and one metadata.name per file, a layout rule
no requirement asks for: an -rd chart may keep one definition per
variant under the same name and render one of them, and such a chart
failed every shipped test with "ApplicationDefinition ... is declared
in both". It also parsed cozy-lib's preset template with a regexp
pinned to 47 rows, pinned some seventy figures the shipped
declarations compute, and required the IaaS kinds to declare their
consumption while nothing reads the declarations yet.

Compiling and evaluating the shipped declarations is now checked on
the rendered charts, and the evaluator's own properties on fixtures.
Whether a declaration matches what its chart requests is a question
for a check against the rendered application, not for literals.

Fixes: 9a2830badf ("feat(api, kubernetes, virtual-machine): declare the IaaS kinds' reservation")
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-11-24 11:49:42 +03:00
Aleksei Sviridkin 62ab75b002 test(reservation): exercise the evaluator on fixtures, not chart sources
The evaluator and classifier tests read the kinds' schemas from
packages/system/<kind>-rd/cozyrds/<kind>.yaml and the instance type
catalog from the kubevirt-instancetypes templates. That ties unit
tests of CEL semantics, quantity arithmetic and classification to how
the charts lay out their sources, so a chart change unrelated to the
evaluator could fail them.

Give them schemas cut down to the keys the declarations read and
instance types in the shapes the classifier has to tell apart. The
expected figures are unchanged. The exact product past int64, pinned
until now only through the shipped vm-instance declaration, gets a
case of its own. The shipped-catalog reader moves next to its last
user, the shipped-declaration test.

Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-11-24 11:49:40 +03:00
Mattia Eleuteri 9a2830badf feat(api, kubernetes, virtual-machine): declare the IaaS kinds' reservation
VMs, disks, Kubernetes control planes and worker pools are where the
virtualization overhead that breaks pod-unit quota accounting lives,
so they are the first kinds to state their reservation in the terms a
tenant buys: guest cores and memory by instance-type class, declared
disk sizes, and the load balancers a spec publishes.

Each declaration follows its chart's own precedence rather than one
rule for all: a VM is sized by resources only when cpu, sockets and
memory are all set, a worker pool when cpu and memory are non-zero,
and a control-plane component fills its preset per key. A worker pool
reserves maxReplicas because the cluster-autoscaler grows it without
writing the pool, and reserves nothing on Proxmox, whose workers run
on the external hypervisor. GPUs are not declared: their quota key is
the device name, which a fixed key cannot express.

The test evaluates the shipped declarations against the shipped
instance types and preset table, including the failures that must
stay errors rather than smaller figures.

Assisted-by: LLM
Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
2026-11-23 08:03:52 +01:00
Mattia Eleuteri fa7c94507a feat(api): carry a consumption declaration on ApplicationDefinition
Tenant quotas are to be enforced against what an application declares
rather than against the pods it renders, and the apiserver must hold no
per-kind knowledge of how to compute that, so that a kind shipped from
an out-of-tree catalog can take part. The declaration therefore lives
on the kind's definition, next to the schema it is evaluated against.

The evaluator's Declaration becomes an alias of the API type, so a
definition is compiled exactly as it was read, with no conversion that
could drift from it. The CRD refuses an exempt declaration that still
carries expressions and a non-exempt one that names no resource, so an
omission cannot pass for a zero reservation.

Nothing reads the field yet.

Assisted-by: LLM
Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
2026-11-23 08:03:50 +01:00
Mattia Eleuteri a069636a4e fix(api): read a null value as absent in a reservation declaration
Helm deletes a key its values set to null, so a chart treats
`resources: {cpu: null}` as if cpu were not set. The evaluator's
defaulting replaced a null only where the schema had a default to put
in its place, so elsewhere the key stayed present: has() reported it,
and an expression reading it failed, for instance with "no such
overload: matches", on a spec the chart renders.

Nulls are dropped after defaulting, so a schema default still fills a
nulled key the way it fills an absent one.

Tested with a nulled key that has no default.

Fixes: 89aba6e104 ("feat(api): add the reservation evaluator for tenant quotas")
Assisted-by: LLM
Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
2026-11-23 08:03:49 +01:00
Mattia Eleuteri 6f705fe0e9 fix(api): keep exact quantity products the int64 coefficient cannot hold
resource.Quantity.Mul returns false when the product no longer fits an
int64 coefficient, not when it is wrong: it carries on in arbitrary
precision. The evaluator read that as an overflow and failed with
"quantity 20992Mi * 3 overflows" for any fractional binary quantity
above about 8.5Gi, since such a quantity is stored at a scale whose
coefficient leaves int64 long before its value does. Declared sizes
like 20.5Gi are ordinary, so every pool or disk using one could not be
reserved.

Tested with fractional Gi and Ti quantities scaled directly and after a
sum.

Fixes: 89aba6e104 ("feat(api): add the reservation evaluator for tenant quotas")
Assisted-by: LLM
Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
2026-11-18 15:58:55 +01:00
Mattia Eleuteri a9245ec165 fix(api): accept the quantities the CEL add and sub return
The Kubernetes CEL quantity library returns a pointer from add and sub,
while quantity() and the evaluator's own mul return a value. The
evaluator matched only the value form, so any declaration that summed
quantities failed with "expression returned kubernetes.Quantity,
expected an int, a double, a string or a quantity", or with "no such
overload" when the sum was then scaled with mul. A kind whose
reservation is a sum of components, such as a control plane, could not
be declared at all.

Both forms are matched by type rather than read through Value(), which
would first materialize any other result, a list included, outside the
expression's cost limit.

Tested with add, sub, add of an int, and mul on either side of a sum.

Fixes: 89aba6e104 ("feat(api): add the reservation evaluator for tenant quotas")
Assisted-by: LLM
Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
2026-11-18 15:58:54 +01:00
Aleksei Sviridkin 87b794a992 chore: handle errors dropped in cleanup paths and tests
The drain tests now assert that RunThenDrain returns the run's nil
error, the idle-tail test fails on any error other than the stream
ending or being cut, and a test fixture file fails the test when it
cannot be closed.

Removing a temporary directory and closing a response body that has
been read are best-effort: a failure leaves nothing for the caller to
act on and does not change any result, so those errors are discarded
explicitly. The same holds for the stub servers' response writes, whose
failure surfaces on the client side of the test.

Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-11-13 12:35:01 +03:00
Aleksei Sviridkin 4c3a4b42cc style: clear unused code and style findings reported by staticcheck
Remove helpers and constants nothing references, escape format
characters in test literals, and take the simplifications staticcheck
suggests where they read the same. Error strings no longer start with a
capital: they keep their meaning, with the kind or component name moved
out of first position. Callers match errors by type, not text; the one
test that matches text, for Kafka, keeps the phrase it looks for.

Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-11-13 11:37:41 +03:00
Mattia Eleuteri 89aba6e104 feat(api): add the reservation evaluator for tenant quotas
Tenant quotas are declared in instance-type units but enforced against
ResourceQuota.status.used, which counts virt-launcher pods with their
additive virtualization overhead and drifts without recomputation. The
accepted tenant-quota-reservation design makes the declared reservation
the accounting authority instead; this is its first phase, the
evaluator, with no consumer yet.

A kind describes its consumption as CEL over its values, so the
evaluator carries no per-kind knowledge and an out-of-tree kind
participates without a change here. Instance types resolve to scalars
keyed by class, read from the type's spec rather than its name, because
a pinned core, a hugepage and an overcommitted page are not the same
capacity as a shared vCPU or ordinary memory. KubeVirt pins the
emulator thread's parity core per type, from the annotations the type
hands to its VMs, so the classifier reads it there too. Anything that
does not resolve is an error, never a smaller figure.

Stored values carry only the keys a tenant wrote, so the evaluator
defaults them first. The defaulting code moves out of the application
registry into its own package so both read the same defaults. Defaulting
replaces a value of the wrong type with the schema's default, which
would turn a malformed spec into a smaller reservation, so values are
type-checked against the schema before it runs.

Assisted-by: LLM
Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
2026-11-09 11:35:53 +01:00