Skip to content

Commit c1e70a1

Browse files
committed
bootstrap: register a managed realm in the ecosystem on first boot
A managed realm's child core only registered on the hourly telemetry loop, so it stayed PROVISIONING for up to an hour and raced the ecosystem's provisioning timeout. Register in the ecosystem right after bootstrap (best-effort; the telemetry loop remains the retrying fallback).
1 parent e89e0c5 commit c1e70a1

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

exordos_core/bootstrap/defaults.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import typing as tp
2323
import uuid as sys_uuid
2424

25+
import bazooka
2526
from gcl_sdk.infra.dm import models as infra_models
2627
from restalchemy.dm import filters as dm_filters
2728
from restalchemy.storage import exceptions as ra_exceptions
@@ -673,3 +674,36 @@ def set_iam_default_client_secret_var(spec: dict) -> bool:
673674
spec["iam"]["default_client_secret"],
674675
c.VAR_IAM_DEFAULT_CLIENT_SECRET_UUID,
675676
)
677+
678+
679+
def register_realm_in_ecosystem(spec: dict[str, tp.Any]) -> bool:
680+
"""Self-register this realm in the ecosystem right after bootstrap.
681+
682+
Without this the first registration happens on the telemetry loop
683+
(hourly), so a managed realm stays PROVISIONING for up to an hour
684+
and races the ecosystem's provisioning timeout. Best-effort: the
685+
telemetry loop remains the retrying fallback, so a failure here
686+
must not fail the bootstrap.
687+
"""
688+
endpoint = spec.get("ecosystem_endpoint", "")
689+
realm_uuid = spec.get("realm_uuid", "")
690+
realm_secret = spec.get("realm_secret", "")
691+
if not (endpoint and realm_uuid and realm_secret):
692+
LOG.info("No realm identity in spec, skipping realm registration")
693+
return True
694+
695+
url = f"{endpoint.rstrip('/')}/api/ecosystem/v1/realms/"
696+
try:
697+
client = bazooka.Client(default_timeout=30)
698+
client.post(
699+
url,
700+
json={"uuid": realm_uuid, "secret": realm_secret},
701+
headers={"Content-Type": "application/json"},
702+
)
703+
LOG.info("Realm %s registered in ecosystem", realm_uuid)
704+
except Exception:
705+
LOG.exception(
706+
"Failed to register realm in ecosystem (the telemetry "
707+
"service will retry hourly)"
708+
)
709+
return True

exordos_core/cmd/bootstrap.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ def _set_defaults_vs(spec: dict[str, tp.Any]):
327327
{"func": bootstrap_defaults.set_realm_secret_var, "args": [spec]},
328328
{"func": bootstrap_defaults.set_realm_access_token_var, "args": [spec]},
329329
{"func": bootstrap_defaults.set_realm_refresh_token_var, "args": [spec]},
330+
# Register in the ecosystem right away: waiting for the hourly
331+
# telemetry loop leaves a managed realm PROVISIONING for up to an
332+
# hour, racing the ecosystem's provisioning timeout.
333+
{"func": bootstrap_defaults.register_realm_in_ecosystem, "args": [spec]},
330334
{
331335
"func": bootstrap_defaults.set_hs256_jwks_encryption_key_var,
332336
"args": [CONF["iam"].hs256_jwks_encryption_key],

0 commit comments

Comments
 (0)