diff --git a/packages/clients/src/api/k8s/v1/api.gen.ts b/packages/clients/src/api/k8s/v1/api.gen.ts index 89baa6281..e7285dbfd 100644 --- a/packages/clients/src/api/k8s/v1/api.gen.ts +++ b/packages/clients/src/api/k8s/v1/api.gen.ts @@ -23,6 +23,7 @@ import { marshalUpgradePoolRequest, unmarshalCluster, unmarshalExternalNode, + unmarshalExternalNodeAuth, unmarshalListClusterAvailableTypesResponse, unmarshalListClusterAvailableVersionsResponse, unmarshalListClusterTypesResponse, @@ -31,10 +32,12 @@ import { unmarshalListPoolsResponse, unmarshalListVersionsResponse, unmarshalNode, + unmarshalNodeMetadata, unmarshalPool, unmarshalVersion, } from './marshalling.gen' import type { + AuthExternalNodeRequest, Cluster, CreateClusterRequest, CreateExternalNodeRequest, @@ -43,8 +46,10 @@ import type { DeleteNodeRequest, DeletePoolRequest, ExternalNode, + ExternalNodeAuth, GetClusterKubeConfigRequest, GetClusterRequest, + GetNodeMetadataRequest, GetNodeRequest, GetPoolRequest, GetVersionRequest, @@ -64,6 +69,7 @@ import type { ListVersionsResponse, MigrateClusterToRoutedIPsRequest, Node, + NodeMetadata, Pool, RebootNodeRequest, ReplaceNodeRequest, @@ -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 = {}) => + this.client.fetch( + { + 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) => + this.client.fetch( + { + 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 diff --git a/packages/clients/src/api/k8s/v1/index.gen.ts b/packages/clients/src/api/k8s/v1/index.gen.ts index aea48b8be..864f930e2 100644 --- a/packages/clients/src/api/k8s/v1/index.gen.ts +++ b/packages/clients/src/api/k8s/v1/index.gen.ts @@ -3,6 +3,7 @@ export { API } from './api.gen' export * from './content.gen' export type { + AuthExternalNodeRequest, AutoscalerEstimator, AutoscalerExpander, CNI, @@ -27,9 +28,11 @@ export type { DeleteNodeRequest, DeletePoolRequest, ExternalNode, + ExternalNodeAuth, ExternalNodeCoreV1Taint, GetClusterKubeConfigRequest, GetClusterRequest, + GetNodeMetadataRequest, GetNodeRequest, GetPoolRequest, GetVersionRequest, @@ -54,6 +57,8 @@ export type { MaintenanceWindowDayOfTheWeek, MigrateClusterToRoutedIPsRequest, Node, + NodeMetadata, + NodeMetadataCoreV1Taint, NodeStatus, Pool, PoolStatus, diff --git a/packages/clients/src/api/k8s/v1/marshalling.gen.ts b/packages/clients/src/api/k8s/v1/marshalling.gen.ts index 7e3c940c3..ae0fe1d33 100644 --- a/packages/clients/src/api/k8s/v1/marshalling.gen.ts +++ b/packages/clients/src/api/k8s/v1/marshalling.gen.ts @@ -23,6 +23,7 @@ import type { CreatePoolRequest, CreatePoolRequestUpgradePolicy, ExternalNode, + ExternalNodeAuth, ExternalNodeCoreV1Taint, ListClusterAvailableTypesResponse, ListClusterAvailableVersionsResponse, @@ -33,6 +34,8 @@ import type { ListVersionsResponse, MaintenanceWindow, Node, + NodeMetadata, + NodeMetadataCoreV1Taint, Pool, PoolUpgradePolicy, SetClusterTypeRequest, @@ -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( @@ -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, diff --git a/packages/clients/src/api/k8s/v1/types.gen.ts b/packages/clients/src/api/k8s/v1/types.gen.ts index 2a1105519..272ed32c7 100644 --- a/packages/clients/src/api/k8s/v1/types.gen.ts +++ b/packages/clients/src/api/k8s/v1/types.gen.ts @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 + 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