Skip to content

Commit 434edec

Browse files
feat(k8s): rationalize node bootstrap (#1381)
Co-authored-by: Jules Castéran <[email protected]>
1 parent dc41d06 commit 434edec

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

packages/clients/src/api/k8s/v1/api.gen.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
marshalUpgradePoolRequest,
2424
unmarshalCluster,
2525
unmarshalExternalNode,
26+
unmarshalExternalNodeAuth,
2627
unmarshalListClusterAvailableTypesResponse,
2728
unmarshalListClusterAvailableVersionsResponse,
2829
unmarshalListClusterTypesResponse,
@@ -31,10 +32,12 @@ import {
3132
unmarshalListPoolsResponse,
3233
unmarshalListVersionsResponse,
3334
unmarshalNode,
35+
unmarshalNodeMetadata,
3436
unmarshalPool,
3537
unmarshalVersion,
3638
} from './marshalling.gen'
3739
import type {
40+
AuthExternalNodeRequest,
3841
Cluster,
3942
CreateClusterRequest,
4043
CreateExternalNodeRequest,
@@ -43,8 +46,10 @@ import type {
4346
DeleteNodeRequest,
4447
DeletePoolRequest,
4548
ExternalNode,
49+
ExternalNodeAuth,
4650
GetClusterKubeConfigRequest,
4751
GetClusterRequest,
52+
GetNodeMetadataRequest,
4853
GetNodeRequest,
4954
GetPoolRequest,
5055
GetVersionRequest,
@@ -64,6 +69,7 @@ import type {
6469
ListVersionsResponse,
6570
MigrateClusterToRoutedIPsRequest,
6671
Node,
72+
NodeMetadata,
6773
Pool,
6874
RebootNodeRequest,
6975
ReplaceNodeRequest,
@@ -487,6 +493,42 @@ export class API extends ParentAPI {
487493
unmarshalPool,
488494
)
489495

496+
/**
497+
* Fetch node metadata. Rerieve metadata to instantiate a Kapsule/Kosmos node.
498+
* This method is not intended to be called by end users but rather
499+
* programmatically by the node-installer.
500+
*
501+
* @param request - The request {@link GetNodeMetadataRequest}
502+
* @returns A Promise of NodeMetadata
503+
*/
504+
getNodeMetadata = (request: Readonly<GetNodeMetadataRequest> = {}) =>
505+
this.client.fetch<NodeMetadata>(
506+
{
507+
method: 'GET',
508+
path: `/k8s/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/nodes/metadata`,
509+
},
510+
unmarshalNodeMetadata,
511+
)
512+
513+
/**
514+
* Authenticate Kosmos external node. Creates a newer Kosmos node and returns
515+
* its token. This method is not intended to be called by end users but rather
516+
* programmatically by the node-installer.
517+
*
518+
* @param request - The request {@link AuthExternalNodeRequest}
519+
* @returns A Promise of ExternalNodeAuth
520+
*/
521+
authExternalNode = (request: Readonly<AuthExternalNodeRequest>) =>
522+
this.client.fetch<ExternalNodeAuth>(
523+
{
524+
body: '{}',
525+
headers: jsonContentHeaders,
526+
method: 'POST',
527+
path: `/k8s/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/pools/${validatePathParam('poolId', request.poolId)}/external-nodes/auth`,
528+
},
529+
unmarshalExternalNodeAuth,
530+
)
531+
490532
/**
491533
* Create a Kosmos node. Retrieve metadata for a Kosmos node. This method is
492534
* not intended to be called by end users but rather programmatically by the

packages/clients/src/api/k8s/v1/index.gen.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export { API } from './api.gen'
44
export * from './content.gen'
55
export type {
6+
AuthExternalNodeRequest,
67
AutoscalerEstimator,
78
AutoscalerExpander,
89
CNI,
@@ -27,9 +28,11 @@ export type {
2728
DeleteNodeRequest,
2829
DeletePoolRequest,
2930
ExternalNode,
31+
ExternalNodeAuth,
3032
ExternalNodeCoreV1Taint,
3133
GetClusterKubeConfigRequest,
3234
GetClusterRequest,
35+
GetNodeMetadataRequest,
3336
GetNodeRequest,
3437
GetPoolRequest,
3538
GetVersionRequest,
@@ -54,6 +57,8 @@ export type {
5457
MaintenanceWindowDayOfTheWeek,
5558
MigrateClusterToRoutedIPsRequest,
5659
Node,
60+
NodeMetadata,
61+
NodeMetadataCoreV1Taint,
5762
NodeStatus,
5863
Pool,
5964
PoolStatus,

packages/clients/src/api/k8s/v1/marshalling.gen.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type {
2323
CreatePoolRequest,
2424
CreatePoolRequestUpgradePolicy,
2525
ExternalNode,
26+
ExternalNodeAuth,
2627
ExternalNodeCoreV1Taint,
2728
ListClusterAvailableTypesResponse,
2829
ListClusterAvailableVersionsResponse,
@@ -33,6 +34,8 @@ import type {
3334
ListVersionsResponse,
3435
MaintenanceWindow,
3536
Node,
37+
NodeMetadata,
38+
NodeMetadataCoreV1Taint,
3639
Pool,
3740
PoolUpgradePolicy,
3841
SetClusterTypeRequest,
@@ -295,6 +298,19 @@ export const unmarshalExternalNode = (data: unknown): ExternalNode => {
295298
} as ExternalNode
296299
}
297300

301+
export const unmarshalExternalNodeAuth = (data: unknown): ExternalNodeAuth => {
302+
if (!isJSONObject(data)) {
303+
throw new TypeError(
304+
`Unmarshalling the type 'ExternalNodeAuth' failed as data isn't a dictionary.`,
305+
)
306+
}
307+
308+
return {
309+
apiUrl: data.api_url,
310+
nodeToken: data.node_token,
311+
} as ExternalNodeAuth
312+
}
313+
298314
const unmarshalClusterType = (data: unknown): ClusterType => {
299315
if (!isJSONObject(data)) {
300316
throw new TypeError(
@@ -424,6 +440,50 @@ export const unmarshalListVersionsResponse = (
424440
} as ListVersionsResponse
425441
}
426442

443+
const unmarshalNodeMetadataCoreV1Taint = (
444+
data: unknown,
445+
): NodeMetadataCoreV1Taint => {
446+
if (!isJSONObject(data)) {
447+
throw new TypeError(
448+
`Unmarshalling the type 'NodeMetadataCoreV1Taint' failed as data isn't a dictionary.`,
449+
)
450+
}
451+
452+
return {
453+
effect: data.effect,
454+
key: data.key,
455+
value: data.value,
456+
} as NodeMetadataCoreV1Taint
457+
}
458+
459+
export const unmarshalNodeMetadata = (data: unknown): NodeMetadata => {
460+
if (!isJSONObject(data)) {
461+
throw new TypeError(
462+
`Unmarshalling the type 'NodeMetadata' failed as data isn't a dictionary.`,
463+
)
464+
}
465+
466+
return {
467+
clusterCa: data.cluster_ca,
468+
clusterUrl: data.cluster_url,
469+
credentialProviderConfig: data.credential_provider_config,
470+
externalIp: data.external_ip,
471+
fullIsolation: data.full_isolation,
472+
hasGpu: data.has_gpu,
473+
id: data.id,
474+
kapsuleIfaceMac: data.kapsule_iface_mac,
475+
kubeletConfig: data.kubelet_config,
476+
name: data.name,
477+
nodeLabels: data.node_labels,
478+
nodeTaints: unmarshalArrayOfObject(
479+
data.node_taints,
480+
unmarshalNodeMetadataCoreV1Taint,
481+
),
482+
poolVersion: data.pool_version,
483+
privateNetworkMode: data.private_network_mode,
484+
} as NodeMetadata
485+
}
486+
427487
const marshalMaintenanceWindow = (
428488
request: MaintenanceWindow,
429489
defaults: DefaultValues,

packages/clients/src/api/k8s/v1/types.gen.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,12 @@ export interface Node {
585585
updatedAt?: Date
586586
}
587587

588+
export interface NodeMetadataCoreV1Taint {
589+
key: string
590+
value: string
591+
effect: string
592+
}
593+
588594
export interface UpdateClusterRequestAutoUpgrade {
589595
/** Defines whether auto upgrade is enabled for the cluster. */
590596
enable?: boolean
@@ -676,6 +682,16 @@ export interface UpdatePoolRequestUpgradePolicy {
676682
maxSurge?: number
677683
}
678684

685+
export type AuthExternalNodeRequest = {
686+
/**
687+
* Region to target. If none is passed will use default region from the
688+
* config.
689+
*/
690+
region?: Region
691+
/** Pool the node will be attached to. */
692+
poolId: string
693+
}
694+
679695
export type CreateClusterRequest = {
680696
/**
681697
* Region to target. If none is passed will use default region from the
@@ -885,6 +901,11 @@ export interface ExternalNode {
885901
nodeTaints: ExternalNodeCoreV1Taint[]
886902
}
887903

904+
export interface ExternalNodeAuth {
905+
nodeToken: string
906+
apiUrl: string
907+
}
908+
888909
export type GetClusterKubeConfigRequest = {
889910
/**
890911
* Region to target. If none is passed will use default region from the
@@ -907,6 +928,14 @@ export type GetClusterRequest = {
907928
clusterId: string
908929
}
909930

931+
export type GetNodeMetadataRequest = {
932+
/**
933+
* Region to target. If none is passed will use default region from the
934+
* config.
935+
*/
936+
region?: Region
937+
}
938+
910939
export type GetNodeRequest = {
911940
/**
912941
* Region to target. If none is passed will use default region from the
@@ -1111,6 +1140,23 @@ export type MigrateClusterToRoutedIPsRequest = {
11111140
clusterId: string
11121141
}
11131142

1143+
export interface NodeMetadata {
1144+
id: string
1145+
name: string
1146+
clusterUrl: string
1147+
clusterCa: string
1148+
credentialProviderConfig: string
1149+
poolVersion: string
1150+
kubeletConfig: string
1151+
nodeLabels: Record<string, string>
1152+
nodeTaints: NodeMetadataCoreV1Taint[]
1153+
privateNetworkMode: string
1154+
kapsuleIfaceMac: string
1155+
fullIsolation: boolean
1156+
hasGpu: boolean
1157+
externalIp: string
1158+
}
1159+
11141160
export type RebootNodeRequest = {
11151161
/**
11161162
* Region to target. If none is passed will use default region from the

0 commit comments

Comments
 (0)