From 551222617ddb87ec7e10fa5bf83917e74784355a Mon Sep 17 00:00:00 2001 From: Alistair Smith Date: Wed, 21 Sep 2022 17:37:56 +0100 Subject: [PATCH 1/3] feat: implement VolumeDefinition --- src/rest/types/ignite.ts | 31 +++++++++++++++++++++++++++++-- src/util/size.ts | 7 +++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/rest/types/ignite.ts b/src/rest/types/ignite.ts index 671a1ab8..3c526cef 100644 --- a/src/rest/types/ignite.ts +++ b/src/rest/types/ignite.ts @@ -1,4 +1,4 @@ -import {ByteString} from '../../util/index.js'; +import {ByteSizeString} from '../../util/index.js'; import {Endpoint} from '../endpoints.js'; import { Empty, @@ -83,6 +83,28 @@ export enum VgpuType { A400 = 'a400', } +export enum VolumeFormat { + EXT4 = 'ext4', + XFS = 'xfs', +} + +export interface VolumeDefinition { + /** + * The format of the volume + */ + fs: VolumeFormat; + + /** + * The size of the volume in bytes + */ + size: ByteSizeString; + + /** + * The mount point of the volume + */ + mount_path: string; +} + export interface Container { /** * The ID of the container @@ -124,6 +146,11 @@ export interface Container { */ type: RuntimeType; + /** + * The volume definition for this container + */ + volume: VolumeDefinition | null; + /** * The internal IP of the container */ @@ -277,7 +304,7 @@ export interface Resources { * Amount of memory to allocate in a readible format * You can use the `parseSize` function to convert this to bytes. */ - ram: ByteString; + ram: ByteSizeString; /** * vGPUs to allocate diff --git a/src/util/size.ts b/src/util/size.ts index 42c06c87..74b02f89 100644 --- a/src/util/size.ts +++ b/src/util/size.ts @@ -4,9 +4,12 @@ export type ByteUnit = | typeof byteUnits[number] | Uppercase; -export type ByteString = `${number}${ByteUnit}`; +export type ByteSizeString = `${number}${ByteUnit}`; -export function isValidByteString(value: string): value is ByteString { +/** @deprecated */ +export type ByteString = ByteSizeString; + +export function isValidByteString(value: string): value is ByteSizeString { return byteUnits.some(unit => { if (!value.endsWith(unit)) { return false; From 6eff9438ee1827fefd6b24b8458d0a78b14c37d3 Mon Sep 17 00:00:00 2001 From: Alistair Smith Date: Wed, 21 Sep 2022 17:41:18 +0100 Subject: [PATCH 2/3] fix: deployment config add support for volume --- src/rest/types/ignite.ts | 9 ++++++++- src/sdks/ignite.ts | 13 ++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/rest/types/ignite.ts b/src/rest/types/ignite.ts index 3c526cef..d71d1a9b 100644 --- a/src/rest/types/ignite.ts +++ b/src/rest/types/ignite.ts @@ -191,7 +191,7 @@ export interface Deployment { /** * The config for this deployment */ - config: DeploymentConfig; + config: Omit; } // This is a type not an interface so we can make a union @@ -240,6 +240,13 @@ export type DeploymentConfig = { * Restart policy for this deployment */ restart_policy: RestartPolicy; + + /** + * The volume definition for this deployment + * + * This can only be used when .type is 'stateful' + */ + volume?: VolumeDefinition; }; /** diff --git a/src/sdks/ignite.ts b/src/sdks/ignite.ts index eff0a4c1..7dd6f324 100644 --- a/src/sdks/ignite.ts +++ b/src/sdks/ignite.ts @@ -1,6 +1,11 @@ import {create, Infer} from '@onehop/json-methods'; import {API, assertId, Id} from '../rest/index.js'; -import {Deployment, Gateway, GatewayType} from '../rest/types/ignite.js'; +import { + Deployment, + Gateway, + GatewayType, + RuntimeType, +} from '../rest/types/ignite.js'; import {parseSize, validateId} from '../util/index.js'; import {sdk} from './create.js'; @@ -106,6 +111,12 @@ export const ignite = sdk(client => { ); } + if (config.volume && config.type !== RuntimeType.STATEFUL) { + throw new Error( + 'Cannot create a deployment with a volume that is not stateful.', + ); + } + const {deployment} = await client.post('/v1/ignite/deployments', config, { project, }); From a8a82bdd6d4a1470c2252918964defdd7d9c0764 Mon Sep 17 00:00:00 2001 From: Alistair Smith Date: Wed, 21 Sep 2022 17:41:46 +0100 Subject: [PATCH 3/3] docs(changeset): Added volume config to creating a deployment --- .changeset/few-toys-kick.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/few-toys-kick.md diff --git a/.changeset/few-toys-kick.md b/.changeset/few-toys-kick.md new file mode 100644 index 00000000..bb3a9048 --- /dev/null +++ b/.changeset/few-toys-kick.md @@ -0,0 +1,5 @@ +--- +'@onehop/js': patch +--- + +Added volume config to creating a deployment