fix(vps): extend import timeout to 1h and stop ongoing CDI tasks on timeout
Build and publish Docker image / build-and-publish (push) Successful in 2m31s
Build and publish Docker image / build-and-publish (push) Successful in 2m31s
This commit is contained in:
1 parent
6732ee9d47
commit
4c2f5f2c01
3 files changed
+99
-5
No files matched your search
@@ -104,6 +104,17 @@ def delete_server(server_id: str, user_id: str) -> bool:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
custom_objects_api.delete_namespaced_custom_object(
|
||||
group="cdi.kubevirt.io",
|
||||
version="v1beta1",
|
||||
namespace=namespace,
|
||||
plural="datavolumes",
|
||||
name=f"{server_id}-rootdisk"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if delete_server_record(server_id):
|
||||
# Removed refund logic
|
||||
pass
|
||||
|
||||
+87
-4
@@ -984,7 +984,7 @@ final_message: "AnchorHost VPS ready! User: {image_config['user']}, Password: {i
|
||||
if progress_callback:
|
||||
progress_callback('Allocating storage', 5, 'Allocating storage for the system image.')
|
||||
|
||||
max_wait = 600
|
||||
max_wait = 3600 # 1 hour timeout for system image download and import
|
||||
wait_interval = 5
|
||||
elapsed = 0
|
||||
latest_progress = 12
|
||||
@@ -1045,6 +1045,24 @@ final_message: "AnchorHost VPS ready! User: {image_config['user']}, Password: {i
|
||||
elif phase == 'Failed':
|
||||
error_message = status.get('conditions', [{}])[0].get('message', 'Unknown error') if status.get('conditions') else 'Unknown error'
|
||||
logger.error(f"VPS system image import failed: {error_message}")
|
||||
try:
|
||||
logger.info(f"🛑 Cleaning up failed DataVolume {data_volume_name}...")
|
||||
custom_objects_api.delete_namespaced_custom_object(
|
||||
group="cdi.kubevirt.io",
|
||||
version="v1beta1",
|
||||
namespace=namespace,
|
||||
plural="datavolumes",
|
||||
name=data_volume_name
|
||||
)
|
||||
except Exception as del_err:
|
||||
logger.warning(f"Could not delete failed DataVolume {data_volume_name}: {del_err}")
|
||||
try:
|
||||
v1.delete_namespaced_persistent_volume_claim(
|
||||
name=data_volume_name,
|
||||
namespace=namespace
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
if progress_callback:
|
||||
progress_callback('Failed', latest_progress, f'System image download failed: {error_message}')
|
||||
raise RuntimeError(f'System image download failed: {error_message}')
|
||||
@@ -1065,10 +1083,29 @@ final_message: "AnchorHost VPS ready! User: {image_config['user']}, Password: {i
|
||||
elapsed += wait_interval
|
||||
|
||||
if elapsed >= max_wait:
|
||||
logger.warning(f"VPS image import did not finish within {max_wait}s")
|
||||
logger.warning(f"VPS image import did not finish within {max_wait}s; stopping ongoing import...")
|
||||
try:
|
||||
custom_objects_api.delete_namespaced_custom_object(
|
||||
group="cdi.kubevirt.io",
|
||||
version="v1beta1",
|
||||
namespace=namespace,
|
||||
plural="datavolumes",
|
||||
name=data_volume_name
|
||||
)
|
||||
logger.info(f"Successfully stopped and deleted timed out DataVolume {data_volume_name}")
|
||||
except Exception as del_err:
|
||||
logger.warning(f"Failed to delete timed out DataVolume {data_volume_name}: {del_err}")
|
||||
try:
|
||||
v1.delete_namespaced_persistent_volume_claim(
|
||||
name=data_volume_name,
|
||||
namespace=namespace
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if progress_callback:
|
||||
progress_callback('Failed', latest_progress, 'The system image download timed out.')
|
||||
raise TimeoutError('System image download timed out; the virtual machine was not started.')
|
||||
progress_callback('Failed', latest_progress, 'The system image download timed out after 1 hour.')
|
||||
raise TimeoutError('System image download timed out after 1 hour; the virtual machine was not started.')
|
||||
|
||||
# Create VM
|
||||
if progress_callback:
|
||||
@@ -1085,6 +1122,24 @@ final_message: "AnchorHost VPS ready! User: {image_config['user']}, Password: {i
|
||||
logger.info(f"Created VirtualMachine {server_id}")
|
||||
except Exception as e:
|
||||
logger.error(f"❌ Failed to create VM: {e}")
|
||||
if dv_created:
|
||||
try:
|
||||
custom_objects_api.delete_namespaced_custom_object(
|
||||
group="cdi.kubevirt.io",
|
||||
version="v1beta1",
|
||||
namespace=namespace,
|
||||
plural="datavolumes",
|
||||
name=data_volume_name
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
v1.delete_namespaced_persistent_volume_claim(
|
||||
name=data_volume_name,
|
||||
namespace=namespace
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
if progress_callback:
|
||||
progress_callback('Error', 0, f'Failed to create VM: {str(e)}')
|
||||
raise Exception(f"Failed to create VM: {str(e)}")
|
||||
@@ -1139,6 +1194,34 @@ final_message: "AnchorHost VPS ready! User: {image_config['user']}, Password: {i
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to create VPS network service: {e}")
|
||||
try:
|
||||
custom_objects_api.delete_namespaced_custom_object(
|
||||
group="kubevirt.io",
|
||||
version="v1",
|
||||
namespace=namespace,
|
||||
plural="virtualmachines",
|
||||
name=server_id
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
if dv_created:
|
||||
try:
|
||||
custom_objects_api.delete_namespaced_custom_object(
|
||||
group="cdi.kubevirt.io",
|
||||
version="v1beta1",
|
||||
namespace=namespace,
|
||||
plural="datavolumes",
|
||||
name=data_volume_name
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
v1.delete_namespaced_persistent_volume_claim(
|
||||
name=data_volume_name,
|
||||
namespace=namespace
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
if progress_callback:
|
||||
progress_callback('Failed', 92, 'Could not create the VPS network service.')
|
||||
raise RuntimeError(f'Failed to create VPS network service: {e}') from e
|
||||
|
||||
@@ -1330,7 +1330,7 @@ async def handle_get_server_creation_progress(client_id, data):
|
||||
with _server_creation_progress_lock:
|
||||
progress = _server_creation_progress_by_user.get(user_id)
|
||||
if progress:
|
||||
expiry = 1800 if progress.get('state') == 'active' else 600
|
||||
expiry = 4200 if progress.get('state') == 'active' else 600
|
||||
if time.time() - progress.get('timestamp', 0) < expiry:
|
||||
await send_message(client_id, {
|
||||
'type': 'server_creation_progress',
|
||||
|
||||
Reference in new issue
Block a user