Merge pull request #1992 from balena-os/1991-wait-for-stopping-services-in-funnel

Wait for Stopping services to stop before target apply success
This commit is contained in:
bulldozer-balena[bot] 2022-08-02 22:57:43 +00:00 committed by GitHub
commit 1c7110badb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -360,6 +360,18 @@ export class App {
);
};
/**
* Checks if Supervisor should keep the state loop alive while waiting on a service to stop
* @param serviceCurrent
* @param serviceTarget
*/
const shouldWaitForStop = (serviceCurrent: Service) => {
return (
serviceCurrent.config.running === true &&
serviceCurrent.status === 'Stopping'
);
};
/**
* Filter all the services which should be updated due to run state change, or config mismatch.
*/
@ -372,7 +384,8 @@ export class App {
({ current: c, target: t }) =>
!isEqualExceptForRunningState(c, t) ||
shouldBeStarted(c, t) ||
shouldBeStopped(c, t),
shouldBeStopped(c, t) ||
shouldWaitForStop(c),
);
return {

View File

@ -657,6 +657,23 @@ describe('compose/app', () => {
expectNoStep('kill', steps);
});
it('should emit a noop while waiting on a stopping service', async () => {
const current = createApp({
services: [
await createService(
{ serviceName: 'main', running: true },
{ state: { status: 'Stopping' } },
),
],
});
const target = createApp({
services: [await createService({ serviceName: 'main', running: true })],
});
const steps = current.nextStepsForAppUpdate(defaultContext, target);
expectSteps('noop', steps);
});
it('should remove a dead container that is still referenced in the target state', async () => {
const current = createApp({
services: [