mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-04-19 08:36:14 +00:00
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:
parent
2615c25fc4
commit
d1956b69cc
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user