Setting oversubscription to x10 in the portal left "hpcod discover" still reporting x6, because the portal applies the recorded policy and the command line applied whatever sites.yaml said. Two answers to how many cores the estate offers, and the one that is out of date is the command line - which is the thing people check an argument against. discover, capacity and plan now fold in the database's policy after discovery, the same way the portal does. Quiet when there is no database, because these commands have always worked without one and a warning on every invocation trains people to ignore warnings. Not quiet when a database was asked for and could not be reached: the numbers that follow are about to be the wrong ones. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/ilkermanap/hpcod/internal/model"
|
|
"github.com/ilkermanap/hpcod/internal/store"
|
|
)
|
|
|
|
// applyRecordedPolicy folds the database's oversubscription policy into a
|
|
// freshly discovered inventory.
|
|
//
|
|
// The portal does this on every sweep. Without it here, hpcod discover and
|
|
// hpcod plan answer from the site catalogue while the portal answers from
|
|
// the database, and the two disagree about how many cores exist - with the
|
|
// command line, the thing people check an argument against, being the one
|
|
// that is out of date.
|
|
//
|
|
// Quiet when there is no database: these commands have always worked
|
|
// without one, and a warning on every invocation would train people to
|
|
// ignore it.
|
|
func applyRecordedPolicy(ctx context.Context, sites []model.Site) {
|
|
dsn, err := resolveDSN("")
|
|
if err != nil {
|
|
return
|
|
}
|
|
st, err := store.Open(ctx, dsn)
|
|
if err != nil {
|
|
if os.Getenv("HPCOD_DB_DSN") != "" {
|
|
// Asked for explicitly and unreachable: worth saying, because
|
|
// the numbers below are about to be the wrong ones.
|
|
log.Printf("warning: %v; showing the site catalogue's ratios", err)
|
|
}
|
|
return
|
|
}
|
|
defer st.Close()
|
|
|
|
policies, err := st.Policies(ctx)
|
|
if err != nil {
|
|
log.Printf("warning: reading site policy: %v; showing the site catalogue's ratios", err)
|
|
return
|
|
}
|
|
model.ApplyOvercommit(sites, policies)
|
|
}
|