diff --git a/internal/config/config.go b/internal/config/config.go index a2e9fd60..e00a51e4 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -540,8 +540,14 @@ func (s Server) Catalog() (*catalog.Catalog, error) { // A model with no profiles cannot be placed, so a configuration of bare names // plus a static endpoint list is the router-only mode used for testing against // sim-engines. +// +// With no static endpoints there is nothing a router-only process could serve, +// so a configuration naming neither endpoints nor models is a control plane +// with an empty catalog — which is what every new cluster is. It used to be +// refused as having nothing to serve, and under systemd that is a unit +// restarting every two seconds with nothing on 8080. func (s Server) ControlPlaneMode() bool { - if s.Control.Enabled { + if s.Control.Enabled || len(s.Endpoints) == 0 { return true } for _, m := range s.Models { diff --git a/internal/config/config_test.go b/internal/config/config_test.go index a75eba8c..47c1bb8b 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -155,19 +155,26 @@ func TestValidateAcceptsDistinctAliases(t *testing.T) { } } -func TestAControlPlaneCanBeAskedForWithNoModelsInTheFile(t *testing.T) { - // Without this, a deployment whose catalog lives entirely in the database - // cannot start: the mode is inferred from the file, an empty models block - // reads as "router only", and the process refuses to start for want of - // anything to serve — so the stored models it would have loaded are never - // read at all. +func TestAnEmptyConfigurationIsAControlPlane(t *testing.T) { + // A new cluster has no models and no endpoints. Refusing it as having + // nothing to serve left a systemd unit restarting every two seconds and + // nothing listening on 8080 — on the first start anyone ever made. var s Server + if !s.ControlPlaneMode() { + t.Fatal("a configuration with no endpoints and no models should run a control plane") + } +} + +func TestStaticEndpointsAloneAreRouterOnly(t *testing.T) { + var s Server + s.Endpoints = []Endpoint{{ID: "e", URL: "http://127.0.0.1:1"}} + s.Models = []catalog.Model{{Name: "m"}} if s.ControlPlaneMode() { - t.Fatal("an empty configuration is not a control plane") + t.Error("static endpoints and bare model names are the router-only mode") } s.Control.Enabled = true if !s.ControlPlaneMode() { - t.Error("control.enabled should run the control plane with no models declared") + t.Error("control.enabled should run the control plane alongside static endpoints") } }