Merge pull request #1892 from balena-os/404-supervisor0

Fix check for supervisor0 network
This commit is contained in:
bulldozer-balena[bot] 2022-02-28 21:21:34 +00:00 committed by GitHub
commit bc571699ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -69,22 +69,31 @@ export async function remove(network: Network) {
await network.remove();
}
const supervisorIfaceSysPath = `/sys/class/net/${constants.supervisorNetworkInterface}`;
export async function supervisorNetworkReady(): Promise<boolean> {
const networkExists = await exists(
`/sys/class/net/${constants.supervisorNetworkInterface}`,
);
const networkExists = await exists(supervisorIfaceSysPath);
if (!networkExists) {
return false;
}
const network = await docker
.getNetwork(constants.supervisorNetworkInterface)
.inspect();
return (
network.Options['com.docker.network.bridge.name'] ===
constants.supervisorNetworkInterface &&
network.IPAM.Config[0].Subnet === constants.supervisorNetworkSubnet &&
network.IPAM.Config[0].Gateway === constants.supervisorNetworkGateway
);
try {
// The inspect may fail even if the interface exist due to docker corruption
const network = await docker
.getNetwork(constants.supervisorNetworkInterface)
.inspect();
return (
network.Options['com.docker.network.bridge.name'] ===
constants.supervisorNetworkInterface &&
network.IPAM.Config[0].Subnet === constants.supervisorNetworkSubnet &&
network.IPAM.Config[0].Gateway === constants.supervisorNetworkGateway
);
} catch (e) {
log.warn(
`Failed to read docker configuration of network ${constants.supervisorNetworkInterface}:`,
e,
);
return false;
}
}
export function ensureSupervisorNetwork(): Bluebird<void> {
@ -108,9 +117,7 @@ export function ensureSupervisorNetwork(): Bluebird<void> {
) {
return removeIt();
} else {
return exists(
`/sys/class/net/${constants.supervisorNetworkInterface}`,
).then((networkExists) => {
return exists(supervisorIfaceSysPath).then((networkExists) => {
if (!networkExists) {
return removeIt();
}