-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(orchestrator): add substrate cli args version (#984)
* wip, k8s * wip, podman and native * clean up and small reorg * remove commented code * fmt * changes from feedback
- Loading branch information
Showing
11 changed files
with
295 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
javascript/packages/orchestrator/src/providers/k8s/substrateCliArgsHelper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { series } from "@zombienet/utils"; | ||
import { ComputedNetwork, SubstrateCliArgsVersion } from "../../types"; | ||
import { getClient } from "../client"; | ||
import { createTempNodeDef, genNodeDef } from "./dynResourceDefinition"; | ||
import { KubeClient } from "./kubeClient"; | ||
|
||
const getVersion = async ( | ||
image: string, | ||
command: string, | ||
): Promise<SubstrateCliArgsVersion> => { | ||
const client = getClient() as KubeClient; | ||
const fullCmd = `${command} --help | grep ws-port`; | ||
const node = await createTempNodeDef( | ||
"temp", | ||
image, | ||
"", // don't used | ||
fullCmd, | ||
false, | ||
); | ||
|
||
const podDef = await genNodeDef(client.namespace, node); | ||
const podName = podDef.metadata.name; | ||
await client.spawnFromDef(podDef); | ||
const logs = await client.getNodeLogs(podName); | ||
|
||
return logs.includes("--ws-port <PORT>") | ||
? SubstrateCliArgsVersion.V0 | ||
: SubstrateCliArgsVersion.V1; | ||
}; | ||
|
||
export const setSubstrateCliArdsVersion = async (network: ComputedNetwork) => { | ||
// Calculate substrate cli version for each node | ||
// and set in the node to use later when we build the cmd. | ||
const imgCmdMap = new Map(); | ||
network.relaychain.nodes.reduce((memo, node) => { | ||
const uniq_image_cmd = `${node.image}_${node.command}`; | ||
if (!memo.has(uniq_image_cmd)) | ||
memo.set(uniq_image_cmd, { image: node.image, command: node.command }); | ||
return memo; | ||
}, imgCmdMap); | ||
|
||
network.parachains.reduce((memo, parachain) => { | ||
for (const collator of parachain.collators) { | ||
const uniq_image_cmd = `${collator.image}_${collator.command}`; | ||
if (!memo.has(uniq_image_cmd)) | ||
memo.set(uniq_image_cmd, { | ||
image: collator.image, | ||
command: collator.command, | ||
}); | ||
} | ||
return memo; | ||
}, imgCmdMap); | ||
|
||
// check versions in series | ||
const promiseGenerators = []; | ||
for (const [, v] of imgCmdMap) { | ||
const getVersionPromise = async () => { | ||
const version = await getVersion(v.image, v.command); | ||
v.version = version; | ||
return version; | ||
}; | ||
promiseGenerators.push(getVersionPromise); | ||
} | ||
|
||
await series(promiseGenerators, 4); | ||
|
||
// now we need to iterate and set in each node the version | ||
// IFF is not set | ||
for (const node of network.relaychain.nodes) { | ||
if (node.substrateCliArgsVersion) continue; | ||
const uniq_image_cmd = `${node.image}_${node.command}`; | ||
node.substrateCliArgsVersion = imgCmdMap.get(uniq_image_cmd).version; | ||
} | ||
|
||
for (const parachain of network.parachains) { | ||
for (const collator of parachain.collators) { | ||
if (collator.substrateCliArgsVersion) continue; | ||
const uniq_image_cmd = `${collator.image}_${collator.command}`; | ||
collator.substrateCliArgsVersion = imgCmdMap.get(uniq_image_cmd).version; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
javascript/packages/orchestrator/src/providers/native/substrateCliArgsHelper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { series } from "@zombienet/utils"; | ||
import { ComputedNetwork, SubstrateCliArgsVersion } from "../../types"; | ||
import { getClient } from "../client"; | ||
|
||
const getVersion = async ( | ||
image: string, | ||
command: string, | ||
): Promise<SubstrateCliArgsVersion> => { | ||
const client = getClient(); | ||
const fullCmd = `${command} --help | grep ws-port`; | ||
const logs = (await client.runCommand(["-c", fullCmd], { allowFail: true })) | ||
.stdout; | ||
|
||
return logs.includes("--ws-port <PORT>") | ||
? SubstrateCliArgsVersion.V0 | ||
: SubstrateCliArgsVersion.V1; | ||
}; | ||
|
||
export const setSubstrateCliArdsVersion = async (network: ComputedNetwork) => { | ||
// Calculate substrate cli version for each node | ||
// and set in the node to use later when we build the cmd. | ||
const imgCmdMap = new Map(); | ||
network.relaychain.nodes.reduce((memo, node) => { | ||
const uniq_image_cmd = `${node.image}_${node.command}`; | ||
if (!memo.has(uniq_image_cmd)) | ||
memo.set(uniq_image_cmd, { image: node.image, command: node.command }); | ||
return memo; | ||
}, imgCmdMap); | ||
|
||
network.parachains.reduce((memo, parachain) => { | ||
for (const collator of parachain.collators) { | ||
const uniq_image_cmd = `${collator.image}_${collator.command}`; | ||
if (!memo.has(uniq_image_cmd)) | ||
memo.set(uniq_image_cmd, { | ||
image: collator.image, | ||
command: collator.command, | ||
}); | ||
} | ||
return memo; | ||
}, imgCmdMap); | ||
|
||
// check versions in series | ||
const promiseGenerators = []; | ||
|
||
for (const [, v] of imgCmdMap) { | ||
const getVersionPromise = async () => { | ||
const version = await getVersion(v.image, v.command); | ||
v.version = version; | ||
return version; | ||
}; | ||
promiseGenerators.push(getVersionPromise); | ||
} | ||
|
||
await series(promiseGenerators, 4); | ||
|
||
// now we need to iterate and set in each node the version | ||
// IFF is not set | ||
for (const node of network.relaychain.nodes) { | ||
if (node.substrateCliArgsVersion) continue; | ||
const uniq_image_cmd = `${node.image}_${node.command}`; | ||
node.substrateCliArgsVersion = imgCmdMap.get(uniq_image_cmd).version; | ||
} | ||
|
||
for (const parachain of network.parachains) { | ||
for (const collator of parachain.collators) { | ||
if (collator.substrateCliArgsVersion) continue; | ||
const uniq_image_cmd = `${collator.image}_${collator.command}`; | ||
collator.substrateCliArgsVersion = imgCmdMap.get(uniq_image_cmd).version; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.