Skip to content
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
42 changes: 42 additions & 0 deletions packages/clients/src/api/k8s/v1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
marshalUpgradePoolRequest,
unmarshalCluster,
unmarshalExternalNode,
unmarshalExternalNodeAuth,
unmarshalListClusterAvailableTypesResponse,
unmarshalListClusterAvailableVersionsResponse,
unmarshalListClusterTypesResponse,
Expand All @@ -31,10 +32,12 @@ import {
unmarshalListPoolsResponse,
unmarshalListVersionsResponse,
unmarshalNode,
unmarshalNodeMetadata,
unmarshalPool,
unmarshalVersion,
} from './marshalling.gen'
import type {
AuthExternalNodeRequest,
Cluster,
CreateClusterRequest,
CreateExternalNodeRequest,
Expand All @@ -43,8 +46,10 @@ import type {
DeleteNodeRequest,
DeletePoolRequest,
ExternalNode,
ExternalNodeAuth,
GetClusterKubeConfigRequest,
GetClusterRequest,
GetNodeMetadataRequest,
GetNodeRequest,
GetPoolRequest,
GetVersionRequest,
Expand All @@ -64,6 +69,7 @@ import type {
ListVersionsResponse,
MigrateClusterToRoutedIPsRequest,
Node,
NodeMetadata,
Pool,
RebootNodeRequest,
ReplaceNodeRequest,
Expand Down Expand Up @@ -487,6 +493,42 @@ export class API extends ParentAPI {
unmarshalPool,
)

/**
* Fetch node metadata. Rerieve metadata to instantiate a Kapsule/Kosmos node.
* This method is not intended to be called by end users but rather
* programmatically by the node-installer.
*
* @param request - The request {@link GetNodeMetadataRequest}
* @returns A Promise of NodeMetadata
*/
getNodeMetadata = (request: Readonly<GetNodeMetadataRequest> = {}) =>
this.client.fetch<NodeMetadata>(
{
method: 'GET',
path: `/k8s/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/nodes/metadata`,
},
unmarshalNodeMetadata,
)

/**
* Authenticate Kosmos external node. Creates a newer Kosmos node and returns
* its token. This method is not intended to be called by end users but rather
* programmatically by the node-installer.
*
* @param request - The request {@link AuthExternalNodeRequest}
* @returns A Promise of ExternalNodeAuth
*/
authExternalNode = (request: Readonly<AuthExternalNodeRequest>) =>
this.client.fetch<ExternalNodeAuth>(
{
body: '{}',
headers: jsonContentHeaders,
method: 'POST',
path: `/k8s/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/pools/${validatePathParam('poolId', request.poolId)}/external-nodes/auth`,
},
unmarshalExternalNodeAuth,
)

/**
* Create a Kosmos node. Retrieve metadata for a Kosmos node. This method is
* not intended to be called by end users but rather programmatically by the
Expand Down
5 changes: 5 additions & 0 deletions packages/clients/src/api/k8s/v1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export { API } from './api.gen'
export * from './content.gen'
export type {
AuthExternalNodeRequest,
AutoscalerEstimator,
AutoscalerExpander,
CNI,
Expand All @@ -27,9 +28,11 @@ export type {
DeleteNodeRequest,
DeletePoolRequest,
ExternalNode,
ExternalNodeAuth,
ExternalNodeCoreV1Taint,
GetClusterKubeConfigRequest,
GetClusterRequest,
GetNodeMetadataRequest,
GetNodeRequest,
GetPoolRequest,
GetVersionRequest,
Expand All @@ -54,6 +57,8 @@ export type {
MaintenanceWindowDayOfTheWeek,
MigrateClusterToRoutedIPsRequest,
Node,
NodeMetadata,
NodeMetadataCoreV1Taint,
NodeStatus,
Pool,
PoolStatus,
Expand Down
60 changes: 60 additions & 0 deletions packages/clients/src/api/k8s/v1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
CreatePoolRequest,
CreatePoolRequestUpgradePolicy,
ExternalNode,
ExternalNodeAuth,
ExternalNodeCoreV1Taint,
ListClusterAvailableTypesResponse,
ListClusterAvailableVersionsResponse,
Expand All @@ -33,6 +34,8 @@ import type {
ListVersionsResponse,
MaintenanceWindow,
Node,
NodeMetadata,
NodeMetadataCoreV1Taint,
Pool,
PoolUpgradePolicy,
SetClusterTypeRequest,
Expand Down Expand Up @@ -295,6 +298,19 @@ export const unmarshalExternalNode = (data: unknown): ExternalNode => {
} as ExternalNode
}

export const unmarshalExternalNodeAuth = (data: unknown): ExternalNodeAuth => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'ExternalNodeAuth' failed as data isn't a dictionary.`,
)
}

return {
apiUrl: data.api_url,
nodeToken: data.node_token,
} as ExternalNodeAuth
}

const unmarshalClusterType = (data: unknown): ClusterType => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand Down Expand Up @@ -424,6 +440,50 @@ export const unmarshalListVersionsResponse = (
} as ListVersionsResponse
}

const unmarshalNodeMetadataCoreV1Taint = (
data: unknown,
): NodeMetadataCoreV1Taint => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'NodeMetadataCoreV1Taint' failed as data isn't a dictionary.`,
)
}

return {
effect: data.effect,
key: data.key,
value: data.value,
} as NodeMetadataCoreV1Taint
}

export const unmarshalNodeMetadata = (data: unknown): NodeMetadata => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'NodeMetadata' failed as data isn't a dictionary.`,
)
}

return {
clusterCa: data.cluster_ca,
clusterUrl: data.cluster_url,
credentialProviderConfig: data.credential_provider_config,
externalIp: data.external_ip,
fullIsolation: data.full_isolation,
hasGpu: data.has_gpu,
id: data.id,
kapsuleIfaceMac: data.kapsule_iface_mac,
kubeletConfig: data.kubelet_config,
name: data.name,
nodeLabels: data.node_labels,
nodeTaints: unmarshalArrayOfObject(
data.node_taints,
unmarshalNodeMetadataCoreV1Taint,
),
poolVersion: data.pool_version,
privateNetworkMode: data.private_network_mode,
} as NodeMetadata
}

const marshalMaintenanceWindow = (
request: MaintenanceWindow,
defaults: DefaultValues,
Expand Down
46 changes: 46 additions & 0 deletions packages/clients/src/api/k8s/v1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,12 @@ export interface Node {
updatedAt?: Date
}

export interface NodeMetadataCoreV1Taint {
key: string
value: string
effect: string
}

export interface UpdateClusterRequestAutoUpgrade {
/** Defines whether auto upgrade is enabled for the cluster. */
enable?: boolean
Expand Down Expand Up @@ -676,6 +682,16 @@ export interface UpdatePoolRequestUpgradePolicy {
maxSurge?: number
}

export type AuthExternalNodeRequest = {
/**
* Region to target. If none is passed will use default region from the
* config.
*/
region?: Region
/** Pool the node will be attached to. */
poolId: string
}

export type CreateClusterRequest = {
/**
* Region to target. If none is passed will use default region from the
Expand Down Expand Up @@ -885,6 +901,11 @@ export interface ExternalNode {
nodeTaints: ExternalNodeCoreV1Taint[]
}

export interface ExternalNodeAuth {
nodeToken: string
apiUrl: string
}

export type GetClusterKubeConfigRequest = {
/**
* Region to target. If none is passed will use default region from the
Expand All @@ -907,6 +928,14 @@ export type GetClusterRequest = {
clusterId: string
}

export type GetNodeMetadataRequest = {
/**
* Region to target. If none is passed will use default region from the
* config.
*/
region?: Region
}

export type GetNodeRequest = {
/**
* Region to target. If none is passed will use default region from the
Expand Down Expand Up @@ -1111,6 +1140,23 @@ export type MigrateClusterToRoutedIPsRequest = {
clusterId: string
}

export interface NodeMetadata {
id: string
name: string
clusterUrl: string
clusterCa: string
credentialProviderConfig: string
poolVersion: string
kubeletConfig: string
nodeLabels: Record<string, string>
nodeTaints: NodeMetadataCoreV1Taint[]
privateNetworkMode: string
kapsuleIfaceMac: string
fullIsolation: boolean
hasGpu: boolean
externalIp: string
}

export type RebootNodeRequest = {
/**
* Region to target. If none is passed will use default region from the
Expand Down