host: departure controller sees a stand-in bucket in the root fixture
The W6 ingress drain root fixture's agent runs on a deployment directory with CARLOS_DEPLOYMENT_BUCKET empty, so the departure controller refused to start and fixed admission never got TerminationStarted. agent.go now reads the controller's environment through fixtureDepartureGetenv: the process environment in every production build, and in a rootrunner build the same with the fixture's control bucket name filled in for the controller only. The agent's store is unchanged. A non-root seam test shows the controller built and the consumer at its first receive.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+68
−6
internal/host/agent.go+5 −4internal/host/departure_queue_default.go+5 −0internal/host/departure_queue_rootrunner.go+25 −0internal/host/ingressdrain_rootrunner_linux_test.go+33 −2
diff --git a/internal/host/agent.go b/internal/host/agent.go| index 966381ee8..83c3050fa 100644 |
| --- a/internal/host/agent.go |
| +++ b/internal/host/agent.go |
| @@ -671,11 +671,12 @@ func runAgent(args []string, buildClaims ClaimFactory) { |
| Unit: &activator.UnitBackend{OptDir: release.OptDir(), SandboxEffective: sandboxEffective, SandboxConfigErr: sandboxErr}, |
| }, reg) // the registry satisfies activator.DueStore directly |
| svc.DutyStore = reg |
| - // MakeQueue is nil in a production build (the queue comes from |
| - // CARLOS_TERMINATION_QUEUE_URL); a rootrunner build's fixture may |
| - // supply one (departure_queue_rootrunner.go). |
| + // MakeQueue is nil and Getenv is os.Getenv in a production build |
| + // (the queue comes from CARLOS_TERMINATION_QUEUE_URL); a rootrunner |
| + // build's fixture may supply a queue and a stand-in deployment |
| + // bucket name (departure_queue_rootrunner.go). |
| admissionOption = wireAgentAdmission(admission, svc, eb, func() hadeparture.Lifecycle { |
| - departures, departureLife, err = armHADepartures(agentCtx, departureArm{Admitted: admission.departureAllowed, BeginWork: admission.beginDepartureWork, Getenv: os.Getenv, Registry: reg, Service: svc, Backend: eb, Confirmer: confirmer, Inventory: boxDepartureInventory, OpenStore: openDeployStore, MakeQueue: fixtureDepartureQueue()}) |
| + departures, departureLife, err = armHADepartures(agentCtx, departureArm{Admitted: admission.departureAllowed, BeginWork: admission.beginDepartureWork, Getenv: fixtureDepartureGetenv(), Registry: reg, Service: svc, Backend: eb, Confirmer: confirmer, Inventory: boxDepartureInventory, OpenStore: openDeployStore, MakeQueue: fixtureDepartureQueue()}) |
| if err != nil { |
| log.Printf("ha_departure_init code=unavailable") |
| } |
diff --git a/internal/host/departure_queue_default.go b/internal/host/departure_queue_default.go| index 2f70c8319..64f503e83 100644 |
| --- a/internal/host/departure_queue_default.go |
| +++ b/internal/host/departure_queue_default.go |
| @@ -4,6 +4,7 @@ package host |
| import ( |
| "context" |
| + "os" |
| "github.com/carlosframework/platform/internal/hadeparture" |
| ) |
| @@ -12,3 +13,7 @@ import ( |
| // supplies (departure_queue_rootrunner.go). A production build has none: |
| // the queue comes from CARLOS_TERMINATION_QUEUE_URL. |
| func fixtureDepartureQueue() func(context.Context) (hadeparture.Queue, error) { return nil } |
| + |
| +// fixtureDepartureGetenv is the departure controller's environment. A |
| +// production build reads the process environment as it is. |
| +func fixtureDepartureGetenv() func(string) string { return os.Getenv } |
diff --git a/internal/host/departure_queue_rootrunner.go b/internal/host/departure_queue_rootrunner.go| index a6cdd80d7..53e3c16f5 100644 |
| --- a/internal/host/departure_queue_rootrunner.go |
| +++ b/internal/host/departure_queue_rootrunner.go |
| @@ -4,6 +4,7 @@ package host |
| import ( |
| "context" |
| + "os" |
| "github.com/carlosframework/platform/internal/hadeparture" |
| ) |
| @@ -14,6 +15,30 @@ import ( |
| // have it. |
| var rootrunnerDepartureQueue func(context.Context) (hadeparture.Queue, error) |
| +// rootrunnerDepartureBucket, when set, is the deployment bucket name the |
| +// departure controller sees. A fixture agent that runs on a deployment |
| +// directory (CARLOS_DEPLOYMENT_BUCKET empty) needs one: the controller |
| +// refuses without it, and uses it only as a label in departure IDs. The |
| +// controller's store still comes from openDeployStore, so the agent keeps |
| +// its directory store. Nothing else in the agent sees this name. |
| +var rootrunnerDepartureBucket string |
| + |
| func fixtureDepartureQueue() func(context.Context) (hadeparture.Queue, error) { |
| return rootrunnerDepartureQueue |
| } |
| + |
| +func fixtureDepartureGetenv() func(string) string { |
| + bucket := rootrunnerDepartureBucket |
| + if bucket == "" { |
| + return os.Getenv |
| + } |
| + return func(k string) string { |
| + if k == "CARLOS_DEPLOYMENT_BUCKET" { |
| + if v := os.Getenv(k); v != "" { |
| + return v |
| + } |
| + return bucket |
| + } |
| + return os.Getenv(k) |
| + } |
| +} |
diff --git a/internal/host/ingressdrain_rootrunner_linux_test.go b/internal/host/ingressdrain_rootrunner_linux_test.go| index e42f55c87..c6106858a 100644 |
| --- a/internal/host/ingressdrain_rootrunner_linux_test.go |
| +++ b/internal/host/ingressdrain_rootrunner_linux_test.go |
| @@ -137,6 +137,13 @@ func (ingressRootQueue) Delete(context.Context, string) error { return nil } |
| // rootrunner-tagged seam supplies an empty queue. The consumer's journal and |
| // proof-store checks still run against the fixture's stores. |
| func ingressRootArmFake() { |
| + // The departure controller needs a deployment bucket name, which this |
| + // agent (on a deployment directory) clears; the seam gives it the |
| + // fixture's control bucket, to the controller only. |
| + rootrunnerDepartureBucket = os.Getenv("CARLOS_DEPLOYMENT_BUCKET") |
| + if rootrunnerDepartureBucket == "" { |
| + rootrunnerDepartureBucket = "deployment" |
| + } |
| var asked atomic.Int64 |
| rootrunnerDepartureQueue = func(context.Context) (hadeparture.Queue, error) { |
| if asked.Add(1) == 1 { |
| @@ -1055,8 +1062,11 @@ func TestIngressRootLoopClassify(t *testing.T) { |
| // fixtureDepartureQueue under the rootrunner tag) starts the consumer, so |
| // fixed admission's TerminationStarted can arrive. |
| func TestIngressRootDepartureSeam(t *testing.T) { |
| - saved, savedC := rootrunnerDepartureQueue, metricsDepartures.Load() |
| - t.Cleanup(func() { rootrunnerDepartureQueue = saved; metricsDepartures.Store(savedC) }) |
| + saved, savedC, savedB := rootrunnerDepartureQueue, metricsDepartures.Load(), rootrunnerDepartureBucket |
| + t.Cleanup(func() { |
| + rootrunnerDepartureQueue, rootrunnerDepartureBucket = saved, savedB |
| + metricsDepartures.Store(savedC) |
| + }) |
| if fixtureDepartureQueue() != nil && saved == nil { |
| t.Fatal("seam set before the fixture armed it") |
| } |
| @@ -1077,7 +1087,28 @@ func TestIngressRootDepartureSeam(t *testing.T) { |
| if _, _, err := armHADepartures(t.Context(), noBucket); !errors.As(err, &initErr) || initErr.Stage != "controller" { |
| t.Fatalf("without a deployment bucket: %v", err) |
| } |
| + // The agent's shape: the deployment bucket is empty in the process |
| + // environment, and the departure controller reads it through |
| + // fixtureDepartureGetenv. Unarmed, the seam is the plain environment. |
| + t.Setenv("CARLOS_DEPLOYMENT_BUCKET", "") |
| + t.Setenv("W6_SEAM_PROBE", "probe") |
| + rootrunnerDepartureBucket = "" |
| + if g := fixtureDepartureGetenv(); g("CARLOS_DEPLOYMENT_BUCKET") != "" || g("W6_SEAM_PROBE") != "probe" { |
| + t.Fatal("an unarmed seam must be the process environment") |
| + } |
| + rootrunnerDepartureBucket = "deployment" |
| + seam := fixtureDepartureGetenv() |
| + if seam("CARLOS_DEPLOYMENT_BUCKET") != "deployment" || seam("W6_SEAM_PROBE") != "probe" || os.Getenv("CARLOS_DEPLOYMENT_BUCKET") != "" { |
| + t.Fatal("the armed seam must name the stand-in bucket to the controller only") |
| + } |
| a, _, _ := departureArmFixture(t) |
| + fixtureEnv := a.Getenv |
| + a.Getenv = func(k string) string { |
| + if k == "CARLOS_DEPLOYMENT_BUCKET" { |
| + return seam(k) |
| + } |
| + return fixtureEnv(k) |
| + } |
| a.MakeQueue = fixtureDepartureQueue() |
| if a.MakeQueue == nil { |
| t.Fatal("the rootrunner build's seam returned no queue") |