Skip to content

Commit 26dd8b7

Browse files
authored
feat: write manifest files on gen command only, rename end to stop (#1089)
* feat: write manifest files on gen command only * show 0 instead of a message * restore error message * rename end to stop * Apply automatic changes --------- Co-authored-by: shamsartem <[email protected]>
1 parent 4cb0bbf commit 26dd8b7

File tree

6 files changed

+43
-36
lines changed

6 files changed

+43
-36
lines changed

packages/cli/package/docs/configs/provider.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Defines an IP resource
116116

117117
###### supply
118118

119-
Either specify only a `start` property (if you want a single IP) or `start` and `end` properties (if you want a range) or `cidr` property (if you want a CIDR notation)
119+
Either specify only a `start` property (if you want a single IP) or `start` and `stop` properties (if you want a range) or `cidr` property (if you want a CIDR notation)
120120

121121
| Property | Type | Required | Description |
122122
|----------|------|----------|-------------|

packages/cli/package/src/commands/provider/gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default class Gen extends BaseCommand<typeof Gen> {
110110
);
111111
}
112112

113-
await ensureComputerPeerConfigs();
113+
await ensureComputerPeerConfigs({ writeManifestFiles: true });
114114

115115
commandObj.logToStderr(
116116
`Secrets are generated at:\n${getFluenceSecretsDir()}\n\nManifest files are generated at:\n${await ensureK8sManifestsDir()}`,

packages/cli/package/src/lib/chain/offer/offer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,9 @@ async function ensureOfferConfigs() {
956956
resourcePrices,
957957
},
958958
]) => {
959-
const computePeerConfigs =
960-
await ensureComputerPeerConfigs(computePeers);
959+
const computePeerConfigs = await ensureComputerPeerConfigs({
960+
computePeerNames: computePeers,
961+
});
961962

962963
const computePeersFromProviderConfig = await Promise.all(
963964
computePeerConfigs.map(

packages/cli/package/src/lib/configs/project/provider/provider.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,15 @@ export type EnsureComputerPeerConfig = Awaited<
183183
ReturnType<typeof ensureComputerPeerConfigs>
184184
>[number];
185185

186-
export async function ensureComputerPeerConfigs(computePeerNames?: string[]) {
186+
type EnsureComputerPeerConfigsArgs = {
187+
computePeerNames?: string[];
188+
writeManifestFiles?: boolean;
189+
};
190+
191+
export async function ensureComputerPeerConfigs({
192+
computePeerNames,
193+
writeManifestFiles = false,
194+
}: EnsureComputerPeerConfigsArgs = {}) {
187195
const { Wallet } = await import("ethers");
188196
const providerConfig = await ensureReadonlyProviderConfig();
189197

@@ -260,13 +268,9 @@ export async function ensureComputerPeerConfigs(computePeerNames?: string[]) {
260268
const capacityCommitment =
261269
providerConfig.capacityCommitments[c.computePeerName];
262270

263-
if (capacityCommitment === undefined) {
264-
return {
265-
error: c.computePeerName,
266-
};
267-
}
268-
269-
return { result: { ...c, capacityCommitment } };
271+
return capacityCommitment === undefined
272+
? { error: c.computePeerName }
273+
: { result: { ...c, capacityCommitment } };
270274
},
271275
);
272276

@@ -304,20 +308,22 @@ export async function ensureComputerPeerConfigs(computePeerNames?: string[]) {
304308
);
305309

306310
const peerId = await getPeerIdFromSecretKey(secretKey);
307-
308-
const manifest = genManifest({
309-
chainPrivateKey: hexStringToUTF8ToBase64String(signingWallet),
310-
ipSupplies: computePeer.resources.ip.supply,
311-
httpEndpoint,
312-
wsEndpoint,
313-
ipfsGatewayEndpoint,
314-
peerIdHex: await peerIdBase58ToHexString(peerId),
315-
networkId,
316-
diamondContract,
317-
});
318-
319311
const manifestPath = join(k8sManifestsDir, `${computePeerName}.yaml`);
320-
await writeFile(manifestPath, manifest, "utf8");
312+
313+
if (writeManifestFiles) {
314+
const manifest = genManifest({
315+
chainPrivateKey: hexStringToUTF8ToBase64String(signingWallet),
316+
ipSupplies: computePeer.resources.ip.supply,
317+
httpEndpoint,
318+
wsEndpoint,
319+
ipfsGatewayEndpoint,
320+
peerIdHex: await peerIdBase58ToHexString(peerId),
321+
networkId,
322+
diamondContract,
323+
});
324+
325+
await writeFile(manifestPath, manifest, "utf8");
326+
}
321327

322328
const cpu =
323329
providerConfig.resources.cpu[computePeer.resources.cpu.name];

packages/cli/package/src/lib/configs/project/provider/provider1.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ export const ccpConfigYAMLSchema = {
645645
type IPSupply =
646646
| {
647647
start: string;
648-
end?: string;
648+
stop?: string;
649649
}
650650
| {
651651
cidr: string;
@@ -654,7 +654,7 @@ type IPSupply =
654654
const supplySchema = {
655655
type: "object",
656656
description:
657-
"Either specify only a `start` property (if you want a single IP) or `start` and `end` properties (if you want a range) or `cidr` property (if you want a CIDR notation)",
657+
"Either specify only a `start` property (if you want a single IP) or `start` and `stop` properties (if you want a range) or `cidr` property (if you want a CIDR notation)",
658658
oneOf: [
659659
{
660660
additionalProperties: false,
@@ -664,7 +664,7 @@ const supplySchema = {
664664
format: "ipv4",
665665
description: "Start of the IP range or individual IP",
666666
},
667-
end: {
667+
stop: {
668668
nullable: true,
669669
type: "string",
670670
format: "ipv4",

packages/cli/package/src/lib/configs/project/provider/provider4.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ type IpRange =
10921092
}
10931093
| {
10941094
start: IPv4;
1095-
end?: IPv4;
1095+
stop?: IPv4;
10961096
};
10971097

10981098
// TODO: export this from deal-ts-clients
@@ -1248,19 +1248,19 @@ export function ipSupplyToIndividualIPs(
12481248
};
12491249
}
12501250

1251-
if (!("end" in s)) {
1251+
if (!("stop" in s)) {
12521252
return { result: { start: startRes.result } };
12531253
}
12541254

1255-
const endRes = stringToIp(s.end);
1255+
const endRes = stringToIp(s.stop);
12561256

12571257
if ("error" in endRes) {
12581258
return {
1259-
error: `Invalid IP range end: ${s.end}. ${endRes.error}`,
1259+
error: `Invalid IP range stop: ${s.stop}. ${endRes.error}`,
12601260
};
12611261
}
12621262

1263-
return { result: { start: startRes.result, end: endRes.result } };
1263+
return { result: { start: startRes.result, stop: endRes.result } };
12641264
},
12651265
);
12661266

@@ -1289,9 +1289,9 @@ export function ipSupplyToIndividualIPs(
12891289
addIp(ipNumToIpStr(ipNum));
12901290
ipNum++;
12911291
}
1292-
} else if ("end" in range) {
1293-
const { end, start } = range;
1294-
const endNum = ipToIpNum(end);
1292+
} else if ("stop" in range) {
1293+
const { stop, start } = range;
1294+
const endNum = ipToIpNum(stop);
12951295
let startNum = ipToIpNum(start);
12961296

12971297
while (startNum <= endNum) {

0 commit comments

Comments
 (0)