Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Delete nodes on decommission instead of just releasing scale in prote…
Browse files Browse the repository at this point in the history
…ction (#2586)

Co-authored-by: Teo Voinea <Teodor.Voinea@microsoft.com>
  • Loading branch information
tevoinea and Teo Voinea authored Nov 1, 2022
1 parent 8be6e3c commit 33e2d5c
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions src/ApiService/ApiService/onefuzzlib/ScalesetOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ where x.State.ReadyForReset()
};

await ReimageNodes(scaleSet, toReimage.Values, strategy);
await DeleteNodes(scaleSet, toDelete.Values, strategy);
await DeleteNodes(scaleSet, toDelete.Values);

return (toReimage.Count > 0 || toDelete.Count > 0, scaleSet);
}
Expand All @@ -629,7 +629,7 @@ public async Async.Task ReimageNodes(Scaleset scaleset, IEnumerable<Node> nodes,

if (scaleset.State == ScalesetState.Shutdown) {
_log.Info($"scaleset shutting down, deleting rather than reimaging nodes {scaleset.ScalesetId:Tag:ScalesetId}");
await DeleteNodes(scaleset, nodes, disposalStrategy);
await DeleteNodes(scaleset, nodes);
return;
}

Expand Down Expand Up @@ -658,10 +658,11 @@ public async Async.Task ReimageNodes(Scaleset scaleset, IEnumerable<Node> nodes,

switch (disposalStrategy) {
case NodeDisposalStrategy.Decommission:
_log.Info($"decommissioning nodes");
_log.Info($"Skipping reimage, deleting nodes: {string.Join(", ", nodesToReimage.Select(n => n.MachineId)):Tag:MachineIds}");
await _context.VmssOperations.DeleteNodes(scaleset.ScalesetId, nodesToReimage);
await Async.Task.WhenAll(nodesToReimage
.Select(async node => {
await _context.NodeOperations.ReleaseScaleInProtection(node).IgnoreResult();
await _context.NodeOperations.Delete(node);
}));
return;

Expand All @@ -683,7 +684,7 @@ await Async.Task.WhenAll(nodesToReimage
}


public async Async.Task DeleteNodes(Scaleset scaleset, IEnumerable<Node> nodes, NodeDisposalStrategy disposalStrategy) {
public async Async.Task DeleteNodes(Scaleset scaleset, IEnumerable<Node> nodes) {
if (nodes is null || !nodes.Any()) {
_log.Info($"no nodes to delete: scaleset_id: {scaleset.ScalesetId:Tag:ScalesetId}");
return;
Expand All @@ -706,24 +707,12 @@ public async Async.Task DeleteNodes(Scaleset scaleset, IEnumerable<Node> nodes,
}
}

switch (disposalStrategy) {
case NodeDisposalStrategy.Decommission:
_log.Info($"decommissioning nodes");
await Async.Task.WhenAll(nodesToDelete
.Select(async node => {
await _context.NodeOperations.ReleaseScaleInProtection(node).IgnoreResult();
}));
return;

case NodeDisposalStrategy.ScaleIn:
_log.Info($"deleting nodes {scaleset.ScalesetId:Tag:ScalesetId} {string.Join(", ", nodesToDelete.Select(n => n.MachineId)):Tag:MachineIds}");
await _context.VmssOperations.DeleteNodes(scaleset.ScalesetId, nodesToDelete);
await Async.Task.WhenAll(nodesToDelete
.Select(async node => {
await _context.NodeOperations.Delete(node);
}));
return;
}
_log.Info($"deleting nodes {scaleset.ScalesetId:Tag:ScalesetId} {string.Join(", ", nodesToDelete.Select(n => n.MachineId)):Tag:MachineIds}");
await _context.VmssOperations.DeleteNodes(scaleset.ScalesetId, nodesToDelete);
await Async.Task.WhenAll(nodesToDelete
.Select(async node => {
await _context.NodeOperations.Delete(node);
}));
}

public async Task<OneFuzzResult<Scaleset>> GetById(Guid scalesetId) {
Expand Down

0 comments on commit 33e2d5c

Please sign in to comment.