Skip to content

Commit 9db240b

Browse files
committed
refactor(sdk): share the TypeScript GetSandbox call for owner lookup
Reuse get's request and error mapping for the owner lookup, and point the routing headers at their documented contract. Part of NVIDIA#4223 Signed-off-by: divesh <[email protected]>
1 parent 82fc0cd commit 9db240b

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

‎sdk/typescript/src/client.ts‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,12 +1275,7 @@ export class SandboxClient {
12751275
}
12761276

12771277
async get(name: string, options?: SandboxCallOptions | null): Promise<SandboxRef> {
1278-
try {
1279-
const resp = await this.grpc.getSandbox({ ...namedTarget(name, options) }, requestCallOptions(options));
1280-
return sandboxRef(resp.sandbox);
1281-
} catch (e) {
1282-
throw fromConnect(e);
1283-
}
1278+
return this.getSandbox(name, options);
12841279
}
12851280

12861281
// get() that also asks the gateway which replica owns the supervisor session.
@@ -1289,18 +1284,22 @@ export class SandboxClient {
12891284
options?: SandboxCallOptions | null,
12901285
): Promise<{ ref: SandboxRef; owner?: string }> {
12911286
let owner: string | undefined;
1287+
const ref = await this.getSandbox(name, options, {
1288+
headers: { [OWNER_REQUEST_HEADER]: '1' },
1289+
onHeader: (header) => {
1290+
owner = header.get(OWNER_REPLICA_HEADER) || undefined;
1291+
},
1292+
});
1293+
return { ref, owner };
1294+
}
1295+
1296+
private async getSandbox(name: string, options?: SandboxCallOptions | null, call?: CallOptions): Promise<SandboxRef> {
12921297
try {
12931298
const resp = await this.grpc.getSandbox(
12941299
{ ...namedTarget(name, options) },
1295-
{
1296-
...requestCallOptions(options),
1297-
headers: { [OWNER_REQUEST_HEADER]: '1' },
1298-
onHeader: (header) => {
1299-
owner = header.get(OWNER_REPLICA_HEADER) || undefined;
1300-
},
1301-
},
1300+
{ ...requestCallOptions(options), ...call },
13021301
);
1303-
return { ref: sandboxRef(resp.sandbox), owner };
1302+
return sandboxRef(resp.sandbox);
13041303
} catch (e) {
13051304
throw fromConnect(e);
13061305
}

‎sdk/typescript/src/routing.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
// Metadata that lets an edge proxy send a sandbox's long-lived calls straight
5-
// to the gateway replica holding its supervisor session.
5+
// to the gateway replica holding its supervisor session. The headers and the
6+
// retry rule are documented in docs/kubernetes/ingress.mdx.
67

78
import { Code, ConnectError } from '@connectrpc/connect';
89

0 commit comments

Comments
 (0)