Skip to content

Commit 4c1dd5f

Browse files
feat(nodes): add feature-flag-gated --enable-infiniband to sf nodes create
The option is only mounted when the user's account has the `infiniband-preview` flag enabled (checked via the existing posthog/ feature-flag helper). When enabled, it shows up in `sf nodes create --help` and forwards `_preview_enable_infiniband: true` to the nodes SDK, exposing the InfiniBand preview surface in the sfcompute/sfcompute API. Generated with [Indent](https://indent.com) Co-Authored-By: Indent <noreply@indent.com>
1 parent 6e5bd5e commit 4c1dd5f

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

src/lib/nodes/create.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from "../../helpers/units.ts";
2222
import { handleNodesError, nodesClient } from "../../nodesClient.ts";
2323
import { GPUS_PER_NODE } from "../constants.ts";
24+
import { isFeatureEnabled } from "../posthog.ts";
2425
import {
2526
createNodesTable,
2627
durationOption,
@@ -240,7 +241,10 @@ Examples:\n
240241

241242
async function createNodesAction(
242243
names: typeof create.args,
243-
options: ReturnType<typeof create.opts> & { image?: string },
244+
options: ReturnType<typeof create.opts> & {
245+
image?: string;
246+
enableInfiniband?: boolean;
247+
},
244248
) {
245249
try {
246250
const client = await nodesClient();
@@ -274,6 +278,7 @@ async function createNodesAction(
274278
cloud_init_user_data: encodedUserData,
275279
image_id: options.image,
276280
node_type: isReserved ? "reserved" : "autoreserved",
281+
...(options.enableInfiniband ? { _preview_enable_infiniband: true } : {}),
277282
};
278283

279284
if (isReserved) {
@@ -497,4 +502,26 @@ async function createNodesAction(
497502
}
498503
}
499504

505+
/**
506+
* Attach the `create` subcommand to the given `nodes` parent command.
507+
*
508+
* Encapsulates the `infiniband-preview` feature-flag check: when the flag is
509+
* enabled for the current account, `--enable-infiniband` is mounted on the
510+
* command (and shows up in `sf nodes create --help`); otherwise the option is
511+
* not registered and the CLI surface is unchanged. The wire field
512+
* (`_preview_enable_infiniband`) is still in preview, so the option may change
513+
* without notice.
514+
*/
515+
export async function registerCreate(nodes: Command) {
516+
if (await isFeatureEnabled("infiniband-preview")) {
517+
create.addOption(
518+
new Option(
519+
"--enable-infiniband",
520+
"Enable InfiniBand on the nodes (preview).",
521+
),
522+
);
523+
}
524+
nodes.addCommand(create);
525+
}
526+
500527
export default create;

src/lib/nodes/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import console from "node:console";
22
import type { Command } from "@commander-js/extra-typings";
33

4-
import create from "./create.ts";
4+
import { registerCreate } from "./create.ts";
55
import deleteCommand from "./delete.ts";
66
import extend from "./extend.ts";
77
import get from "./get.tsx";
@@ -13,15 +13,14 @@ import release from "./release.ts";
1313
import set from "./set.ts";
1414
import ssh from "./ssh.ts";
1515

16-
export function registerNodes(program: Command) {
16+
export async function registerNodes(program: Command) {
1717
const nodes = program
1818
.command("nodes")
1919
.alias("node")
2020
.showHelpAfterError()
2121
.description("Manage compute nodes")
2222
.addCommand(list)
2323
.addCommand(get)
24-
.addCommand(create)
2524
.addCommand(extend)
2625
.addCommand(release)
2726
.addCommand(deleteCommand)
@@ -30,6 +29,7 @@ export function registerNodes(program: Command) {
3029
.addCommand(ssh)
3130
.addCommand(logs)
3231
.addCommand(image);
32+
await registerCreate(nodes);
3333

3434
const baseHelpText = nodes.helpInformation();
3535

src/lib/posthog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const trackEvent = ({
6262
}
6363
};
6464

65-
type FeatureFlags = "procurements" | "zones";
65+
type FeatureFlags = "procurements" | "zones" | "infiniband-preview";
6666

6767
/**
6868
* Checks if a feature is enabled for the current user.

0 commit comments

Comments
 (0)