Handle instance being destroyed before updating scaling protection (#1719)

* Handle instance being destroyed before updating scaling protection

* Fix bug where we release protection too early
This commit is contained in:
Teo Voinea
2022-03-28 10:14:39 -04:00
committed by GitHub
parent 5c418eeb36
commit ce03394376
2 changed files with 17 additions and 2 deletions

View File

@ -184,7 +184,23 @@ def update_scale_in_protection(
compute_client.virtual_machine_scale_set_vms.begin_update(
resource_group, name, instance_id, instance_vm
)
except (ResourceNotFoundError, CloudError):
except (ResourceNotFoundError, CloudError, HttpResponseError) as err:
if isinstance(err, HttpResponseError):
err_str = str(err)
instance_not_found = (
" is not an active Virtual Machine Scale Set VM instanceId."
)
if (
instance_not_found in err_str
and instance_vm.protection_policy.protect_from_scale_in is False
and protect_from_scale_in
== instance_vm.protection_policy.protect_from_scale_in
):
logging.info(
"Tried to remove scale in protection on node %s but the instance no longer exists" # noqa: E501
% instance_id
)
return None
return Error(
code=ErrorCode.UNABLE_TO_UPDATE,
errors=["unable to set protection policy on: %s:%s" % (vm_id, instance_id)],

View File

@ -390,7 +390,6 @@ class Node(BASE_NODE, ORMMixin):
# if we're going to reimage, make sure the node doesn't pick up new work
# too.
self.send_stop_if_free()
self.release_scale_in_protection()
self.save()