Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Add canonical hosted tenant runtime rollout control

rcourtman9ab2f8ab2163
diff --git a/cmd/pulse-control-plane/main.go b/cmd/pulse-control-plane/main.go
index 2cf4fcce0e..3c972de5ea 100644
--- a/cmd/pulse-control-plane/main.go
+++ b/cmd/pulse-control-plane/main.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
+ "time"
"github.com/rcourtman/pulse-go-rewrite/internal/cloudcp"
"github.com/spf13/cobra"
@@ -38,8 +39,71 @@ var versionCmd = &cobra.Command{
},
}
+func newTenantRuntimeCmd() *cobra.Command {
+ cmd := &cobra.Command{
+ Use: "tenant-runtime",
+ Short: "Operate on hosted tenant runtime containers",
+ }
+ cmd.AddCommand(newTenantRuntimeRolloutCmd())
+ return cmd
+}
+
+func newTenantRuntimeRolloutCmd() *cobra.Command {
+ var tenantID string
+ var image string
+ var runID string
+ var snapshotRoot string
+ var healthTimeout time.Duration
+ var prunePrevious bool
+
+ cmd := &cobra.Command{
+ Use: "rollout",
+ Short: "Canonically roll a hosted tenant onto a target runtime image",
+ RunE: func(cmd *cobra.Command, args []string) error {
+ cfg, err := cloudcp.LoadConfig()
+ if err != nil {
+ return fmt.Errorf("load control plane config: %w", err)
+ }
+ result, err := cloudcp.RolloutTenantRuntime(cmd.Context(), cfg, cloudcp.TenantRuntimeRolloutOptions{
+ TenantID: tenantID,
+ Image: image,
+ RunID: runID,
+ SnapshotRoot: snapshotRoot,
+ HealthTimeout: healthTimeout,
+ PrunePrevious: prunePrevious,
+ })
+ if err != nil {
+ return err
+ }
+
+ fmt.Printf("tenant_id=%s\n", result.TenantID)
+ fmt.Printf("active_container_id=%s\n", result.ActiveContainerID)
+ fmt.Printf("active_image_ref=%s\n", result.ActiveImageRef)
+ fmt.Printf("active_image_id=%s\n", result.ActiveImageID)
+ fmt.Printf("reconciled_only=%t\n", result.ReconciledOnly)
+ if result.PreviousContainerID != "" {
+ fmt.Printf("previous_container_id=%s\n", result.PreviousContainerID)
+ }
+ if result.BackupContainerName != "" {
+ fmt.Printf("backup_container_name=%s\n", result.BackupContainerName)
+ }
+ return nil
+ },
+ }
+ cmd.Flags().StringVar(&tenantID, "tenant-id", "", "Hosted tenant ID to roll")
+ cmd.Flags().StringVar(&image, "image", "", "Target Pulse runtime image reference")
+ cmd.Flags().StringVar(&runID, "run-id", "", "Operator-visible rollout run identifier")
+ cmd.Flags().StringVar(&snapshotRoot, "snapshot-root", "", "Override tenant snapshot root (default: <CP_DATA_DIR>/backups/rollout)")
+ cmd.Flags().DurationVar(&healthTimeout, "health-timeout", 90*time.Second, "How long to wait for the target runtime to become healthy")
+ cmd.Flags().BoolVar(&prunePrevious, "prune-previous", false, "Remove the preserved pre-rollout container after success")
+ _ = cmd.MarkFlagRequired("tenant-id")
+ _ = cmd.MarkFlagRequired("image")
+ return cmd
+}
+
func init() {
rootCmd.AddCommand(versionCmd)
+ rootCmd.AddCommand(newTenantRuntimeCmd())
}
func main() {
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index 0f100d9ebf..05f87a35e2 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -23,41 +23,44 @@ server-side update execution surfaces.
1. `internal/updates/`
2. `internal/api/updates.go`
3. `frontend-modern/src/api/updates.ts`
-4. `.github/workflows/create-release.yml`
-5. `.github/workflows/deploy-demo-server.yml`
-6. `.github/workflows/helm-pages.yml`
-7. `.github/workflows/promote-floating-tags.yml`
-8. `.github/workflows/publish-docker.yml`
-9. `.github/workflows/publish-helm-chart.yml`
-10. `.github/workflows/release-dry-run.yml`
-11. `.github/workflows/update-demo-server.yml`
-12. `docs/releases/V6_PRERELEASE_RUNBOOK.md`
-13. `package.json`
-14. `frontend-modern/package.json`
-15. `scripts/build-release.sh`
-16. `scripts/check-workflow-dispatch-inputs.py`
-17. `scripts/clean-mock-alerts.sh`
-18. `scripts/com.pulse.hot-dev.plist.template`
-19. `scripts/dev-check.sh`
-20. `scripts/dev-launchd-setup.sh`
-21. `scripts/dev-launchd-wrapper.sh`
-22. `scripts/hot-dev-bg.sh`
-23. `scripts/hot-dev.sh`
-24. `scripts/install-container-agent.sh`
-25. `scripts/install.ps1`
-26. `scripts/install.sh`
-27. `scripts/pulse-auto-update.sh`
-28. `scripts/release_control/resolve_release_promotion.py`
-29. `scripts/release_ldflags.sh`
-30. `scripts/trigger-release-dry-run.sh`
-31. `scripts/trigger-release.sh`
-32. `scripts/toggle-mock.sh`
-33. `tests/integration/playwright.config.ts`
-34. `tests/integration/QUICK_START.md`
-35. `tests/integration/README.md`
-36. `tests/integration/scripts/managed-dev-runtime.mjs`
-37. `tests/integration/tests/helpers.ts`
-38. `tests/integration/tests/runtime-defaults.ts`
+4. `cmd/pulse-control-plane/main.go`
+5. `internal/cloudcp/docker/manager.go`
+6. `internal/cloudcp/tenant_runtime_rollout.go`
+7. `.github/workflows/create-release.yml`
+8. `.github/workflows/deploy-demo-server.yml`
+9. `.github/workflows/helm-pages.yml`
+10. `.github/workflows/promote-floating-tags.yml`
+11. `.github/workflows/publish-docker.yml`
+12. `.github/workflows/publish-helm-chart.yml`
+13. `.github/workflows/release-dry-run.yml`
+14. `.github/workflows/update-demo-server.yml`
+15. `docs/releases/V6_PRERELEASE_RUNBOOK.md`
+16. `package.json`
+17. `frontend-modern/package.json`
+18. `scripts/build-release.sh`
+19. `scripts/check-workflow-dispatch-inputs.py`
+20. `scripts/clean-mock-alerts.sh`
+21. `scripts/com.pulse.hot-dev.plist.template`
+22. `scripts/dev-check.sh`
+23. `scripts/dev-launchd-setup.sh`
+24. `scripts/dev-launchd-wrapper.sh`
+25. `scripts/hot-dev-bg.sh`
+26. `scripts/hot-dev.sh`
+27. `scripts/install-container-agent.sh`
+28. `scripts/install.ps1`
+29. `scripts/install.sh`
+30. `scripts/pulse-auto-update.sh`
+31. `scripts/release_control/resolve_release_promotion.py`
+32. `scripts/release_ldflags.sh`
+33. `scripts/trigger-release-dry-run.sh`
+34. `scripts/trigger-release.sh`
+35. `scripts/toggle-mock.sh`
+36. `tests/integration/playwright.config.ts`
+37. `tests/integration/QUICK_START.md`
+38. `tests/integration/README.md`
+39. `tests/integration/scripts/managed-dev-runtime.mjs`
+40. `tests/integration/tests/helpers.ts`
+41. `tests/integration/tests/runtime-defaults.ts`
## Shared Boundaries
@@ -75,6 +78,7 @@ server-side update execution surfaces.
5. Add or change local dev-runtime orchestration, managed ownership, browser-runtime proof wiring, frontend/backend coherence diagnostics, canonical developer entry wrappers, or dev-runtime helper control surfaces through `scripts/hot-dev.sh`, `scripts/hot-dev-bg.sh`, `Makefile`, `package.json`, `frontend-modern/package.json`, `scripts/dev-check.sh`, `scripts/toggle-mock.sh`, `scripts/clean-mock-alerts.sh`, `scripts/dev-launchd-setup.sh`, `scripts/dev-launchd-wrapper.sh`, `scripts/com.pulse.hot-dev.plist.template`, `tests/integration/scripts/managed-dev-runtime.mjs`, `tests/integration/playwright.config.ts`, `tests/integration/tests/helpers.ts`, `tests/integration/tests/runtime-defaults.ts`, `tests/integration/README.md`, and `tests/integration/QUICK_START.md`
6. Add or change governed release-promotion workflow inputs, operator-facing promotion metadata, artifact publication lineage enforcement, or stable-promotion rehearsal summaries through `.github/workflows/create-release.yml`, `.github/workflows/helm-pages.yml`, `.github/workflows/publish-docker.yml`, `.github/workflows/publish-helm-chart.yml`, `.github/workflows/promote-floating-tags.yml`, `.github/workflows/release-dry-run.yml`, `.github/workflows/update-demo-server.yml`, `docs/releases/V6_PRERELEASE_RUNBOOK.md`, `scripts/check-workflow-dispatch-inputs.py`, `scripts/trigger-release.sh`, and `scripts/trigger-release-dry-run.sh`
7. Preserve release-matched installer and Helm operator documentation links through `scripts/install.sh`, `.github/workflows/helm-pages.yml`, `.github/workflows/publish-helm-chart.yml`, and the chart metadata itself so deployment guidance and packaged chart metadata do not drift back to branch-tip `main` docs when a release line or promoted tag already exists.
+8. Add or change operator-facing hosted tenant runtime canary rollout or control-plane runtime-registry reconciliation through `cmd/pulse-control-plane/main.go`, `internal/cloudcp/docker/manager.go`, and `internal/cloudcp/tenant_runtime_rollout.go`
## Forbidden Paths
@@ -238,6 +242,14 @@ one.
`scripts/hot-dev-bg.sh verify` must also establish a managed verification lock
for the duration of the proof pack, pass that lock path into the integration
runner, and keep the lock owned by the actual browser-proof process lifetime
+rather than dropping it as soon as the launcher command itself exits.
+That same deployment boundary now owns hosted tenant canary rollouts too.
+`cmd/pulse-control-plane/main.go`, `internal/cloudcp/docker/manager.go`, and
+`internal/cloudcp/tenant_runtime_rollout.go` must replace tenant runtime
+containers through the canonical Docker manager, snapshot tenant data before
+swap, and reconcile the control-plane registry to the live container that
+actually serves traffic instead of relying on ad hoc host-local scripts that
+swap containers behind the control plane's back.
across pretest, Playwright, and posttest. `scripts/hot-dev.sh` must honor that
lock by suppressing source-triggered rebuilds and manual `pulse` binary restart
churn while the owning proof process is still alive. Stale verify locks must
diff --git a/docs/release-control/v6/internal/subsystems/registry.json b/docs/release-control/v6/internal/subsystems/registry.json
index ee316310bc..c8f6beb389 100644
--- a/docs/release-control/v6/internal/subsystems/registry.json
+++ b/docs/release-control/v6/internal/subsystems/registry.json
@@ -2265,11 +2265,14 @@
".github/workflows/publish-helm-chart.yml",
".github/workflows/release-dry-run.yml",
".github/workflows/update-demo-server.yml",
+ "cmd/pulse-control-plane/main.go",
"Dockerfile",
"docs/releases/V6_PRERELEASE_RUNBOOK.md",
"frontend-modern/package.json",
"frontend-modern/src/api/updates.ts",
"internal/api/updates.go",
+ "internal/cloudcp/docker/manager.go",
+ "internal/cloudcp/tenant_runtime_rollout.go",
"Makefile",
"package.json",
"scripts/build-release.sh",
@@ -2391,6 +2394,21 @@
"scripts/installtests/root_install_sh_test.go"
]
},
+ {
+ "id": "hosted-runtime-rollout-control",
+ "label": "hosted runtime rollout control proof",
+ "match_prefixes": [],
+ "match_files": [
+ "cmd/pulse-control-plane/main.go",
+ "internal/cloudcp/docker/manager.go",
+ "internal/cloudcp/tenant_runtime_rollout.go"
+ ],
+ "allow_same_subsystem_tests": false,
+ "test_prefixes": [],
+ "exact_files": [
+ "internal/cloudcp/tenant_runtime_rollout_test.go"
+ ]
+ },
{
"id": "dev-runtime-orchestration",
"label": "dev runtime orchestration proof",
diff --git a/internal/cloudcp/docker/manager.go b/internal/cloudcp/docker/manager.go
index f471441804..f9ab354537 100644
--- a/internal/cloudcp/docker/manager.go
+++ b/internal/cloudcp/docker/manager.go
@@ -16,6 +16,7 @@ import (
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
+ "github.com/docker/docker/errdefs"
"github.com/rs/zerolog/log"
)
@@ -37,6 +38,16 @@ type Manager struct {
cfg ManagerConfig
}
+// RuntimeContainerInfo is the canonical live-container snapshot used by
+// operator rollout and reconciliation flows.
+type RuntimeContainerInfo struct {
+ ID string
+ Name string
+ ImageRef string
+ ImageID string
+ Running bool
+}
+
const immutableOwnershipPathsEnv = "PULSE_IMMUTABLE_OWNERSHIP_PATHS"
const (
@@ -64,6 +75,11 @@ func (m *Manager) Close() error {
return nil
}
+// IsNotFound reports whether Docker treated an identifier as missing.
+func IsNotFound(err error) bool {
+ return errdefs.IsNotFound(err)
+}
+
func (m *Manager) ensureDaemonReachable(ctx context.Context) error {
if m == nil || m.cli == nil {
return fmt.Errorf("docker client unavailable")
@@ -266,6 +282,11 @@ func (m *Manager) Stop(ctx context.Context, containerID string) error {
return m.cli.ContainerStop(ctx, containerID, container.StopOptions{Timeout: &timeout})
}
+// Start starts a stopped tenant container.
+func (m *Manager) Start(ctx context.Context, containerID string) error {
+ return m.cli.ContainerStart(ctx, containerID, container.StartOptions{})
+}
+
// Remove removes a stopped tenant container.
func (m *Manager) Remove(ctx context.Context, containerID string) error {
return m.cli.ContainerRemove(ctx, containerID, container.RemoveOptions{
@@ -273,6 +294,41 @@ func (m *Manager) Remove(ctx context.Context, containerID string) error {
})
}
+// Rename renames a tenant container to the supplied Docker name.
+func (m *Manager) Rename(ctx context.Context, containerIDOrName, newName string) error {
+ if err := m.ensureDaemonReachable(ctx); err != nil {
+ return err
+ }
+ if err := m.cli.ContainerRename(ctx, containerIDOrName, newName); err != nil {
+ return fmt.Errorf("rename container %s -> %s: %w", containerIDOrName, newName, err)
+ }
+ return nil
+}
+
+// Inspect returns the canonical live metadata for the supplied container
+// identifier.
+func (m *Manager) Inspect(ctx context.Context, containerIDOrName string) (*RuntimeContainerInfo, error) {
+ if err := m.ensureDaemonReachable(ctx); err != nil {
+ return nil, err
+ }
+ inspect, err := m.cli.ContainerInspect(ctx, containerIDOrName)
+ if err != nil {
+ return nil, fmt.Errorf("inspect container %s: %w", containerIDOrName, err)
+ }
+ imageRef := ""
+ if inspect.Config != nil {
+ imageRef = strings.TrimSpace(inspect.Config.Image)
+ }
+ running := inspect.State != nil && inspect.State.Running
+ return &RuntimeContainerInfo{
+ ID: inspect.ID,
+ Name: strings.TrimPrefix(strings.TrimSpace(inspect.Name), "/"),
+ ImageRef: imageRef,
+ ImageID: strings.TrimSpace(inspect.Image),
+ Running: running,
+ }, nil
+}
+
// StopAndRemove stops then removes a tenant container.
func (m *Manager) StopAndRemove(ctx context.Context, containerID string) error {
if err := m.Stop(ctx, containerID); err != nil {
diff --git a/internal/cloudcp/tenant_runtime_rollout.go b/internal/cloudcp/tenant_runtime_rollout.go
new file mode 100644
index 0000000000..6deb5feebc
--- /dev/null
+++ b/internal/cloudcp/tenant_runtime_rollout.go
@@ -0,0 +1,444 @@
+package cloudcp
+
+import (
+ "context"
+ "fmt"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strings"
+ "time"
+
+ cpDocker "github.com/rcourtman/pulse-go-rewrite/internal/cloudcp/docker"
+ "github.com/rcourtman/pulse-go-rewrite/internal/cloudcp/registry"
+ "github.com/rs/zerolog/log"
+)
+
+const (
+ defaultTenantRuntimeRolloutHealthTimeout = 90 * time.Second
+ defaultTenantRuntimeRolloutHealthPoll = 2 * time.Second
+)
+
+// TenantRuntimeRolloutOptions controls the hosted tenant runtime rollout path.
+type TenantRuntimeRolloutOptions struct {
+ TenantID string
+ Image string
+ RunID string
+ SnapshotRoot string
+ HealthTimeout time.Duration
+ HealthPollInterval time.Duration
+ PrunePrevious bool
+}
+
+// TenantRuntimeRolloutResult summarizes the canonical runtime state after a
+// rollout or drift-reconciliation pass.
+type TenantRuntimeRolloutResult struct {
+ TenantID string
+ PreviousContainerID string
+ ActiveContainerID string
+ ActiveImageRef string
+ ActiveImageID string
+ BackupContainerName string
+ ReconciledOnly bool
+}
+
+type tenantRuntimeRolloutRegistry interface {
+ Get(tenantID string) (*registry.Tenant, error)
+ Update(t *registry.Tenant) error
+}
+
+type tenantRuntimeRolloutDocker interface {
+ CreateAndStart(ctx context.Context, tenantID, tenantDataDir string) (string, error)
+ HealthCheck(ctx context.Context, containerID string) (bool, error)
+ Inspect(ctx context.Context, containerIDOrName string) (*cpDocker.RuntimeContainerInfo, error)
+ Remove(ctx context.Context, containerID string) error
+ Rename(ctx context.Context, containerIDOrName, newName string) error
+ Start(ctx context.Context, containerID string) error
+ Stop(ctx context.Context, containerID string) error
+}
+
+type tenantRuntimeRolloutSynchronizer interface {
+ Snapshot(ctx context.Context, srcDir, snapshotDir string) error
+ Restore(ctx context.Context, snapshotDir, dstDir string) error
+}
+
+type tenantRuntimeRolloutService struct {
+ registry tenantRuntimeRolloutRegistry
+ docker tenantRuntimeRolloutDocker
+ tenantsDir string
+ synchronizer tenantRuntimeRolloutSynchronizer
+ now func() time.Time
+ sleep func(time.Duration)
+ healthTimeout time.Duration
+ healthPoll time.Duration
+}
+
+// RolloutTenantRuntime executes the canonical hosted tenant runtime rollout
+// path using the control plane's registry and Docker manager.
+func RolloutTenantRuntime(ctx context.Context, cfg *CPConfig, opts TenantRuntimeRolloutOptions) (*TenantRuntimeRolloutResult, error) {
+ if cfg == nil {
+ return nil, fmt.Errorf("control plane config is required")
+ }
+
+ image := strings.TrimSpace(opts.Image)
+ if image == "" {
+ image = strings.TrimSpace(cfg.PulseImage)
+ }
+ if image == "" {
+ return nil, fmt.Errorf("missing tenant runtime image")
+ }
+ opts.Image = image
+
+ if err := os.MkdirAll(cfg.TenantsDir(), 0o755); err != nil {
+ return nil, fmt.Errorf("ensure tenants dir: %w", err)
+ }
+ if err := os.MkdirAll(cfg.ControlPlaneDir(), 0o755); err != nil {
+ return nil, fmt.Errorf("ensure control-plane dir: %w", err)
+ }
+
+ reg, err := registry.NewTenantRegistry(cfg.ControlPlaneDir())
+ if err != nil {
+ return nil, fmt.Errorf("open tenant registry: %w", err)
+ }
+ defer reg.Close()
+
+ dockerMgr, err := cpDocker.NewManager(cpDocker.ManagerConfig{
+ Image: image,
+ Network: cfg.DockerNetwork,
+ BaseDomain: baseDomainFromURL(cfg.BaseURL),
+ TrialActivationPublicKey: cfg.TrialActivationPublicKey,
+ TrustedProxyCIDRs: cfg.TrustedProxyCIDRs,
+ MemoryLimit: cfg.TenantMemoryLimit,
+ CPUShares: cfg.TenantCPUShares,
+ })
+ if err != nil {
+ return nil, fmt.Errorf("create docker manager: %w", err)
+ }
+ defer dockerMgr.Close()
+
+ service := &tenantRuntimeRolloutService{
+ registry: reg,
+ docker: dockerMgr,
+ tenantsDir: cfg.TenantsDir(),
+ synchronizer: rsyncTenantRuntimeSynchronizer{},
+ now: func() time.Time { return time.Now().UTC() },
+ sleep: time.Sleep,
+ healthTimeout: defaultTenantRuntimeRolloutHealthTimeout,
+ healthPoll: defaultTenantRuntimeRolloutHealthPoll,
+ }
+ return service.Rollout(ctx, opts)
+}
+
+// Rollout performs the tenant runtime rollout or a drift reconciliation if the
+// canonical live container is already on the requested image.
+func (s *tenantRuntimeRolloutService) Rollout(ctx context.Context, opts TenantRuntimeRolloutOptions) (*TenantRuntimeRolloutResult, error) {
+ if s == nil {
+ return nil, fmt.Errorf("rollout service is nil")
+ }
+ tenantID := strings.TrimSpace(opts.TenantID)
+ if tenantID == "" {
+ return nil, fmt.Errorf("tenant id is required")
+ }
+ image := strings.TrimSpace(opts.Image)
+ if image == "" {
+ return nil, fmt.Errorf("image is required")
+ }
+
+ tenant, err := s.registry.Get(tenantID)
+ if err != nil {
+ return nil, fmt.Errorf("load tenant %s: %w", tenantID, err)
+ }
+ if tenant == nil {
+ return nil, fmt.Errorf("tenant %s not found", tenantID)
+ }
+
+ healthTimeout := opts.HealthTimeout
+ if healthTimeout <= 0 {
+ healthTimeout = s.healthTimeout
+ }
+ healthPoll := opts.HealthPollInterval
+ if healthPoll <= 0 {
+ healthPoll = s.healthPoll
+ }
+ runID := sanitizeTenantRuntimeRolloutRunID(opts.RunID, s.now())
+
+ live, err := s.resolveLiveContainer(ctx, tenant)
+ if err != nil {
+ return nil, err
+ }
+ if strings.TrimSpace(tenant.ContainerID) != "" && tenant.ContainerID != live.ID {
+ log.Warn().
+ Str("tenant_id", tenantID).
+ Str("registry_container_id", tenant.ContainerID).
+ Str("live_container_id", live.ID).
+ Msg("Tenant registry container_id drifted from the live runtime container")
+ }
+
+ canonicalName := tenantRuntimeContainerName(tenantID)
+ if live.Name == canonicalName && live.ImageRef == image {
+ healthy, err := s.waitForHealth(ctx, live.ID, healthTimeout, healthPoll)
+ if err == nil {
+ if updateErr := s.persistTenantRuntimeState(tenant, live, healthy); updateErr != nil {
+ return nil, updateErr
+ }
+ return &TenantRuntimeRolloutResult{
+ TenantID: tenantID,
+ PreviousContainerID: live.ID,
+ ActiveContainerID: live.ID,
+ ActiveImageRef: live.ImageRef,
+ ActiveImageID: live.ImageID,
+ ReconciledOnly: true,
+ }, nil
+ }
+ log.Warn().
+ Err(err).
+ Str("tenant_id", tenantID).
+ Str("container_id", live.ID).
+ Msg("Live tenant container already matches requested image but failed health sync; recreating canonically")
+ }
+
+ tenantDataDir := filepath.Join(s.tenantsDir, tenantID)
+ snapshotRoot := strings.TrimSpace(opts.SnapshotRoot)
+ if snapshotRoot == "" {
+ snapshotRoot = filepath.Join(filepath.Dir(s.tenantsDir), "backups", "rollout")
+ }
+ snapshotDir := filepath.Join(snapshotRoot, runID, tenantID)
+ if err := s.synchronizer.Snapshot(ctx, tenantDataDir, snapshotDir); err != nil {
+ return nil, fmt.Errorf("snapshot tenant data for %s: %w", tenantID, err)
+ }
+
+ backupName := canonicalName + ".pre-" + runID
+ if existing, inspectErr := s.docker.Inspect(ctx, backupName); inspectErr == nil && existing != nil {
+ return nil, fmt.Errorf("backup container name %s already exists", backupName)
+ } else if inspectErr != nil && !cpDocker.IsNotFound(inspectErr) {
+ return nil, fmt.Errorf("inspect backup container %s: %w", backupName, inspectErr)
+ }
+
+ if err := s.docker.Stop(ctx, live.ID); err != nil {
+ return nil, fmt.Errorf("stop live tenant container %s: %w", live.ID, err)
+ }
+ if err := s.docker.Rename(ctx, live.ID, backupName); err != nil {
+ return nil, fmt.Errorf("rename live tenant container %s -> %s: %w", live.ID, backupName, err)
+ }
+
+ restorePrevious := func(newContainerID string, rolloutErr error) error {
+ var restoreProblems []string
+ if strings.TrimSpace(newContainerID) != "" {
+ if removeErr := s.docker.Remove(ctx, newContainerID); removeErr != nil {
+ restoreProblems = append(restoreProblems, fmt.Sprintf("remove failed container: %v", removeErr))
+ }
+ }
+ if syncErr := s.synchronizer.Restore(ctx, snapshotDir, tenantDataDir); syncErr != nil {
+ restoreProblems = append(restoreProblems, fmt.Sprintf("restore tenant data: %v", syncErr))
+ }
+ if renameErr := s.docker.Rename(ctx, backupName, canonicalName); renameErr != nil {
+ restoreProblems = append(restoreProblems, fmt.Sprintf("rename backup container back: %v", renameErr))
+ }
+ if startErr := s.docker.Start(ctx, canonicalName); startErr != nil {
+ restoreProblems = append(restoreProblems, fmt.Sprintf("restart previous container: %v", startErr))
+ }
+ restoredInfo, inspectErr := s.resolveLiveContainer(ctx, tenant)
+ if inspectErr != nil {
+ restoreProblems = append(restoreProblems, fmt.Sprintf("inspect restored container: %v", inspectErr))
+ } else {
+ healthy, healthErr := s.waitForHealth(ctx, restoredInfo.ID, healthTimeout, healthPoll)
+ if healthErr != nil {
+ restoreProblems = append(restoreProblems, fmt.Sprintf("verify restored container health: %v", healthErr))
+ }
+ if updateErr := s.persistTenantRuntimeState(tenant, restoredInfo, healthy); updateErr != nil {
+ restoreProblems = append(restoreProblems, fmt.Sprintf("persist restored tenant state: %v", updateErr))
+ }
+ }
+ if len(restoreProblems) == 0 {
+ return rolloutErr
+ }
+ return fmt.Errorf("%w; rollback problems: %s", rolloutErr, strings.Join(restoreProblems, "; "))
+ }
+
+ newContainerID, err := s.docker.CreateAndStart(ctx, tenantID, tenantDataDir)
+ if err != nil {
+ return nil, restorePrevious("", fmt.Errorf("start new tenant runtime: %w", err))
+ }
+
+ healthy, err := s.waitForHealth(ctx, newContainerID, healthTimeout, healthPoll)
+ if err != nil || !healthy {
+ if err == nil {
+ err = fmt.Errorf("tenant runtime %s failed health checks", newContainerID)
+ }
+ return nil, restorePrevious(newContainerID, err)
+ }
+
+ newInfo, err := s.resolveLiveContainer(ctx, tenant)
+ if err != nil {
+ return nil, restorePrevious(newContainerID, fmt.Errorf("inspect new tenant runtime: %w", err))
+ }
+ if newInfo.Name != canonicalName {
+ return nil, restorePrevious(newContainerID, fmt.Errorf("new tenant runtime is not using canonical container name %s", canonicalName))
+ }
+ if err := s.persistTenantRuntimeState(tenant, newInfo, true); err != nil {
+ return nil, restorePrevious(newContainerID, err)
+ }
+ if opts.PrunePrevious {
+ if err := s.docker.Remove(ctx, backupName); err != nil {
+ return nil, fmt.Errorf("remove previous tenant runtime %s: %w", backupName, err)
+ }
+ backupName = ""
+ }
+
+ return &TenantRuntimeRolloutResult{
+ TenantID: tenantID,
+ PreviousContainerID: live.ID,
+ ActiveContainerID: newInfo.ID,
+ ActiveImageRef: newInfo.ImageRef,
+ ActiveImageID: newInfo.ImageID,
+ BackupContainerName: backupName,
+ ReconciledOnly: false,
+ }, nil
+}
+
+func (s *tenantRuntimeRolloutService) resolveLiveContainer(ctx context.Context, tenant *registry.Tenant) (*cpDocker.RuntimeContainerInfo, error) {
+ if tenant == nil {
+ return nil, fmt.Errorf("tenant is nil")
+ }
+ canonicalName := tenantRuntimeContainerName(tenant.ID)
+ info, err := s.docker.Inspect(ctx, canonicalName)
+ if err == nil {
+ return info, nil
+ }
+ if !cpDocker.IsNotFound(err) {
+ return nil, fmt.Errorf("inspect canonical tenant container %s: %w", canonicalName, err)
+ }
+
+ containerID := strings.TrimSpace(tenant.ContainerID)
+ if containerID == "" {
+ return nil, fmt.Errorf("tenant %s has no canonical runtime container and no registry container_id", tenant.ID)
+ }
+ info, err = s.docker.Inspect(ctx, containerID)
+ if err != nil {
+ return nil, fmt.Errorf("inspect tenant container %s: %w", containerID, err)
+ }
+ return info, nil
+}
+
+func (s *tenantRuntimeRolloutService) waitForHealth(ctx context.Context, containerID string, timeout, poll time.Duration) (bool, error) {
+ if timeout <= 0 {
+ timeout = defaultTenantRuntimeRolloutHealthTimeout
+ }
+ if poll <= 0 {
+ poll = defaultTenantRuntimeRolloutHealthPoll
+ }
+ deadline := s.now().Add(timeout)
+ for {
+ healthy, err := s.docker.HealthCheck(ctx, containerID)
+ if err == nil && healthy {
+ return true, nil
+ }
+ if ctx.Err() != nil {
+ return false, ctx.Err()
+ }
+ if !s.now().Before(deadline) {
+ if err != nil {
+ return false, fmt.Errorf("container %s did not become healthy before timeout: %w", containerID, err)
+ }
+ return false, fmt.Errorf("container %s did not become healthy before timeout", containerID)
+ }
+ s.sleep(poll)
+ }
+}
+
+func (s *tenantRuntimeRolloutService) persistTenantRuntimeState(tenant *registry.Tenant, info *cpDocker.RuntimeContainerInfo, healthy bool) error {
+ if tenant == nil {
+ return fmt.Errorf("tenant is nil")
+ }
+ if info == nil {
+ return fmt.Errorf("runtime container info is nil")
+ }
+ now := s.now()
+ tenant.ContainerID = info.ID
+ tenant.CurrentImageDigest = info.ImageID
+ tenant.DesiredImageDigest = info.ImageID
+ tenant.LastHealthCheck = &now
+ tenant.HealthCheckOK = healthy
+ if err := s.registry.Update(tenant); err != nil {
+ return fmt.Errorf("update tenant %s runtime registry state: %w", tenant.ID, err)
+ }
+ return nil
+}
+
+func tenantRuntimeContainerName(tenantID string) string {
+ return "pulse-" + strings.TrimSpace(tenantID)
+}
+
+func sanitizeTenantRuntimeRolloutRunID(raw string, now time.Time) string {
+ value := strings.TrimSpace(raw)
+ if value == "" {
+ value = now.UTC().Format("20060102T150405Z")
+ }
+ var builder strings.Builder
+ for _, r := range value {
+ switch {
+ case r >= 'a' && r <= 'z':
+ builder.WriteRune(r)
+ case r >= 'A' && r <= 'Z':
+ builder.WriteRune(r)
+ case r >= '0' && r <= '9':
+ builder.WriteRune(r)
+ case r == '-', r == '_', r == '.':
+ builder.WriteRune(r)
+ default:
+ builder.WriteRune('-')
+ }
+ }
+ sanitized := strings.Trim(builder.String(), "-")
+ if sanitized == "" {
+ return now.UTC().Format("20060102T150405Z")
+ }
+ return sanitized
+}
+
+type rsyncTenantRuntimeSynchronizer struct{}
+
+func (rsyncTenantRuntimeSynchronizer) Snapshot(ctx context.Context, srcDir, snapshotDir string) error {
+ return runTenantRuntimeRsync(ctx, srcDir, snapshotDir)
+}
+
+func (rsyncTenantRuntimeSynchronizer) Restore(ctx context.Context, snapshotDir, dstDir string) error {
+ return runTenantRuntimeRsync(ctx, snapshotDir, dstDir)
+}
+
+func runTenantRuntimeRsync(ctx context.Context, srcDir, dstDir string) error {
+ srcDir = strings.TrimSpace(srcDir)
+ dstDir = strings.TrimSpace(dstDir)
+ if srcDir == "" || dstDir == "" {
+ return fmt.Errorf("source and destination directories are required")
+ }
+ if err := os.MkdirAll(dstDir, 0o755); err != nil {
+ return fmt.Errorf("create destination dir %s: %w", dstDir, err)
+ }
+ cmd := exec.CommandContext(
+ ctx,
+ "rsync",
+ "-a",
+ "--delete",
+ "--numeric-ids",
+ withTrailingSeparator(srcDir),
+ withTrailingSeparator(dstDir),
+ )
+ output, err := cmd.CombinedOutput()
+ if err != nil {
+ trimmed := strings.TrimSpace(string(output))
+ if trimmed == "" {
+ return fmt.Errorf("rsync %s -> %s: %w", srcDir, dstDir, err)
+ }
+ return fmt.Errorf("rsync %s -> %s: %w: %s", srcDir, dstDir, err, trimmed)
+ }
+ return nil
+}
+
+func withTrailingSeparator(path string) string {
+ cleaned := filepath.Clean(path)
+ if strings.HasSuffix(cleaned, string(os.PathSeparator)) {
+ return cleaned
+ }
+ return cleaned + string(os.PathSeparator)
+}
diff --git a/internal/cloudcp/tenant_runtime_rollout_test.go b/internal/cloudcp/tenant_runtime_rollout_test.go
new file mode 100644
index 0000000000..9d508bfb5e
--- /dev/null
+++ b/internal/cloudcp/tenant_runtime_rollout_test.go
@@ -0,0 +1,382 @@
+package cloudcp
+
+import (
+ "context"
+ "fmt"
+ "testing"
+ "time"
+
+ "github.com/docker/docker/errdefs"
+ cpDocker "github.com/rcourtman/pulse-go-rewrite/internal/cloudcp/docker"
+ "github.com/rcourtman/pulse-go-rewrite/internal/cloudcp/registry"
+)
+
+func TestTenantRuntimeRollout_ReconcilesLiveContainerAlreadyOnTargetImage(t *testing.T) {
+ tenant := &registry.Tenant{ID: "t-ROLLSYNC", ContainerID: "stale-registry-id"}
+ reg := &fakeTenantRuntimeRolloutRegistry{tenant: tenant}
+ docker := newFakeTenantRuntimeRolloutDocker()
+ docker.addContainer(&cpDocker.RuntimeContainerInfo{
+ ID: "live-container",
+ Name: tenantRuntimeContainerName(tenant.ID),
+ ImageRef: "pulse-runtime:target",
+ ImageID: "sha256:target",
+ Running: true,
+ })
+ docker.health["live-container"] = []bool{true}
+ sync := &fakeTenantRuntimeRolloutSynchronizer{}
+ clock := newFakeTenantRuntimeRolloutClock()
+
+ service := newTestTenantRuntimeRolloutService(reg, docker, sync, clock)
+ result, err := service.Rollout(context.Background(), TenantRuntimeRolloutOptions{
+ TenantID: tenant.ID,
+ Image: "pulse-runtime:target",
+ })
+ if err != nil {
+ t.Fatalf("Rollout() error = %v", err)
+ }
+
+ if !result.ReconciledOnly {
+ t.Fatalf("ReconciledOnly = false, want true")
+ }
+ if len(sync.snapshots) != 0 {
+ t.Fatalf("snapshot count = %d, want 0", len(sync.snapshots))
+ }
+ if got := reg.updatedTenant.ContainerID; got != "live-container" {
+ t.Fatalf("updated tenant container id = %q, want live-container", got)
+ }
+ if got := reg.updatedTenant.CurrentImageDigest; got != "sha256:target" {
+ t.Fatalf("updated tenant image digest = %q, want sha256:target", got)
+ }
+ if !reg.updatedTenant.HealthCheckOK {
+ t.Fatalf("updated tenant health_check_ok = false, want true")
+ }
+ if len(docker.createCalls) != 0 {
+ t.Fatalf("create call count = %d, want 0", len(docker.createCalls))
+ }
+}
+
+func TestTenantRuntimeRollout_RollsForwardCanonically(t *testing.T) {
+ tenant := &registry.Tenant{ID: "t-ROLLFWD", ContainerID: "old-container"}
+ reg := &fakeTenantRuntimeRolloutRegistry{tenant: tenant}
+ docker := newFakeTenantRuntimeRolloutDocker()
+ docker.addContainer(&cpDocker.RuntimeContainerInfo{
+ ID: "old-container",
+ Name: tenantRuntimeContainerName(tenant.ID),
+ ImageRef: "pulse-runtime:old",
+ ImageID: "sha256:old",
+ Running: true,
+ })
+ docker.queueCreate(&cpDocker.RuntimeContainerInfo{
+ ID: "new-container",
+ Name: tenantRuntimeContainerName(tenant.ID),
+ ImageRef: "pulse-runtime:new",
+ ImageID: "sha256:new",
+ Running: true,
+ }, nil)
+ docker.health["new-container"] = []bool{true}
+ sync := &fakeTenantRuntimeRolloutSynchronizer{}
+ clock := newFakeTenantRuntimeRolloutClock()
+
+ service := newTestTenantRuntimeRolloutService(reg, docker, sync, clock)
+ result, err := service.Rollout(context.Background(), TenantRuntimeRolloutOptions{
+ TenantID: tenant.ID,
+ Image: "pulse-runtime:new",
+ RunID: "aliasfix",
+ })
+ if err != nil {
+ t.Fatalf("Rollout() error = %v", err)
+ }
+
+ if result.ReconciledOnly {
+ t.Fatalf("ReconciledOnly = true, want false")
+ }
+ if got := result.BackupContainerName; got != "pulse-t-ROLLFWD.pre-aliasfix" {
+ t.Fatalf("backup container name = %q, want pulse-t-ROLLFWD.pre-aliasfix", got)
+ }
+ if len(sync.snapshots) != 1 {
+ t.Fatalf("snapshot count = %d, want 1", len(sync.snapshots))
+ }
+ if len(sync.restores) != 0 {
+ t.Fatalf("restore count = %d, want 0", len(sync.restores))
+ }
+ if got := reg.updatedTenant.ContainerID; got != "new-container" {
+ t.Fatalf("updated tenant container id = %q, want new-container", got)
+ }
+ if got := reg.updatedTenant.CurrentImageDigest; got != "sha256:new" {
+ t.Fatalf("updated tenant image digest = %q, want sha256:new", got)
+ }
+ if len(docker.renameCalls) != 1 {
+ t.Fatalf("rename count = %d, want 1", len(docker.renameCalls))
+ }
+ if docker.renameCalls[0].newName != "pulse-t-ROLLFWD.pre-aliasfix" {
+ t.Fatalf("rename target = %q, want pulse-t-ROLLFWD.pre-aliasfix", docker.renameCalls[0].newName)
+ }
+}
+
+func TestTenantRuntimeRollout_RollsBackOnHealthFailure(t *testing.T) {
+ tenant := &registry.Tenant{ID: "t-ROLLBACK", ContainerID: "old-container"}
+ reg := &fakeTenantRuntimeRolloutRegistry{tenant: tenant}
+ docker := newFakeTenantRuntimeRolloutDocker()
+ docker.addContainer(&cpDocker.RuntimeContainerInfo{
+ ID: "old-container",
+ Name: tenantRuntimeContainerName(tenant.ID),
+ ImageRef: "pulse-runtime:old",
+ ImageID: "sha256:old",
+ Running: true,
+ })
+ docker.queueCreate(&cpDocker.RuntimeContainerInfo{
+ ID: "new-container",
+ Name: tenantRuntimeContainerName(tenant.ID),
+ ImageRef: "pulse-runtime:new",
+ ImageID: "sha256:new",
+ Running: true,
+ }, nil)
+ docker.health["new-container"] = []bool{false, false, false}
+ docker.health["old-container"] = []bool{true}
+ sync := &fakeTenantRuntimeRolloutSynchronizer{}
+ clock := newFakeTenantRuntimeRolloutClock()
+
+ service := newTestTenantRuntimeRolloutService(reg, docker, sync, clock)
+ _, err := service.Rollout(context.Background(), TenantRuntimeRolloutOptions{
+ TenantID: tenant.ID,
+ Image: "pulse-runtime:new",
+ RunID: "rollback",
+ HealthTimeout: 5 * time.Second,
+ })
+ if err == nil {
+ t.Fatalf("Rollout() error = nil, want rollback failure")
+ }
+
+ if len(sync.snapshots) != 1 {
+ t.Fatalf("snapshot count = %d, want 1", len(sync.snapshots))
+ }
+ if len(sync.restores) != 1 {
+ t.Fatalf("restore count = %d, want 1", len(sync.restores))
+ }
+ if got := reg.updatedTenant.ContainerID; got != "old-container" {
+ t.Fatalf("updated tenant container id = %q, want old-container", got)
+ }
+ if got := reg.updatedTenant.CurrentImageDigest; got != "sha256:old" {
+ t.Fatalf("updated tenant image digest = %q, want sha256:old", got)
+ }
+ if len(docker.removeCalls) == 0 || docker.removeCalls[0] != "new-container" {
+ t.Fatalf("remove calls = %v, want new-container removed", docker.removeCalls)
+ }
+ if got := docker.byName[tenantRuntimeContainerName(tenant.ID)]; got == nil || got.ID != "old-container" {
+ t.Fatalf("canonical container after rollback = %#v, want old-container", got)
+ }
+}
+
+func newTestTenantRuntimeRolloutService(
+ reg tenantRuntimeRolloutRegistry,
+ docker tenantRuntimeRolloutDocker,
+ sync tenantRuntimeRolloutSynchronizer,
+ clock *fakeTenantRuntimeRolloutClock,
+) *tenantRuntimeRolloutService {
+ return &tenantRuntimeRolloutService{
+ registry: reg,
+ docker: docker,
+ tenantsDir: tTempDirForRolloutService(),
+ synchronizer: sync,
+ now: clock.Now,
+ sleep: clock.Sleep,
+ healthTimeout: 5 * time.Second,
+ healthPoll: 1 * time.Second,
+ }
+}
+
+func tTempDirForRolloutService() string {
+ return "/tmp/pulse-rollout-tests"
+}
+
+type fakeTenantRuntimeRolloutRegistry struct {
+ tenant *registry.Tenant
+ updatedTenant registry.Tenant
+ updateCount int
+}
+
+func (f *fakeTenantRuntimeRolloutRegistry) Get(tenantID string) (*registry.Tenant, error) {
+ if f.tenant == nil || f.tenant.ID != tenantID {
+ return nil, nil
+ }
+ copy := *f.tenant
+ return &copy, nil
+}
+
+func (f *fakeTenantRuntimeRolloutRegistry) Update(t *registry.Tenant) error {
+ if t == nil {
+ return fmt.Errorf("tenant is nil")
+ }
+ f.updatedTenant = *t
+ f.updateCount++
+ f.tenant = &f.updatedTenant
+ return nil
+}
+
+type fakeTenantRuntimeRolloutSynchronizer struct {
+ snapshots [][2]string
+ restores [][2]string
+}
+
+func (f *fakeTenantRuntimeRolloutSynchronizer) Snapshot(_ context.Context, srcDir, snapshotDir string) error {
+ f.snapshots = append(f.snapshots, [2]string{srcDir, snapshotDir})
+ return nil
+}
+
+func (f *fakeTenantRuntimeRolloutSynchronizer) Restore(_ context.Context, snapshotDir, dstDir string) error {
+ f.restores = append(f.restores, [2]string{snapshotDir, dstDir})
+ return nil
+}
+
+type fakeTenantRuntimeRolloutDocker struct {
+ byID map[string]*cpDocker.RuntimeContainerInfo
+ byName map[string]*cpDocker.RuntimeContainerInfo
+ createQueue []fakeTenantRuntimeCreateResult
+ createCalls []fakeTenantRuntimeCreateCall
+ stopCalls []string
+ startCalls []string
+ removeCalls []string
+ renameCalls []fakeTenantRuntimeRenameCall
+ health map[string][]bool
+}
+
+type fakeTenantRuntimeCreateResult struct {
+ info *cpDocker.RuntimeContainerInfo
+ err error
+}
+
+type fakeTenantRuntimeCreateCall struct {
+ tenantID string
+ tenantDataDir string
+}
+
+type fakeTenantRuntimeRenameCall struct {
+ containerIDOrName string
+ newName string
+}
+
+func newFakeTenantRuntimeRolloutDocker() *fakeTenantRuntimeRolloutDocker {
+ return &fakeTenantRuntimeRolloutDocker{
+ byID: make(map[string]*cpDocker.RuntimeContainerInfo),
+ byName: make(map[string]*cpDocker.RuntimeContainerInfo),
+ health: make(map[string][]bool),
+ }
+}
+
+func (f *fakeTenantRuntimeRolloutDocker) addContainer(info *cpDocker.RuntimeContainerInfo) {
+ copy := *info
+ f.byID[copy.ID] = &copy
+ f.byName[copy.Name] = &copy
+}
+
+func (f *fakeTenantRuntimeRolloutDocker) queueCreate(info *cpDocker.RuntimeContainerInfo, err error) {
+ f.createQueue = append(f.createQueue, fakeTenantRuntimeCreateResult{info: info, err: err})
+}
+
+func (f *fakeTenantRuntimeRolloutDocker) CreateAndStart(_ context.Context, tenantID, tenantDataDir string) (string, error) {
+ f.createCalls = append(f.createCalls, fakeTenantRuntimeCreateCall{tenantID: tenantID, tenantDataDir: tenantDataDir})
+ if len(f.createQueue) == 0 {
+ return "", fmt.Errorf("unexpected CreateAndStart call")
+ }
+ next := f.createQueue[0]
+ f.createQueue = f.createQueue[1:]
+ if next.err != nil {
+ return "", next.err
+ }
+ f.addContainer(next.info)
+ return next.info.ID, nil
+}
+
+func (f *fakeTenantRuntimeRolloutDocker) HealthCheck(_ context.Context, containerID string) (bool, error) {
+ if sequence, ok := f.health[containerID]; ok {
+ if len(sequence) == 0 {
+ return false, nil
+ }
+ next := sequence[0]
+ f.health[containerID] = sequence[1:]
+ return next, nil
+ }
+ info, ok := f.byID[containerID]
+ if !ok {
+ return false, errdefs.NotFound(fmt.Errorf("missing container %s", containerID))
+ }
+ return info.Running, nil
+}
+
+func (f *fakeTenantRuntimeRolloutDocker) Inspect(_ context.Context, containerIDOrName string) (*cpDocker.RuntimeContainerInfo, error) {
+ if info, ok := f.byID[containerIDOrName]; ok {
+ copy := *info
+ return &copy, nil
+ }
+ if info, ok := f.byName[containerIDOrName]; ok {
+ copy := *info
+ return &copy, nil
+ }
+ return nil, errdefs.NotFound(fmt.Errorf("missing container %s", containerIDOrName))
+}
+
+func (f *fakeTenantRuntimeRolloutDocker) Remove(_ context.Context, containerID string) error {
+ f.removeCalls = append(f.removeCalls, containerID)
+ info, ok := f.byID[containerID]
+ if !ok {
+ if infoByName, okByName := f.byName[containerID]; okByName {
+ info = infoByName
+ ok = true
+ }
+ }
+ if !ok {
+ return errdefs.NotFound(fmt.Errorf("missing container %s", containerID))
+ }
+ delete(f.byID, info.ID)
+ delete(f.byName, info.Name)
+ return nil
+}
+
+func (f *fakeTenantRuntimeRolloutDocker) Rename(_ context.Context, containerIDOrName, newName string) error {
+ f.renameCalls = append(f.renameCalls, fakeTenantRuntimeRenameCall{containerIDOrName: containerIDOrName, newName: newName})
+ info, err := f.Inspect(context.Background(), containerIDOrName)
+ if err != nil {
+ return err
+ }
+ stored := f.byID[info.ID]
+ delete(f.byName, stored.Name)
+ stored.Name = newName
+ f.byName[newName] = stored
+ return nil
+}
+
+func (f *fakeTenantRuntimeRolloutDocker) Start(_ context.Context, containerID string) error {
+ f.startCalls = append(f.startCalls, containerID)
+ info, err := f.Inspect(context.Background(), containerID)
+ if err != nil {
+ return err
+ }
+ f.byID[info.ID].Running = true
+ return nil
+}
+
+func (f *fakeTenantRuntimeRolloutDocker) Stop(_ context.Context, containerID string) error {
+ f.stopCalls = append(f.stopCalls, containerID)
+ info, err := f.Inspect(context.Background(), containerID)
+ if err != nil {
+ return err
+ }
+ f.byID[info.ID].Running = false
+ return nil
+}
+
+type fakeTenantRuntimeRolloutClock struct {
+ now time.Time
+}
+
+func newFakeTenantRuntimeRolloutClock() *fakeTenantRuntimeRolloutClock {
+ return &fakeTenantRuntimeRolloutClock{now: time.Unix(1_700_000_000, 0).UTC()}
+}
+
+func (c *fakeTenantRuntimeRolloutClock) Now() time.Time {
+ return c.now
+}
+
+func (c *fakeTenantRuntimeRolloutClock) Sleep(duration time.Duration) {
+ c.now = c.now.Add(duration)
+}
diff --git a/scripts/release_control/subsystem_lookup_test.py b/scripts/release_control/subsystem_lookup_test.py
index b095d821f9..5c12b05621 100644
--- a/scripts/release_control/subsystem_lookup_test.py
+++ b/scripts/release_control/subsystem_lookup_test.py
@@ -4334,6 +4334,34 @@ class SubsystemLookupTest(unittest.TestCase):
],
)
+ def test_lookup_paths_assigns_control_plane_rollout_command_to_deployment_installability(self) -> None:
+ result = lookup_paths(["cmd/pulse-control-plane/main.go"])
+ self.assertEqual(result["unowned_runtime_files"], [])
+ self.assertEqual(
+ {item["subsystem"] for item in result["impacted_subsystems"]},
+ {"deployment-installability"},
+ )
+ file_entry = result["files"][0]
+ self.assertEqual(file_entry["classification"], "runtime")
+ self.assertEqual(
+ {match["subsystem"] for match in file_entry["matches"]},
+ {"deployment-installability"},
+ )
+ match = file_entry["matches"][0]
+ self.assertEqual(
+ match["contract"],
+ "docs/release-control/v6/internal/subsystems/deployment-installability.md",
+ )
+ self.assertEqual(match["lane_context"]["lane_id"], "L1")
+ self.assertEqual(
+ match["verification_requirement"]["id"],
+ "hosted-runtime-rollout-control",
+ )
+ self.assertEqual(
+ match["verification_requirement"]["exact_files"],
+ ["internal/cloudcp/tenant_runtime_rollout_test.go"],
+ )
+
def test_lookup_paths_normalizes_absolute_repo_paths(self) -> None:
absolute = str(Path(REPO_ROOT, "internal/api/resources.go"))
result = lookup_paths([absolute])