-
Notifications
You must be signed in to change notification settings - Fork 177
Implements address space cleanup when a workspace service is uninstalled #4744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c83471e
029f506
1abd135
c9f9307
f38ef4a
8f722aa
539c4ab
a1ca86a
6ebeb08
3583506
b32d4ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| __version__ = "0.25.14" | ||
| __version__ = "0.25.15" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| from pydantic import ValidationError, parse_obj_as | ||
|
|
||
| from api.routes.resource_helpers import get_timestamp | ||
| from models.domain.resource import Output | ||
| from models.domain.resource import Output, ResourceType | ||
| from db.repositories.resources_history import ResourceHistoryRepository | ||
| from models.domain.request_action import RequestAction | ||
| from db.repositories.resource_templates import ResourceTemplateRepository | ||
|
|
@@ -21,6 +21,9 @@ | |
| from models.domain.operation import DeploymentStatusUpdateMessage, Operation, OperationStep, Status | ||
| from resources import strings | ||
| from services.logging import logger, tracer | ||
| from db.repositories.workspaces import WorkspaceRepository | ||
| from models.schemas.resource import ResourcePatch | ||
| from azure.cosmos.exceptions import CosmosAccessConditionFailedError | ||
|
|
||
|
|
||
| class DeploymentStatusUpdater(): | ||
|
|
@@ -187,6 +190,34 @@ async def update_status_in_database(self, message: DeploymentStatusUpdateMessage | |
| next_step.status = Status.UpdatingFailed | ||
| await self.update_overall_operation_status(operation, next_step, is_last_step) | ||
| await self.operations_repo.update_item(operation) | ||
| # If the 'main' step succeeded for an uninstall operation, free any allocated address space | ||
| # owned by a WorkspaceService resource. We trigger cleanup when the step with templateStepId == 'main' | ||
| # is successful; this ensures the primary resource has been destroyed successfully before attempting to free the ip address space | ||
| try: | ||
| # if the step that just succeeded is the main step for this operation, and this is an uninstall, | ||
| # proceed with post-uninstall cleanup. No need to scan the operation.steps list again. | ||
| if step_to_update.templateStepId == "main" and step_to_update.is_success() and operation.action == RequestAction.UnInstall: | ||
| if resource_to_persist.get("resourceType") == ResourceType.WorkspaceService: | ||
| address_to_free = resource_to_persist.get("properties", {}).get("address_space") | ||
| parent_workspace_id = resource_to_persist.get("workspaceId") | ||
| if address_to_free and parent_workspace_id: | ||
| try: | ||
| workspace_repo = await WorkspaceRepository.create() | ||
| workspace = await workspace_repo.get_workspace_by_id(parent_workspace_id) | ||
| workspace_address_spaces = workspace.properties.get("address_spaces", []) | ||
| if address_to_free in workspace_address_spaces: | ||
| new_address_spaces = [a for a in workspace_address_spaces if a != address_to_free] | ||
| workspace_patch = ResourcePatch() | ||
| workspace_patch.properties = {"address_spaces": new_address_spaces} | ||
| try: | ||
| await workspace_repo.patch_workspace(workspace, workspace_patch, workspace.etag, self.resource_template_repo, self.resource_history_repo, operation.user, False) | ||
| logger.info(f"Freed address space {address_to_free} from workspace {parent_workspace_id} after successful uninstall of {resource_id}") | ||
|
Comment on lines
+193
to
+214
|
||
| except CosmosAccessConditionFailedError: | ||
| logger.exception("ETag conflict when freeing workspace address space after successful uninstall") | ||
|
Comment on lines
+212
to
+216
|
||
| except Exception: | ||
| logger.exception("Failed to free workspace address space after successful uninstall") | ||
| except Exception: | ||
| logger.exception("Unexpected error during post-uninstall address space cleanup") | ||
|
|
||
| result = True | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CHANGELOG entry for address space deallocation reads like a bug fix (existing behavior leaking address ranges) but is currently listed under ENHANCEMENTS. Please move this bullet under the BUG FIXES section in the Unreleased block to match the project’s changelog categorization.