mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-19 13:47:54 +00:00
Merge pull request #1892 from balena-os/404-supervisor0
Fix check for supervisor0 network
This commit is contained in:
commit
bc571699ce
@ -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…
Reference in New Issue
Block a user