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.

Canonicalize hosted tenant routing addresses

rcourtman04589391498a
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index e8b403ff10..fbb0137be1 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -25,42 +25,43 @@ server-side update execution surfaces.
3. `frontend-modern/src/api/updates.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`
+6. `internal/cloudcp/docker/labels.go`
+7. `internal/cloudcp/tenant_runtime_rollout.go`
+8. `.github/workflows/create-release.yml`
+9. `.github/workflows/deploy-demo-server.yml`
+10. `.github/workflows/helm-pages.yml`
+11. `.github/workflows/promote-floating-tags.yml`
+12. `.github/workflows/publish-docker.yml`
+13. `.github/workflows/publish-helm-chart.yml`
+14. `.github/workflows/release-dry-run.yml`
+15. `.github/workflows/update-demo-server.yml`
+16. `docs/releases/V6_PRERELEASE_RUNBOOK.md`
+17. `package.json`
+18. `frontend-modern/package.json`
+19. `scripts/build-release.sh`
+20. `scripts/check-workflow-dispatch-inputs.py`
+21. `scripts/clean-mock-alerts.sh`
+22. `scripts/com.pulse.hot-dev.plist.template`
+23. `scripts/dev-check.sh`
+24. `scripts/dev-launchd-setup.sh`
+25. `scripts/dev-launchd-wrapper.sh`
+26. `scripts/hot-dev-bg.sh`
+27. `scripts/hot-dev.sh`
+28. `scripts/install-container-agent.sh`
+29. `scripts/install.ps1`
+30. `scripts/install.sh`
+31. `scripts/pulse-auto-update.sh`
+32. `scripts/release_control/resolve_release_promotion.py`
+33. `scripts/release_ldflags.sh`
+34. `scripts/trigger-release-dry-run.sh`
+35. `scripts/trigger-release.sh`
+36. `scripts/toggle-mock.sh`
+37. `tests/integration/playwright.config.ts`
+38. `tests/integration/QUICK_START.md`
+39. `tests/integration/README.md`
+40. `tests/integration/scripts/managed-dev-runtime.mjs`
+41. `tests/integration/tests/helpers.ts`
+42. `tests/integration/tests/runtime-defaults.ts`
## Shared Boundaries
@@ -78,7 +79,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`
+8. Add or change operator-facing hosted tenant runtime canary rollout, canonical hosted route/public URL generation, or control-plane runtime-registry reconciliation through `cmd/pulse-control-plane/main.go`, `internal/cloudcp/docker/manager.go`, `internal/cloudcp/docker/labels.go`, and `internal/cloudcp/tenant_runtime_rollout.go`
## Forbidden Paths
@@ -201,6 +202,14 @@ local demos. `scripts/toggle-mock.sh` must seed the same `PULSE_MOCK_*`
defaults as `internal/mock.DefaultConfig`, so managed runtime toggles, local
demo restarts, and CLI mock status all converge on one canonical dataset
instead of drifting across shell helpers.
+That same hosted runtime rollout boundary also owns public routing identity for
+managed tenants. `internal/cloudcp/docker/labels.go`,
+`internal/cloudcp/docker/manager.go`, and
+`internal/cloudcp/tenant_runtime_rollout.go` must derive one canonical hosted
+route host and `PULSE_PUBLIC_URL`, keep that addressing lowercase-safe for
+mixed-case tenant IDs, and treat same-image runtime routing drift as rollout
+drift that requires a canonical recreate rather than silently reconciling the
+registry against stale Traefik labels or runtime env.
That same rule applies to live runtime behavior too: config loading and reload
watching may not treat `mock.env` as a parallel primary-path control surface.
Supported mock-mode runtime state must come from the canonical `.env` contract,
diff --git a/docs/release-control/v6/internal/subsystems/registry.json b/docs/release-control/v6/internal/subsystems/registry.json
index c8f6beb389..5b92f939e6 100644
--- a/docs/release-control/v6/internal/subsystems/registry.json
+++ b/docs/release-control/v6/internal/subsystems/registry.json
@@ -2271,6 +2271,7 @@
"frontend-modern/package.json",
"frontend-modern/src/api/updates.ts",
"internal/api/updates.go",
+ "internal/cloudcp/docker/labels.go",
"internal/cloudcp/docker/manager.go",
"internal/cloudcp/tenant_runtime_rollout.go",
"Makefile",
@@ -2400,6 +2401,7 @@
"match_prefixes": [],
"match_files": [
"cmd/pulse-control-plane/main.go",
+ "internal/cloudcp/docker/labels.go",
"internal/cloudcp/docker/manager.go",
"internal/cloudcp/tenant_runtime_rollout.go"
],
diff --git a/internal/cloudcp/docker/labels.go b/internal/cloudcp/docker/labels.go
index fdf981cc4f..7e9a79f8e8 100644
--- a/internal/cloudcp/docker/labels.go
+++ b/internal/cloudcp/docker/labels.go
@@ -1,18 +1,44 @@
package docker
-import "fmt"
+import (
+ "fmt"
+ "strings"
+)
+
+// TenantRuntimeRoutingContract is the canonical hosted-runtime addressing
+// surface derived from a tenant ID and base domain.
+type TenantRuntimeRoutingContract struct {
+ Host string
+ PublicURL string
+}
+
+// CanonicalTenantRuntimeRouting derives the canonical hosted route host and
+// public URL. Hosted routing must stay lowercase regardless of how the tenant
+// ID is cased in control-plane storage.
+func CanonicalTenantRuntimeRouting(tenantID, baseDomain string) TenantRuntimeRoutingContract {
+ tenantID = strings.ToLower(strings.TrimSpace(tenantID))
+ baseDomain = strings.ToLower(strings.TrimSpace(baseDomain))
+ if tenantID == "" || baseDomain == "" {
+ return TenantRuntimeRoutingContract{}
+ }
+ host := fmt.Sprintf("%s.%s", tenantID, baseDomain)
+ return TenantRuntimeRoutingContract{
+ Host: host,
+ PublicURL: "https://" + host,
+ }
+}
// TraefikLabels generates Docker labels for Traefik reverse-proxy routing.
// Each tenant gets a subdomain: <tenantID>.cloud.pulserelay.pro
func TraefikLabels(tenantID, baseDomain string, containerPort int) map[string]string {
svc := "pulse-" + tenantID
- host := fmt.Sprintf("%s.%s", tenantID, baseDomain)
+ routing := CanonicalTenantRuntimeRouting(tenantID, baseDomain)
return map[string]string{
"traefik.enable": "true",
// HTTP router
- fmt.Sprintf("traefik.http.routers.%s.rule", svc): fmt.Sprintf("Host(`%s`)", host),
+ fmt.Sprintf("traefik.http.routers.%s.rule", svc): fmt.Sprintf("Host(`%s`)", routing.Host),
fmt.Sprintf("traefik.http.routers.%s.entrypoints", svc): "websecure",
fmt.Sprintf("traefik.http.routers.%s.tls.certresolver", svc): "le",
diff --git a/internal/cloudcp/docker/manager.go b/internal/cloudcp/docker/manager.go
index f9ab354537..71309965c1 100644
--- a/internal/cloudcp/docker/manager.go
+++ b/internal/cloudcp/docker/manager.go
@@ -41,11 +41,13 @@ type Manager struct {
// 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
+ ID string
+ Name string
+ ImageRef string
+ ImageID string
+ Running bool
+ RouteHost string
+ PublicURL string
}
const immutableOwnershipPathsEnv = "PULSE_IMMUTABLE_OWNERSHIP_PATHS"
@@ -75,6 +77,15 @@ func (m *Manager) Close() error {
return nil
}
+// DesiredRuntimeRouting returns the canonical hosted route/public URL contract
+// for a tenant on this manager's configured base domain.
+func (m *Manager) DesiredRuntimeRouting(tenantID string) TenantRuntimeRoutingContract {
+ if m == nil {
+ return TenantRuntimeRoutingContract{}
+ }
+ return CanonicalTenantRuntimeRouting(tenantID, m.cfg.BaseDomain)
+}
+
// IsNotFound reports whether Docker treated an identifier as missing.
func IsNotFound(err error) bool {
return errdefs.IsNotFound(err)
@@ -160,12 +171,8 @@ func tenantRuntimeOwnershipPaths() []string {
}
func tenantEnv(tenantID, baseDomain, trialActivationPublicKey string, trustedProxyCIDRs []string) []string {
- publicURL := ""
+ routing := CanonicalTenantRuntimeRouting(tenantID, baseDomain)
tenantID = strings.TrimSpace(tenantID)
- baseDomain = strings.TrimSpace(baseDomain)
- if tenantID != "" && baseDomain != "" {
- publicURL = fmt.Sprintf("https://%s.%s", tenantID, baseDomain)
- }
env := []string{
"PULSE_DATA_DIR=/etc/pulse",
@@ -176,8 +183,8 @@ func tenantEnv(tenantID, baseDomain, trialActivationPublicKey string, trustedPro
fmt.Sprintf("PGID=%d", tenantRuntimeGID),
fmt.Sprintf("%s=%s", immutableOwnershipPathsEnv, strings.Join(tenantImmutableOwnershipPaths(), ":")),
}
- if publicURL != "" {
- env = append(env, "PULSE_PUBLIC_URL="+publicURL)
+ if routing.PublicURL != "" {
+ env = append(env, "PULSE_PUBLIC_URL="+routing.PublicURL)
}
if strings.TrimSpace(trialActivationPublicKey) != "" {
env = append(env, "PULSE_TRIAL_ACTIVATION_PUBLIC_KEY="+strings.TrimSpace(trialActivationPublicKey))
@@ -188,6 +195,37 @@ func tenantEnv(tenantID, baseDomain, trialActivationPublicKey string, trustedPro
return env
}
+func routeHostFromLabels(labels map[string]string) string {
+ for key, value := range labels {
+ if !strings.HasPrefix(key, "traefik.http.routers.") || !strings.HasSuffix(key, ".rule") {
+ continue
+ }
+ if host := parseTraefikHostRule(value); host != "" {
+ return host
+ }
+ }
+ return ""
+}
+
+func parseTraefikHostRule(rule string) string {
+ rule = strings.TrimSpace(rule)
+ if !strings.HasPrefix(rule, "Host(`") || !strings.HasSuffix(rule, "`)") {
+ return ""
+ }
+ return strings.TrimSuffix(strings.TrimPrefix(rule, "Host(`"), "`)")
+}
+
+func envValue(env []string, key string) string {
+ prefix := key + "="
+ for _, item := range env {
+ if !strings.HasPrefix(item, prefix) {
+ continue
+ }
+ return strings.TrimPrefix(item, prefix)
+ }
+ return ""
+}
+
func (m *Manager) tenantTrustedProxyCIDRs(ctx context.Context) []string {
values := make([]string, 0, len(m.cfg.TrustedProxyCIDRs)+1)
seen := make(map[string]struct{})
@@ -320,12 +358,20 @@ func (m *Manager) Inspect(ctx context.Context, containerIDOrName string) (*Runti
imageRef = strings.TrimSpace(inspect.Config.Image)
}
running := inspect.State != nil && inspect.State.Running
+ routeHost := ""
+ publicURL := ""
+ if inspect.Config != nil {
+ routeHost = routeHostFromLabels(inspect.Config.Labels)
+ publicURL = envValue(inspect.Config.Env, "PULSE_PUBLIC_URL")
+ }
return &RuntimeContainerInfo{
- ID: inspect.ID,
- Name: strings.TrimPrefix(strings.TrimSpace(inspect.Name), "/"),
- ImageRef: imageRef,
- ImageID: strings.TrimSpace(inspect.Image),
- Running: running,
+ ID: inspect.ID,
+ Name: strings.TrimPrefix(strings.TrimSpace(inspect.Name), "/"),
+ ImageRef: imageRef,
+ ImageID: strings.TrimSpace(inspect.Image),
+ Running: running,
+ RouteHost: routeHost,
+ PublicURL: publicURL,
}, nil
}
diff --git a/internal/cloudcp/docker/manager_test.go b/internal/cloudcp/docker/manager_test.go
index 8b726ccf1d..3edec836c9 100644
--- a/internal/cloudcp/docker/manager_test.go
+++ b/internal/cloudcp/docker/manager_test.go
@@ -93,6 +93,41 @@ func TestTenantEnvIncludesImmutableOwnershipContract(t *testing.T) {
}
}
+func TestCanonicalTenantRuntimeRoutingLowercasesHostedAddressing(t *testing.T) {
+ t.Parallel()
+
+ got := CanonicalTenantRuntimeRouting("T-AbCd123", "Cloud.PulseRelay.Pro")
+ if got.Host != "t-abcd123.cloud.pulserelay.pro" {
+ t.Fatalf("Host = %q, want %q", got.Host, "t-abcd123.cloud.pulserelay.pro")
+ }
+ if got.PublicURL != "https://t-abcd123.cloud.pulserelay.pro" {
+ t.Fatalf("PublicURL = %q, want %q", got.PublicURL, "https://t-abcd123.cloud.pulserelay.pro")
+ }
+}
+
+func TestTraefikLabelsUseCanonicalLowercaseHost(t *testing.T) {
+ t.Parallel()
+
+ labels := TraefikLabels("T-AbCd123", "Cloud.PulseRelay.Pro", 7655)
+ got := labels["traefik.http.routers.pulse-T-AbCd123.rule"]
+ if got != "Host(`t-abcd123.cloud.pulserelay.pro`)" {
+ t.Fatalf("router rule = %q, want %q", got, "Host(`t-abcd123.cloud.pulserelay.pro`)")
+ }
+}
+
+func TestTenantEnvLowercasesPublicURLHost(t *testing.T) {
+ t.Parallel()
+
+ env := tenantEnv("T-AbCd123", "Cloud.PulseRelay.Pro", "", nil)
+ want := "PULSE_PUBLIC_URL=https://t-abcd123.cloud.pulserelay.pro"
+ for _, item := range env {
+ if item == want {
+ return
+ }
+ }
+ t.Fatalf("tenantEnv() missing %q in %v", want, env)
+}
+
func TestTenantEnvOmitsPublicURLWithoutTenantContext(t *testing.T) {
t.Parallel()
diff --git a/internal/cloudcp/tenant_runtime_rollout.go b/internal/cloudcp/tenant_runtime_rollout.go
index 7c24786c48..418c0069c1 100644
--- a/internal/cloudcp/tenant_runtime_rollout.go
+++ b/internal/cloudcp/tenant_runtime_rollout.go
@@ -52,6 +52,7 @@ type tenantRuntimeRolloutRegistry interface {
type tenantRuntimeRolloutDocker interface {
CreateAndStart(ctx context.Context, tenantID, tenantDataDir string) (string, error)
+ DesiredRuntimeRouting(tenantID string) cpDocker.TenantRuntimeRoutingContract
HealthCheck(ctx context.Context, containerID string) (bool, error)
Inspect(ctx context.Context, containerIDOrName string) (*cpDocker.RuntimeContainerInfo, error)
Remove(ctx context.Context, containerID string) error
@@ -178,7 +179,8 @@ func (s *tenantRuntimeRolloutService) Rollout(ctx context.Context, opts TenantRu
}
canonicalName := tenantRuntimeContainerName(tenantID)
- if live.Name == canonicalName && live.ImageRef == image {
+ desiredRouting := s.docker.DesiredRuntimeRouting(tenantID)
+ if tenantRuntimeMatchesContract(live, canonicalName, image, desiredRouting) {
healthy, err := s.waitForHealth(ctx, live.ID, healthTimeout, healthPoll)
if err == nil {
if updateErr := s.persistTenantRuntimeState(tenant, live, healthy); updateErr != nil {
@@ -198,6 +200,15 @@ func (s *tenantRuntimeRolloutService) Rollout(ctx context.Context, opts TenantRu
Str("tenant_id", tenantID).
Str("container_id", live.ID).
Msg("Live tenant container already matches requested image but failed health sync; recreating canonically")
+ } else if live.Name == canonicalName && live.ImageRef == image {
+ log.Warn().
+ Str("tenant_id", tenantID).
+ Str("container_id", live.ID).
+ Str("live_route_host", live.RouteHost).
+ Str("desired_route_host", desiredRouting.Host).
+ Str("live_public_url", live.PublicURL).
+ Str("desired_public_url", desiredRouting.PublicURL).
+ Msg("Live tenant container already matches requested image but runtime routing drifted; recreating canonically")
}
tenantDataDir := filepath.Join(s.tenantsDir, tenantID)
@@ -299,6 +310,21 @@ func (s *tenantRuntimeRolloutService) Rollout(ctx context.Context, opts TenantRu
}, nil
}
+func tenantRuntimeMatchesContract(
+ live *cpDocker.RuntimeContainerInfo,
+ canonicalName string,
+ image string,
+ desiredRouting cpDocker.TenantRuntimeRoutingContract,
+) bool {
+ if live == nil {
+ return false
+ }
+ if live.Name != canonicalName || live.ImageRef != image {
+ return false
+ }
+ return live.RouteHost == desiredRouting.Host && live.PublicURL == desiredRouting.PublicURL
+}
+
func (s *tenantRuntimeRolloutService) resolveLiveContainer(ctx context.Context, tenant *registry.Tenant) (*cpDocker.RuntimeContainerInfo, error) {
if tenant == nil {
return nil, fmt.Errorf("tenant is nil")
diff --git a/internal/cloudcp/tenant_runtime_rollout_test.go b/internal/cloudcp/tenant_runtime_rollout_test.go
index aebca658db..c7b76322d6 100644
--- a/internal/cloudcp/tenant_runtime_rollout_test.go
+++ b/internal/cloudcp/tenant_runtime_rollout_test.go
@@ -17,12 +17,15 @@ func TestTenantRuntimeRollout_ReconcilesLiveContainerAlreadyOnTargetImage(t *tes
tenant := &registry.Tenant{ID: "t-ROLLSYNC", ContainerID: "stale-registry-id"}
reg := &fakeTenantRuntimeRolloutRegistry{tenant: tenant}
docker := newFakeTenantRuntimeRolloutDocker()
+ routing := docker.DesiredRuntimeRouting(tenant.ID)
docker.addContainer(&cpDocker.RuntimeContainerInfo{
- ID: "live-container",
- Name: tenantRuntimeContainerName(tenant.ID),
- ImageRef: "pulse-runtime:target",
- ImageID: "sha256:target",
- Running: true,
+ ID: "live-container",
+ Name: tenantRuntimeContainerName(tenant.ID),
+ ImageRef: "pulse-runtime:target",
+ ImageID: "sha256:target",
+ Running: true,
+ RouteHost: routing.Host,
+ PublicURL: routing.PublicURL,
})
docker.health["live-container"] = []bool{true}
sync := &fakeTenantRuntimeRolloutSynchronizer{}
@@ -61,19 +64,24 @@ func TestTenantRuntimeRollout_RollsForwardCanonically(t *testing.T) {
tenant := &registry.Tenant{ID: "t-ROLLFWD", ContainerID: "old-container"}
reg := &fakeTenantRuntimeRolloutRegistry{tenant: tenant}
docker := newFakeTenantRuntimeRolloutDocker()
+ routing := docker.DesiredRuntimeRouting(tenant.ID)
docker.addContainer(&cpDocker.RuntimeContainerInfo{
- ID: "old-container",
- Name: tenantRuntimeContainerName(tenant.ID),
- ImageRef: "pulse-runtime:old",
- ImageID: "sha256:old",
- Running: true,
+ ID: "old-container",
+ Name: tenantRuntimeContainerName(tenant.ID),
+ ImageRef: "pulse-runtime:old",
+ ImageID: "sha256:old",
+ Running: true,
+ RouteHost: routing.Host,
+ PublicURL: routing.PublicURL,
})
docker.queueCreate(&cpDocker.RuntimeContainerInfo{
- ID: "new-container",
- Name: tenantRuntimeContainerName(tenant.ID),
- ImageRef: "pulse-runtime:new",
- ImageID: "sha256:new",
- Running: true,
+ ID: "new-container",
+ Name: tenantRuntimeContainerName(tenant.ID),
+ ImageRef: "pulse-runtime:new",
+ ImageID: "sha256:new",
+ Running: true,
+ RouteHost: routing.Host,
+ PublicURL: routing.PublicURL,
}, nil)
docker.health["new-container"] = []bool{true}
sync := &fakeTenantRuntimeRolloutSynchronizer{}
@@ -119,19 +127,24 @@ func TestTenantRuntimeRollout_RollsBackOnHealthFailure(t *testing.T) {
tenant := &registry.Tenant{ID: "t-ROLLBACK", ContainerID: "old-container"}
reg := &fakeTenantRuntimeRolloutRegistry{tenant: tenant}
docker := newFakeTenantRuntimeRolloutDocker()
+ routing := docker.DesiredRuntimeRouting(tenant.ID)
docker.addContainer(&cpDocker.RuntimeContainerInfo{
- ID: "old-container",
- Name: tenantRuntimeContainerName(tenant.ID),
- ImageRef: "pulse-runtime:old",
- ImageID: "sha256:old",
- Running: true,
+ ID: "old-container",
+ Name: tenantRuntimeContainerName(tenant.ID),
+ ImageRef: "pulse-runtime:old",
+ ImageID: "sha256:old",
+ Running: true,
+ RouteHost: routing.Host,
+ PublicURL: routing.PublicURL,
})
docker.queueCreate(&cpDocker.RuntimeContainerInfo{
- ID: "new-container",
- Name: tenantRuntimeContainerName(tenant.ID),
- ImageRef: "pulse-runtime:new",
- ImageID: "sha256:new",
- Running: true,
+ ID: "new-container",
+ Name: tenantRuntimeContainerName(tenant.ID),
+ ImageRef: "pulse-runtime:new",
+ ImageID: "sha256:new",
+ Running: true,
+ RouteHost: routing.Host,
+ PublicURL: routing.PublicURL,
}, nil)
docker.health["new-container"] = []bool{false, false, false}
docker.health["old-container"] = []bool{true}
@@ -238,6 +251,60 @@ func TestFilesystemTenantRuntimeSynchronizer_SnapshotAndRestore(t *testing.T) {
}
}
+func TestTenantRuntimeRollout_RecreatesSameImageWhenRoutingContractDrifts(t *testing.T) {
+ tenant := &registry.Tenant{ID: "t-MixedCase", ContainerID: "live-container"}
+ 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,
+ RouteHost: "t-MixedCase.cloud.pulserelay.pro",
+ PublicURL: "https://t-MixedCase.cloud.pulserelay.pro",
+ })
+ routing := docker.DesiredRuntimeRouting(tenant.ID)
+ docker.queueCreate(&cpDocker.RuntimeContainerInfo{
+ ID: "new-container",
+ Name: tenantRuntimeContainerName(tenant.ID),
+ ImageRef: "pulse-runtime:target",
+ ImageID: "sha256:target",
+ Running: true,
+ RouteHost: routing.Host,
+ PublicURL: routing.PublicURL,
+ }, 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:target",
+ RunID: "routingfix",
+ })
+ if err != nil {
+ t.Fatalf("Rollout() error = %v", err)
+ }
+
+ if result.ReconciledOnly {
+ t.Fatalf("ReconciledOnly = true, want false")
+ }
+ if len(docker.createCalls) != 1 {
+ t.Fatalf("create call count = %d, want 1", len(docker.createCalls))
+ }
+ 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:target" {
+ t.Fatalf("updated tenant image digest = %q, want sha256:target", got)
+ }
+ if len(sync.snapshots) != 1 {
+ t.Fatalf("snapshot count = %d, want 1", len(sync.snapshots))
+ }
+}
+
func newTestTenantRuntimeRolloutService(
reg tenantRuntimeRolloutRegistry,
docker tenantRuntimeRolloutDocker,
@@ -300,6 +367,7 @@ func (f *fakeTenantRuntimeRolloutSynchronizer) Restore(_ context.Context, snapsh
}
type fakeTenantRuntimeRolloutDocker struct {
+ baseDomain string
byID map[string]*cpDocker.RuntimeContainerInfo
byName map[string]*cpDocker.RuntimeContainerInfo
createQueue []fakeTenantRuntimeCreateResult
@@ -328,9 +396,10 @@ type fakeTenantRuntimeRenameCall struct {
func newFakeTenantRuntimeRolloutDocker() *fakeTenantRuntimeRolloutDocker {
return &fakeTenantRuntimeRolloutDocker{
- byID: make(map[string]*cpDocker.RuntimeContainerInfo),
- byName: make(map[string]*cpDocker.RuntimeContainerInfo),
- health: make(map[string][]bool),
+ baseDomain: "cloud.pulserelay.pro",
+ byID: make(map[string]*cpDocker.RuntimeContainerInfo),
+ byName: make(map[string]*cpDocker.RuntimeContainerInfo),
+ health: make(map[string][]bool),
}
}
@@ -358,6 +427,10 @@ func (f *fakeTenantRuntimeRolloutDocker) CreateAndStart(_ context.Context, tenan
return next.info.ID, nil
}
+func (f *fakeTenantRuntimeRolloutDocker) DesiredRuntimeRouting(tenantID string) cpDocker.TenantRuntimeRoutingContract {
+ return cpDocker.CanonicalTenantRuntimeRouting(tenantID, f.baseDomain)
+}
+
func (f *fakeTenantRuntimeRolloutDocker) HealthCheck(_ context.Context, containerID string) (bool, error) {
if sequence, ok := f.health[containerID]; ok {
if len(sequence) == 0 {