Files
ilker f74859d138 hpcod phase 1: multi-provider discovery
First code for the HPC-on-demand portal. The portal is meant to front more
than Proxmox - OpenStack is expected next - so the provider abstraction comes
first and Proxmox is simply its first implementation. internal/model holds the
vocabulary everything above reasons in; adding a provider means writing one
package and registering it.

The layered capability detection from the design is implemented and enforced.
A PCI class code cannot identify InfiniBand: a ConnectX-4 Lx reports class
0x0200 because that variant is Ethernet-only, while a ConnectX-6 reports
0x0207 in IB mode and 0x0200 in Ethernet mode. Every capability claim
therefore records how it was made - class, curated vendor:device map, or live
agent - and Capability.Trusted refuses to schedule on a fabric until an agent
confirms the link. Unconfirmed devices are still reported, since that gap is
what an operator has to close. Passthrough viability comes from IOMMU group
membership rather than device presence: sibling functions of one card are
fine, an unrelated device in the group is not.

Verified against a live Proxmox site, where it correctly classifies the
Mellanox cards as roce rather than infiniband and withholds them from the
schedulable set, while offering the Quadro K620 that does sit alone in its
IOMMU group.

Two bugs found and fixed while running it for real:

- Query strings were appended to url.URL.Path, which is the decoded path, so
  String() escaped the "?" and /cluster/resources?type=vm silently stopped
  filtering. Guests were ignored and a node running 22 VMs reported all cores
  free. Regression test added.
- Physical cores are now the schedulable total by default rather than being
  ignored, with a per-site cpu_overcommit for hosts where oversubscription is
  acceptable. An HPC tenant given oversubscribed cores just runs slowly.

Secrets stay out of the catalogue: any setting may be written env:NAME. The
Proxmox token needs PVEAuditor only.
2026-09-01 11:53:35 +02:00

73 lines
1.9 KiB
Go

// Package provider defines what the control plane needs from a backing cloud.
//
// Proxmox is the first implementation; OpenStack and others are expected to
// follow. The interface is deliberately small and read-only for now: phase 1
// of the design is discovery, which carries the design risk and none of the
// destructive operations.
package provider
import (
"context"
"fmt"
"sort"
"sync"
"github.com/ilkermanap/hpcod/internal/model"
)
// Provider is one backing cloud the portal can place tenants on.
type Provider interface {
// ID is the stable identifier from configuration.
ID() string
// Kind names the implementation: "proxmox", "openstack", ...
Kind() string
// Discover returns current inventory. It must not mutate the site, and
// must return a Site with Reachable=false and Error set rather than an
// error when the site is merely unreachable - an unreachable site is
// inventory data, not a program failure.
Discover(ctx context.Context) (model.Site, error)
}
// Factory builds a Provider from its configuration block.
type Factory func(cfg SiteConfig) (Provider, error)
var (
mu sync.RWMutex
factories = map[string]Factory{}
)
// Register makes a provider kind available to the loader. Implementations call
// this from an init function.
func Register(kind string, f Factory) {
mu.Lock()
defer mu.Unlock()
if _, dup := factories[kind]; dup {
panic("provider registered twice: " + kind)
}
factories[kind] = f
}
// Kinds lists the registered provider kinds.
func Kinds() []string {
mu.RLock()
defer mu.RUnlock()
out := make([]string, 0, len(factories))
for k := range factories {
out = append(out, k)
}
sort.Strings(out)
return out
}
// New builds the provider named by cfg.Kind.
func New(cfg SiteConfig) (Provider, error) {
mu.RLock()
f, ok := factories[cfg.Kind]
mu.RUnlock()
if !ok {
return nil, fmt.Errorf("site %q: unknown provider kind %q (known: %v)",
cfg.ID, cfg.Kind, Kinds())
}
return f(cfg)
}