fix: Rework delete-then-download handling in state engine

In the original implementation it was possible that the delete did not
wait for the kill step to be finished, so it would not be deleted.

We seperate this process into two steps, to allow for the container to
have stopped before proceeding.

Change-type: patch
Closes: #841
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-02-05 17:24:03 +00:00
parent 9d8552ea8d
commit e9b51bbcd7
No known key found for this signature in database
GPG Key ID: 49690ED87032539F

View File

@ -545,8 +545,8 @@ module.exports = class ApplicationManager extends EventEmitter
return null
'kill-then-download': (current, target) ->
return serviceAction('kill', target.serviceId, current, target)
'delete-then-download': (current, target, needsDownload) ->
return serviceAction('kill', target.serviceId, current, target, removeImage: needsDownload)
'delete-then-download': (current, target) ->
return serviceAction('kill', target.serviceId, current, target)
'hand-over': (current, target, needsDownload, dependenciesMetForStart, dependenciesMetForKill, needsSpecialKill, timeout) ->
if needsDownload
return fetchAction(target)
@ -849,7 +849,10 @@ module.exports = class ApplicationManager extends EventEmitter
return @bestDeltaSource(image, available)
proxyvisorImages = @proxyvisor.imagesInUse(current, target)
imagesToRemove = _.filter availableAndUnused, (image) ->
potentialDeleteThenDownload = _.filter current.local.apps.services, (svc) ->
svc.config.labels['io.balena.update.strategy'] == 'delete-then-download' and svc.status == 'Stopped'
imagesToRemove = _.filter availableAndUnused.concat(potentialDeleteThenDownload), (image) ->
notUsedForDelta = !_.includes(deltaSources, image.name)
notUsedByProxyvisor = !_.some proxyvisorImages, (proxyvisorImage) -> Images.isSameImage(image, { name: proxyvisorImage })
return notUsedForDelta and notUsedByProxyvisor