Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: write manifest files on gen command only, rename end to stop #1089

Merged
merged 6 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/package/docs/configs/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Defines an IP resource

###### supply

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)
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)

| Property | Type | Required | Description |
|----------|------|----------|-------------|
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package/src/commands/provider/gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default class Gen extends BaseCommand<typeof Gen> {
);
}

await ensureComputerPeerConfigs();
await ensureComputerPeerConfigs({ writeManifestFiles: true });

commandObj.logToStderr(
`Secrets are generated at:\n${getFluenceSecretsDir()}\n\nManifest files are generated at:\n${await ensureK8sManifestsDir()}`,
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/package/src/lib/chain/offer/offer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,9 @@ async function ensureOfferConfigs() {
resourcePrices,
},
]) => {
const computePeerConfigs =
await ensureComputerPeerConfigs(computePeers);
const computePeerConfigs = await ensureComputerPeerConfigs({
computePeerNames: computePeers,
});

const computePeersFromProviderConfig = await Promise.all(
computePeerConfigs.map(
Expand Down
48 changes: 27 additions & 21 deletions packages/cli/package/src/lib/configs/project/provider/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,15 @@ export type EnsureComputerPeerConfig = Awaited<
ReturnType<typeof ensureComputerPeerConfigs>
>[number];

export async function ensureComputerPeerConfigs(computePeerNames?: string[]) {
type EnsureComputerPeerConfigsArgs = {
computePeerNames?: string[];
writeManifestFiles?: boolean;
};

export async function ensureComputerPeerConfigs({
computePeerNames,
writeManifestFiles = false,
}: EnsureComputerPeerConfigsArgs = {}) {
const { Wallet } = await import("ethers");
const providerConfig = await ensureReadonlyProviderConfig();

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

if (capacityCommitment === undefined) {
return {
error: c.computePeerName,
};
}

return { result: { ...c, capacityCommitment } };
return capacityCommitment === undefined
? { error: c.computePeerName }
: { result: { ...c, capacityCommitment } };
},
);

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

const peerId = await getPeerIdFromSecretKey(secretKey);

const manifest = genManifest({
chainPrivateKey: hexStringToUTF8ToBase64String(signingWallet),
ipSupplies: computePeer.resources.ip.supply,
httpEndpoint,
wsEndpoint,
ipfsGatewayEndpoint,
peerIdHex: await peerIdBase58ToHexString(peerId),
networkId,
diamondContract,
});

const manifestPath = join(k8sManifestsDir, `${computePeerName}.yaml`);
await writeFile(manifestPath, manifest, "utf8");

if (writeManifestFiles) {
const manifest = genManifest({
chainPrivateKey: hexStringToUTF8ToBase64String(signingWallet),
ipSupplies: computePeer.resources.ip.supply,
httpEndpoint,
wsEndpoint,
ipfsGatewayEndpoint,
peerIdHex: await peerIdBase58ToHexString(peerId),
networkId,
diamondContract,
});

await writeFile(manifestPath, manifest, "utf8");
}

const cpu =
providerConfig.resources.cpu[computePeer.resources.cpu.name];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ export const ccpConfigYAMLSchema = {
type IPSupply =
| {
start: string;
end?: string;
stop?: string;
}
| {
cidr: string;
Expand All @@ -654,7 +654,7 @@ type IPSupply =
const supplySchema = {
type: "object",
description:
"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)",
"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)",
oneOf: [
{
additionalProperties: false,
Expand All @@ -664,7 +664,7 @@ const supplySchema = {
format: "ipv4",
description: "Start of the IP range or individual IP",
},
end: {
stop: {
nullable: true,
type: "string",
format: "ipv4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ type IpRange =
}
| {
start: IPv4;
end?: IPv4;
stop?: IPv4;
};

// TODO: export this from deal-ts-clients
Expand Down Expand Up @@ -1248,19 +1248,19 @@ export function ipSupplyToIndividualIPs(
};
}

if (!("end" in s)) {
if (!("stop" in s)) {
return { result: { start: startRes.result } };
}

const endRes = stringToIp(s.end);
const endRes = stringToIp(s.stop);

if ("error" in endRes) {
return {
error: `Invalid IP range end: ${s.end}. ${endRes.error}`,
error: `Invalid IP range stop: ${s.stop}. ${endRes.error}`,
};
}

return { result: { start: startRes.result, end: endRes.result } };
return { result: { start: startRes.result, stop: endRes.result } };
},
);

Expand Down Expand Up @@ -1289,9 +1289,9 @@ export function ipSupplyToIndividualIPs(
addIp(ipNumToIpStr(ipNum));
ipNum++;
}
} else if ("end" in range) {
const { end, start } = range;
const endNum = ipToIpNum(end);
} else if ("stop" in range) {
const { stop, start } = range;
const endNum = ipToIpNum(stop);
let startNum = ipToIpNum(start);

while (startNum <= endNum) {
Expand Down
Loading