common: Fix bug where aliases might be undefined

Should handle the scenario where the network aliases are undefined.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
This commit is contained in:
Rich Bayliss 2020-07-23 16:41:40 +01:00
parent 72d715b254
commit 60132134de
No known key found for this signature in database
GPG Key ID: E53C4B4D18499E1A

View File

@ -154,10 +154,13 @@ export function safeAppClone(app) {
// TODO: Make the process of moving from a current state to a target state
// well-defined (and implemented in a seperate module)
const svcCopy = _.cloneDeep(svc);
_.each(svcCopy.config.networks, (net) => {
net.aliases = net.aliases.filter(
(alias) => alias !== containerIdForService[svcCopy.serviceName],
);
if (Array.isArray(net.aliases)) {
net.aliases = net.aliases.filter(
(alias) => alias !== containerIdForService[svcCopy.serviceName],
);
}
});
return svcCopy;
}),