Skip to content

Commit fd4bcc3

Browse files
committed
improve description. require at least one item in supply if resources is specified, add validation on deploy
1 parent 3dc4241 commit fd4bcc3

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

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

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
import assert from "node:assert";
1918
import { readFile } from "node:fs/promises";
2019
import { isAbsolute, resolve } from "node:path";
2120

2221
import type k8s from "@kubernetes/client-node";
22+
import { color } from "@oclif/color";
2323

2424
import { BaseCommand } from "../../baseCommand.js";
2525
import { commandObj } from "../../lib/commandObj.js";
26+
import { ensureReadonlyProviderConfig } from "../../lib/configs/project/provider/provider.js";
2627
import { CHAIN_FLAGS, PEER_AND_OFFER_NAMES_FLAGS } from "../../lib/const.js";
28+
import { splitErrorsAndResults } from "../../lib/helpers/utils.js";
2729
import { initCli } from "../../lib/lifeCycle.js";
2830
import { projectRootDir } from "../../lib/paths.js";
2931
import { resolveComputePeersByNames } from "../../lib/resolveComputePeersByNames.js";
@@ -39,7 +41,35 @@ export default class Deploy extends BaseCommand<typeof Deploy> {
3941
const { flags } = await initCli(this, await this.parse(Deploy));
4042
const computePeers = await resolveComputePeersByNames(flags);
4143

42-
for (const { kubeconfigPath, name, manifestPath } of computePeers) {
44+
const [invalidPeers, peers] = splitErrorsAndResults(
45+
computePeers,
46+
({ kubeconfigPath, ipSupplies, name, ...restPeer }) => {
47+
return kubeconfigPath === undefined || ipSupplies.length === 0
48+
? {
49+
error: [
50+
kubeconfigPath === undefined &&
51+
`computePeer ${color.yellow(name)} must have a ${color.yellow("kubeconfigPath")} property`,
52+
ipSupplies.length === 0 &&
53+
`computePeer ${color.yellow(name)} must have a ${color.yellow("resources.ip.supply")} property, which must be a non-empty array`,
54+
]
55+
.filter((err) => {
56+
return typeof err === "string";
57+
})
58+
.join("\n"),
59+
}
60+
: { result: { name, ipSupplies, kubeconfigPath, ...restPeer } };
61+
},
62+
);
63+
64+
if (invalidPeers.length > 0) {
65+
const providerConfig = await ensureReadonlyProviderConfig();
66+
67+
commandObj.error(
68+
`Invalid config at ${providerConfig.$getPath()}:\n${invalidPeers.join("\n")}`,
69+
);
70+
}
71+
72+
for (const { kubeconfigPath, name, manifestPath } of peers) {
4373
await kubectlApply(kubeconfigPath, manifestPath, name);
4474
}
4575
}
@@ -54,15 +84,10 @@ export default class Deploy extends BaseCommand<typeof Deploy> {
5484
* @return Array of resources created
5585
*/
5686
export async function kubectlApply(
57-
kubeconfigPath: string | undefined,
87+
kubeconfigPath: string,
5888
specPath: string,
5989
peerName: string,
6090
): Promise<k8s.KubernetesObject[]> {
61-
assert(
62-
typeof kubeconfigPath === "string",
63-
`Kubeconfig path is required for computePeer ${peerName}`,
64-
);
65-
6691
const kubeconfigAbsolutePath = isAbsolute(kubeconfigPath)
6792
? kubeconfigPath
6893
: resolve(projectRootDir, kubeconfigPath);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,11 @@ export async function ensureComputerPeerConfigs(computePeerNames?: string[]) {
472472

473473
const peerId = await getPeerIdFromSecretKey(secretKey);
474474

475+
const ipSupplies = computePeer.resources?.ip.supply ?? [];
476+
475477
const manifest = genManifest({
476478
chainPrivateKey: hexStringToUTF8ToBase64String(signingWallet),
477-
IPSupplies: computePeer.resources?.ip.supply ?? [],
479+
ipSupplies,
478480
httpEndpoint,
479481
wsEndpoint,
480482
ipfsGatewayEndpoint,
@@ -516,6 +518,7 @@ export async function ensureComputerPeerConfigs(computePeerNames?: string[]) {
516518
peerId,
517519
computeUnits: computePeer.computeUnits,
518520
kubeconfigPath: computePeer.kubeconfigPath,
521+
ipSupplies,
519522
manifestPath,
520523
walletKey: signingWallet,
521524
walletAddress: await new Wallet(signingWallet).getAddress(),

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,8 @@ type IPSupply =
653653

654654
const supplySchema = {
655655
type: "object",
656+
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)",
656658
oneOf: [
657659
{
658660
additionalProperties: false,
@@ -701,6 +703,7 @@ const ipSchema = {
701703
type: "array",
702704
items: supplySchema,
703705
description: "IP supply",
706+
minItems: 1,
704707
},
705708
},
706709
required: ["supply"],

packages/cli/package/src/lib/genManifest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const PRIVATE_KEY_SECRET_REF = "private-key-secret";
2323

2424
type GenManifestsArgs = {
2525
chainPrivateKey: string;
26-
IPSupplies: IPSupplies;
26+
ipSupplies: IPSupplies;
2727
httpEndpoint: string;
2828
wsEndpoint: string;
2929
ipfsGatewayEndpoint: string;
@@ -34,7 +34,7 @@ type GenManifestsArgs = {
3434

3535
export function genManifest({
3636
chainPrivateKey,
37-
IPSupplies,
37+
ipSupplies,
3838
httpEndpoint,
3939
wsEndpoint,
4040
ipfsGatewayEndpoint,
@@ -81,7 +81,7 @@ ${stringify({
8181
{
8282
op: "add",
8383
path: "/spec/blocks",
84-
value: IPSupplies,
84+
value: ipSupplies,
8585
},
8686
]),
8787
target: {

0 commit comments

Comments
 (0)