mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-23 15:32:24 +00:00
Report any optional containers that aren't being run
Change-type: patch Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
parent
f75b8aad2b
commit
8223bf2ccb
@ -735,18 +735,23 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
@proxyvisor.setTargetInTransaction(dependent, trx)
|
||||
|
||||
contractViolators = {}
|
||||
Promise.props(contractsFulfilled).then (fulfilledContracts) ->
|
||||
Promise.props(contractsFulfilled).then (fulfilledContracts) =>
|
||||
filteredApps = _.cloneDeep(apps)
|
||||
_.each fulfilledContracts, ({ valid, unmetServices, fulfilledServices }, appId) ->
|
||||
if not valid
|
||||
contractViolators[apps[appId].name] = unmetServices
|
||||
delete filteredApps[appId]
|
||||
else
|
||||
# valid is true, but we could still be missing
|
||||
# some optional containers, and need to filter
|
||||
# these out of the target state
|
||||
filteredApps[appId].services = _.pickBy filteredApps[appId].services, ({ serviceName }) ->
|
||||
fulfilledServices.includes(serviceName)
|
||||
_.each(
|
||||
fulfilledContracts,
|
||||
({ valid, unmetServices, fulfilledServices, unmetAndOptional }, appId) =>
|
||||
if not valid
|
||||
contractViolators[apps[appId].name] = unmetServices
|
||||
delete filteredApps[appId]
|
||||
else
|
||||
# valid is true, but we could still be missing
|
||||
# some optional containers, and need to filter
|
||||
# these out of the target state
|
||||
filteredApps[appId].services = _.pickBy filteredApps[appId].services, ({ serviceName }) ->
|
||||
fulfilledServices.includes(serviceName)
|
||||
if unmetAndOptional.length != 0
|
||||
@reportOptionalContainers(unmetAndOptional)
|
||||
)
|
||||
if trx?
|
||||
setInTransaction(filteredApps, trx)
|
||||
else
|
||||
@ -1008,3 +1013,12 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
return volumes.map((v) -> { action: 'removeVolume', current: v })
|
||||
|
||||
localModeSwitchCompletion: => @localModeManager.switchCompletion()
|
||||
|
||||
reportOptionalContainers: (serviceNames) =>
|
||||
# Print logs to the console and dashboard, letting the
|
||||
# user know that we're not going to run certain services
|
||||
# because of their contract
|
||||
message = "Not running containers because of contract violations: #{serviceNames.join('. ')}"
|
||||
log.info(message)
|
||||
@logger.logSystemMessage(message, {}, 'optionalContainerViolation', true)
|
||||
|
||||
|
@ -22,6 +22,7 @@ export async function containerContractsFulfilled(
|
||||
valid: boolean;
|
||||
unmetServices: string[];
|
||||
fulfilledServices: string[];
|
||||
unmetAndOptional: string[];
|
||||
}> {
|
||||
const containers = _(serviceContracts)
|
||||
.map('contract')
|
||||
@ -76,6 +77,7 @@ export async function containerContractsFulfilled(
|
||||
valid: false,
|
||||
unmetServices: _.keys(serviceContracts),
|
||||
fulfilledServices: [],
|
||||
unmetAndOptional: [],
|
||||
};
|
||||
}
|
||||
|
||||
@ -90,6 +92,7 @@ export async function containerContractsFulfilled(
|
||||
valid: true,
|
||||
unmetServices: [],
|
||||
fulfilledServices: _.keys(serviceContracts),
|
||||
unmetAndOptional: [],
|
||||
};
|
||||
} else {
|
||||
// If we got here, it means that at least one of the
|
||||
@ -112,15 +115,18 @@ export async function containerContractsFulfilled(
|
||||
},
|
||||
);
|
||||
|
||||
const valid = !_.some(
|
||||
const [unmetAndRequired, unmetAndOptional] = _.partition(
|
||||
unfulfilledServices,
|
||||
svcName => !serviceContracts[svcName].optional,
|
||||
serviceName => {
|
||||
return !serviceContracts[serviceName].optional;
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
valid,
|
||||
valid: unmetAndRequired.length === 0,
|
||||
unmetServices: unfulfilledServices,
|
||||
fulfilledServices,
|
||||
unmetAndOptional,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user