Files
ilker 142ebfbf1f hpcod: an application catalogue, so a request can name software not hardware
A container registry stores bytes. Nothing in an OCI manifest says that a
particular GROMACS build needs a GPU, how large it is, what module name it
exposes, or whether anyone signed it. That is what this catalogue carries,
and it is why a registry alone was not enough.

The effect is that a request can name what someone actually wants. A request
for "gromacs" states no hardware at all; the catalogue resolves it to the
newest published build, which declares a GPU requirement, and placement is
handed that requirement as if it had been written down. Verified through the
endpoint, not only in unit tests: posting a request whose only content is
`apps: [gromacs]` comes back with the resolved image and a derived GPU
constraint. Someone who wants the software should not have to know the
hardware it implies, and if they forget, they should not be placed on a site
that cannot run it.

Expansion happens before placement, not inside it. Placement matches
constraints against hardware; which build of which application wants a GPU is
catalogue knowledge, and mixing the two would mean placement's tests had to
carry an application list to say anything about scheduling. It also leaves
the caller's request untouched, so examining a request twice does not grow
its constraints.

A YAML file rather than a service, deliberately, for the same reason
sites.yaml is one: it is read, not written, and only the platform team
publishes to it. It becomes a service the day someone else needs to write to
it. A missing file is an empty catalogue rather than an error - publishing no
applications is a legitimate configuration and the control plane still has to
start - but an entry without an image is rejected at load, because the
alternative is finding out when a tenant tries to pull it.

An unknown application is an error, not a warning. Provisioning a fourteen-
day cluster and only then discovering that the software someone came for was
never published is the wrong order to find out.

Version resolution prefers the newest, so "openfoam" means the latest
published OpenFOAM rather than whichever happens to be first in the file.

Not yet built: the provisioning half that pulls the resolved images onto a
tenant's /opt. size_gb is in the schema for the decision it will drive -
whether an image is small enough to pull while provisioning, or large enough
that it belongs in the template or in a fetch after the cluster is already
usable, rather than back on the critical path.
2026-09-20 19:24:59 +02:00

153 lines
4.0 KiB
Go

package catalog
import (
"os"
"path/filepath"
"testing"
"github.com/ilkermanap/hpcod/internal/model"
"github.com/ilkermanap/hpcod/internal/spec"
)
const sample = `
apps:
- name: openfoam
version: "11"
image: oras://gitea.example/hpcapps/openfoam:11
size_gb: 1.8
signed: true
- name: openfoam
version: "12"
image: oras://gitea.example/hpcapps/openfoam:12
size_gb: 2.1
signed: true
- name: gromacs-gpu
version: "2024"
image: oras://gitea.example/hpcapps/gromacs-gpu:2024
requires: [gpu]
size_gb: 3.4
signed: false
`
func load(t *testing.T, body string) *Catalog {
t.Helper()
p := filepath.Join(t.TempDir(), "apps.yaml")
if err := os.WriteFile(p, []byte(body), 0o600); err != nil {
t.Fatal(err)
}
c, err := Load(p)
if err != nil {
t.Fatal(err)
}
return c
}
func TestMissingCatalogIsEmptyNotAnError(t *testing.T) {
// A site that publishes nothing is a legitimate configuration, and the
// control plane has to start anyway.
c, err := Load(filepath.Join(t.TempDir(), "absent.yaml"))
if err != nil {
t.Fatalf("missing catalog should not be an error: %v", err)
}
if len(c.Apps) != 0 {
t.Fatalf("expected no apps, got %d", len(c.Apps))
}
}
func TestLookupPrefersTheNewestWhenNoVersionIsGiven(t *testing.T) {
c := load(t, sample)
a, ok := c.Lookup("openfoam")
if !ok || a.Version != "12" {
t.Fatalf(`Lookup("openfoam") = %q, %v; want the newest, 12`, a.Version, ok)
}
a, ok = c.Lookup("openfoam:11")
if !ok || a.Version != "11" {
t.Fatalf(`Lookup("openfoam:11") = %q, %v; want 11`, a.Version, ok)
}
if _, ok := c.Lookup("openfoam:99"); ok {
t.Fatal("a version that was never published must not resolve")
}
}
func TestUnknownApplicationFailsBeforeAnythingIsProvisioned(t *testing.T) {
c := load(t, sample)
if _, _, err := c.Resolve([]string{"openfoam", "nastran"}); err == nil {
t.Fatal("an unpublished application must be an error, not a warning")
}
}
func TestExpandDerivesHardwareFromTheApplication(t *testing.T) {
c := load(t, sample)
req := spec.Request{
Compute: spec.ComputeSpec{Count: 4},
Stack: spec.StackSpec{Apps: []string{"gromacs-gpu"}},
}
out, apps, err := c.Expand(req)
if err != nil {
t.Fatal(err)
}
if len(apps) != 1 || apps[0].Name != "gromacs-gpu" {
t.Fatalf("resolved %v, want gromacs-gpu", apps)
}
// The user asked for an application, not for hardware. Placement has to
// see the GPU requirement anyway.
if len(out.Compute.Require) != 1 || out.Compute.Require[0].Capability != model.CapGPU {
t.Fatalf("constraints = %v, want a GPU requirement derived from the app", out.Compute.Require)
}
// And the caller's request must not have grown behind its back.
if len(req.Compute.Require) != 0 {
t.Fatalf("Expand mutated its input: %v", req.Compute.Require)
}
}
func TestExpandDoesNotOverrideAnExplicitCount(t *testing.T) {
c := load(t, sample)
req := spec.Request{
Compute: spec.ComputeSpec{
Count: 4,
Require: []spec.Constraint{{Capability: model.CapGPU, Count: 4}},
},
Stack: spec.StackSpec{Apps: []string{"gromacs-gpu"}},
}
out, _, err := c.Expand(req)
if err != nil {
t.Fatal(err)
}
if len(out.Compute.Require) != 1 || out.Compute.Require[0].Count != 4 {
t.Fatalf("constraints = %v; an app needing one GPU must not reduce an explicit four",
out.Compute.Require)
}
}
func TestAnAppWithoutHardwareNeedsAddsNoConstraints(t *testing.T) {
c := load(t, sample)
req := spec.Request{
Compute: spec.ComputeSpec{Count: 2},
Stack: spec.StackSpec{Apps: []string{"openfoam:12"}},
}
out, _, err := c.Expand(req)
if err != nil {
t.Fatal(err)
}
if len(out.Compute.Require) != 0 {
t.Fatalf("constraints = %v, want none: OpenFOAM asks for no special hardware",
out.Compute.Require)
}
}
func TestAnEntryWithoutAnImageIsRejected(t *testing.T) {
p := filepath.Join(t.TempDir(), "apps.yaml")
if err := os.WriteFile(p, []byte("apps:\n - name: broken\n"), 0o600); err != nil {
t.Fatal(err)
}
if _, err := Load(p); err == nil {
t.Fatal("an entry with no image must be rejected at load, not at pull time")
}
}