mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-21 02:01:35 +00:00
Fix network appUuid inference in local mode
Local mode uses a numeric `appUuid` which was messing up parsing the network name. This fixes this issue so the current state can be used as a target state Change-type: patch
This commit is contained in:
parent
b1fc4e1761
commit
43630e5267
@ -24,7 +24,10 @@ export class Network {
|
||||
|
||||
private constructor() {}
|
||||
|
||||
private static deconstructDockerName(name: string): {
|
||||
private static deconstructDockerName(
|
||||
name: string,
|
||||
appId?: number,
|
||||
): {
|
||||
name: string;
|
||||
appId?: number;
|
||||
appUuid?: string;
|
||||
@ -41,7 +44,14 @@ export class Network {
|
||||
return { name: matchWithAppUuid[2], appUuid };
|
||||
}
|
||||
|
||||
const appId = parseInt(matchWithAppId[1], 10);
|
||||
// If the appId is provided, then it was already available
|
||||
// as a label, which means that the appUuid is the first match
|
||||
// even if it is numeric only
|
||||
if (appId != null && !isNaN(appId)) {
|
||||
return { name: matchWithAppId[2], appUuid: matchWithAppId[1], appId };
|
||||
}
|
||||
|
||||
appId = parseInt(matchWithAppId[1], 10);
|
||||
if (isNaN(appId)) {
|
||||
throw new InvalidNetworkNameError(name);
|
||||
}
|
||||
@ -55,12 +65,13 @@ export class Network {
|
||||
public static fromDockerNetwork(network: NetworkInspectInfo): Network {
|
||||
const ret = new Network();
|
||||
|
||||
const labels = network.Labels ?? {};
|
||||
// Detect the name and appId from the inspect data
|
||||
const { name, appId, appUuid } = Network.deconstructDockerName(
|
||||
network.Name,
|
||||
parseInt(labels['io.balena.app-id'], 10),
|
||||
);
|
||||
|
||||
const labels = network.Labels ?? {};
|
||||
if (!appId && isNaN(parseInt(labels['io.balena.app-id'], 10))) {
|
||||
// This should never happen as supervised networks will always have either
|
||||
// the id or the label
|
||||
|
Loading…
x
Reference in New Issue
Block a user