Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rock/sandbox/operator/k8s/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ class K8sConstants:
# Nacos config keys
NACOS_POOLS_KEY = "pools"
NACOS_TEMPLATE_RULES_KEY = "template_rules"
K8S_ALIVE_CHECK_SWITCH = "k8s_alive_check_enabled"
17 changes: 12 additions & 5 deletions rock/sandbox/operator/k8s/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ async def get_status(self, sandbox_id: str) -> SandboxInfo:

This method fetches the sandbox resource from K8s and checks if the sandbox
is alive by calling its is_alive endpoint. The state is determined by:
- RUNNING: IP allocated AND is_alive returns true
- PENDING: IP not allocated OR is_alive returns false
- RUNNING: alive check disabled OR IP allocated AND is_alive returns true
- PENDING: alive check enabled AND (IP not allocated OR is_alive returns false)

Args:
sandbox_id: Sandbox identifier
Expand All @@ -449,9 +449,16 @@ async def get_status(self, sandbox_id: str) -> SandboxInfo:
# Get host_ip, port_mapping and resource_version
host_ip, port_mapping, resource_version = await self._get_sandbox_runtime_info(sandbox_id)

# Check is_alive through runtime
is_alive = False
if host_ip:
# Check is_alive through runtime unless disabled by Nacos
check_alive_enabled = True
if self._nacos_provider:
check_alive_enabled = await self._nacos_provider.get_switch_status(
K8sConstants.K8S_ALIVE_CHECK_SWITCH,
True,
)

is_alive = not check_alive_enabled
if check_alive_enabled and host_ip:
runtime = self._build_runtime(host_ip, port_mapping)
try:
is_alive_response = await runtime.is_alive()
Expand Down
Loading