Publishing worked; everything after it did not. Four things were wrong and each was silent in its own way. Versions were compared as text, so asking for "gromacs" with 2024.9 and 2024.10 published returned 2024.9. The whole meaning of an unversioned reference is "the newest one", and it was a wrong answer rather than a missing one - invisible until somebody noticed they had spent a week on last year's build. A recipe could hold one version while the catalogue could hold many, so an update either destroyed what it replaced or grew a parallel directory sharing nothing with the first. Recipes now carry a list, and the single-version form is read into the same shape, so nothing downstream knows which was written. An image was named by a mutable tag. Whoever repushes gromacs:2024.4 changed what every rebuilt cluster received, silently, and the record meant to freeze the cluster froze only its opinion of it. Two hashes are now recorded because they are checkable in different places: the manifest digest answers "has this moved" from the control plane, and the SIF hash is the only one a head can check with no network and no credential - which matters, because the head is where a wrong image does harm. Pulling by digest is deliberately not done: whether this Apptainer accepts an @sha256: reference is not established, and a provision failing at its last task over untested syntax would be worse than the problem. Module and binaries had been in the catalogue since it was written and were read by nothing - Module was referenced nowhere in the program. So a tenant was handed /opt/apps/gromacs.sif and left to work out Apptainer. They now become a wrapper per binary and an Lmod modulefile, and the answer is `module load gromacs`. Whether to pass --nv is decided on the node at run time: passing it without a driver fails outright, and omitting it where there is one leaves the job on the CPU saying nothing at all, which is the dangerous one. Four states replace `published:`. A withdrawn entry stays in the catalogue file, because dropping it would make it indistinguishable from one that never existed - and that difference is what an operator needs when a cluster is found still holding it. A pinned reference to one is refused with the recorded reason instead of "no application", which would send the user hunting for a typo in a correct name. The portal re-reads the catalogue when it changes, so publishing an application no longer needs a restart - the step that is invisible when forgotten. C20 ships the catalogue, which nothing did. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
258 lines
7.9 KiB
Go
258 lines
7.9 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"sort"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
"github.com/ilkermanap/hpcod/internal/catalog"
|
|
"github.com/ilkermanap/hpcod/internal/model"
|
|
"github.com/ilkermanap/hpcod/internal/spec"
|
|
)
|
|
|
|
// The New cluster page used to be a textarea holding YAML.
|
|
//
|
|
// It asked someone who wants four machines with a GPU to know the shape of
|
|
// a document: which keys nest under which, that memory is stated per node
|
|
// and in gibibytes, that a capability is spelled "gpu" and not "GPU", and
|
|
// that "prefer" exists at all. Every one of those is a thing the page
|
|
// already knows and the person does not, and getting any of them wrong
|
|
// produced a parse error rather than a cluster.
|
|
//
|
|
// The request is the same structure either way; only the authoring changed.
|
|
// The command line and the JSON API still take the document, which is the
|
|
// right shape for something being generated by a script rather than typed.
|
|
|
|
// capabilityField is one hardware row on the form.
|
|
type capabilityField struct {
|
|
Cap model.Capability
|
|
Label string
|
|
Help string
|
|
// AsksVendor and AsksSpeed say which detail the row offers. A minimum
|
|
// link speed on a GPU, or a vendor on an NVMe drive, is a question
|
|
// with no useful answer.
|
|
//
|
|
// Named apart from the values the row carries: the embedded field
|
|
// wins in a template, so a bool called Speed beside a string called
|
|
// Speed silently rendered neither - the flag was shadowed by an empty
|
|
// string, and the input for it never appeared on the page.
|
|
AsksVendor bool
|
|
AsksSpeed bool
|
|
}
|
|
|
|
func capabilityFields() []capabilityField {
|
|
return []capabilityField{
|
|
{Cap: model.CapGPU, Label: "GPU", Help: "Whole devices, passed through", AsksVendor: true},
|
|
{Cap: model.CapInfiniBand, Label: "InfiniBand", Help: "For multi-node MPI", AsksSpeed: true},
|
|
{Cap: model.CapRoCE, Label: "RoCE", Help: "RDMA over Ethernet", AsksSpeed: true},
|
|
{Cap: model.CapNVMe, Label: "NVMe", Help: "Local fast scratch"},
|
|
}
|
|
}
|
|
|
|
// planForm is what the page rendered and what came back, in one place.
|
|
//
|
|
// Keeping the raw strings alongside the parsed request is what lets a
|
|
// rejected form come back with the numbers still in it. Re-rendering
|
|
// defaults after someone has filled eleven fields is its own kind of
|
|
// refusal.
|
|
type planForm struct {
|
|
values map[string]string
|
|
}
|
|
|
|
func (f planForm) str(k string) string { return strings.TrimSpace(f.values[k]) }
|
|
|
|
func (f planForm) num(k string) int {
|
|
n, err := strconv.Atoi(f.str(k))
|
|
if err != nil || n < 0 {
|
|
return 0
|
|
}
|
|
return n
|
|
}
|
|
|
|
// defaultPlanForm is a request someone could plausibly want, so the page
|
|
// is useful before anything is typed and the fields show what belongs in
|
|
// them.
|
|
func defaultPlanForm() planForm {
|
|
return planForm{values: map[string]string{
|
|
"name": "",
|
|
"lease": "14d",
|
|
"head_cores": "4",
|
|
"head_memory": "16",
|
|
"head_disk": "120",
|
|
"compute_count": "2",
|
|
"compute_cores": "8",
|
|
"compute_memory": "32",
|
|
}}
|
|
}
|
|
|
|
// formFromRequest reads the submitted fields, keeping every value as typed.
|
|
func formFromRequest(r *http.Request) planForm {
|
|
f := planForm{values: map[string]string{}}
|
|
for k, v := range r.PostForm {
|
|
if len(v) > 0 {
|
|
f.values[k] = v[0]
|
|
}
|
|
}
|
|
// Checkbox groups arrive as several values under one name.
|
|
f.values["apps"] = strings.Join(r.PostForm["apps"], ",")
|
|
return f
|
|
}
|
|
|
|
// request turns the form into the same structure the API and the command
|
|
// line take. Validation is left to spec.Request, so a field typed into the
|
|
// page is refused for exactly the reason it would be in a document.
|
|
func (f planForm) request() (spec.Request, error) {
|
|
req := spec.Request{
|
|
Name: f.str("name"),
|
|
Tenant: f.str("tenant"),
|
|
Lease: f.str("lease"),
|
|
Head: spec.NodeSpec{
|
|
Cores: f.num("head_cores"),
|
|
MemoryGB: f.num("head_memory"),
|
|
DiskGB: f.num("head_disk"),
|
|
},
|
|
Compute: spec.ComputeSpec{
|
|
Count: f.num("compute_count"),
|
|
Cores: f.num("compute_cores"),
|
|
MemoryGB: f.num("compute_memory"),
|
|
},
|
|
}
|
|
|
|
for _, c := range capabilityFields() {
|
|
n := f.num(string(c.Cap) + "_count")
|
|
if n == 0 {
|
|
continue
|
|
}
|
|
con := spec.Constraint{Capability: c.Cap, Count: n}
|
|
if c.AsksVendor {
|
|
con.Vendor = f.str(string(c.Cap) + "_vendor")
|
|
}
|
|
if c.AsksSpeed {
|
|
con.MinSpeedGb = f.num(string(c.Cap) + "_speed")
|
|
}
|
|
// "Preferred" means placement may ignore it rather than refuse
|
|
// the request, which is a different question from how many.
|
|
if f.str(string(c.Cap)+"_how") == "prefer" {
|
|
req.Compute.Prefer = append(req.Compute.Prefer, con)
|
|
} else {
|
|
req.Compute.Require = append(req.Compute.Require, con)
|
|
}
|
|
}
|
|
|
|
for _, a := range strings.Split(f.values["apps"], ",") {
|
|
if a = strings.TrimSpace(a); a != "" {
|
|
req.Stack.Apps = append(req.Stack.Apps, a)
|
|
}
|
|
}
|
|
sort.Strings(req.Stack.Apps)
|
|
|
|
return req, req.Validate()
|
|
}
|
|
|
|
// asYAML is how the planned request survives the step between "here is
|
|
// where it would go" and "yes, build it". The second POST carries one
|
|
// hidden field rather than a copy of every input, so the thing created is
|
|
// by construction the thing that was planned.
|
|
func (f planForm) asYAML(req spec.Request) (string, error) {
|
|
b, err := yaml.Marshal(req)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(b), nil
|
|
}
|
|
|
|
// appChoice is one catalogue entry as the form offers it.
|
|
type appChoice struct {
|
|
Ref string // "gromacs:2024" - what the request names
|
|
Name string
|
|
Version string
|
|
Description string
|
|
Requires string // "gpu, infiniband", for the line under the checkbox
|
|
Checked bool
|
|
// Deprecated marks a version that still works and still may be asked
|
|
// for, but is not what the bare name resolves to. Shown rather than
|
|
// hidden: somebody who pinned it deliberately should see that it has
|
|
// been superseded, and somebody who has not should see why they are
|
|
// being offered two.
|
|
Deprecated bool
|
|
Note string
|
|
}
|
|
|
|
func appChoices(c *catalog.Catalog, chosen string) []appChoice {
|
|
if c == nil {
|
|
return nil
|
|
}
|
|
picked := map[string]bool{}
|
|
for _, a := range strings.Split(chosen, ",") {
|
|
if a = strings.TrimSpace(a); a != "" {
|
|
picked[a] = true
|
|
}
|
|
}
|
|
out := make([]appChoice, 0, len(c.Apps))
|
|
for _, a := range c.Apps {
|
|
// A withdrawn version is in the file because the catalogue is the
|
|
// record of what has been published, but it must not be offered -
|
|
// the form is where a new cluster is asked for, and Resolve would
|
|
// refuse it anyway, at the end of a form the person had filled in.
|
|
if !a.Offered() {
|
|
continue
|
|
}
|
|
ref := a.Name
|
|
if a.Version != "" {
|
|
ref = a.Name + ":" + a.Version
|
|
}
|
|
reqs := make([]string, len(a.Requires))
|
|
for i, x := range a.Requires {
|
|
reqs[i] = string(x)
|
|
}
|
|
out = append(out, appChoice{
|
|
Ref: ref, Name: a.Name, Version: a.Version,
|
|
Description: a.Description,
|
|
Requires: strings.Join(reqs, ", "),
|
|
Checked: picked[ref],
|
|
Deprecated: a.Status() == catalog.StatusDeprecated,
|
|
Note: a.StatusNote,
|
|
})
|
|
}
|
|
sort.Slice(out, func(i, j int) bool { return out[i].Ref < out[j].Ref })
|
|
return out
|
|
}
|
|
|
|
// capabilityRow is one rendered hardware row, with what was typed in it.
|
|
type capabilityRow struct {
|
|
capabilityField
|
|
Key string
|
|
Count string
|
|
Vendor string
|
|
Speed string
|
|
Prefer bool
|
|
}
|
|
|
|
func capabilityRows(f planForm) []capabilityRow {
|
|
fields := capabilityFields()
|
|
out := make([]capabilityRow, 0, len(fields))
|
|
for _, c := range fields {
|
|
k := string(c.Cap)
|
|
out = append(out, capabilityRow{
|
|
capabilityField: c,
|
|
Key: k,
|
|
Count: f.str(k + "_count"),
|
|
Vendor: f.str(k + "_vendor"),
|
|
Speed: f.str(k + "_speed"),
|
|
Prefer: f.str(k+"_how") == "prefer",
|
|
})
|
|
}
|
|
return out
|
|
}
|
|
|
|
// memoryNote states the one thing about the numbers that is not obvious,
|
|
// where it is being typed rather than in documentation nobody opens.
|
|
func memoryNote() string {
|
|
return fmt.Sprintf("Usable memory per node. Warewulf holds the root filesystem in RAM, "+
|
|
"so %d GiB is added on top of whatever you ask for.", spec.RootfsReserveGB)
|
|
}
|