Fix check for supervisor0 network

The check for the docker network supervisor0 assumed that if the
interface supervisor0 existed, then the network would exist too. However this is not
true on the case of docker directory corruption, which would lead to a
loop with `Error: (HTTP code 404) no such network - network supervisor0 not found`.

Change-type: patch
Closes: #1806
This commit is contained in:
Felipe Lalanne 2022-02-25 19:46:59 -03:00
parent 2615c25fc4
commit d1956b69cc

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();
}