import {z} from 'zod' export type V1Time = string; export type ContainerObjectMeta = {annotations: {[key: string]: string}, creationTimestamp: V1Time, deletionTimestamp: V1Time, labels: {[key: string]: string}, name: string, resourceVersion?: string | undefined, uid: string, workspace: string}; export type ContainerNodeCRIConfig = {runtime: 'containerd' | 'docker'} | null; export type ContainerSotoonMachineTemplate = {iamEnabled: boolean, instanceType: string}; export type ContainerSKEVersion = {kubernetesVersion: string, patchVersion: string}; export type ContainerSotoonNodepoolSpec = {allowedUnsafeSysctls?: Array | undefined, clusterName: string, cri?: ContainerNodeCRIConfig | undefined, labels?: {[key: string]: string} | undefined, replicas: number, template: ContainerSotoonMachineTemplate, version: ContainerSKEVersion}; export type V1Condition = {lastTransitionTime: V1Time, message: string, observedGeneration?: number | undefined, reason: string, status: string, type: string}; export type ContainerSotoonNodepoolStatus = {availableReplicas: number, conditions?: Array | undefined, phase: 'ScalingUp' | 'ScalingDown' | 'Running' | 'Failed' | 'Provisioning' | 'Unknown', ready: boolean, readyReplicas: number, replicas: number, unavailableReplicas: number, updatedReplicas: number}; export type ContainerSotoonNodepool = {apiVersion: 'ske.sotoon.ir/v1alpha1', kind: 'SotoonNodepool', metadata: ContainerObjectMeta, spec: ContainerSotoonNodepoolSpec, status: ContainerSotoonNodepoolStatus}; export type UpdateApiSkeV2alpha1Thr3StandardWorkspacesWorkspaceUUIDSotoonnodepoolsResourceIdArgs = {resourceId: string, workspaceUUID: string, body: ContainerSotoonNodepool}; export type UpdateApiSkeV2alpha1Thr3StandardWorkspacesWorkspaceUUIDSotoonnodepoolsResourceIdOptions = {baseUrl: string, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const v1Time = z.string(); export const containerObjectMeta = z.object({annotations: z.record(z.string(), z.string()), creationTimestamp: v1Time, deletionTimestamp: v1Time, labels: z.record(z.string(), z.string()), name: z.string(), resourceVersion: z.string().optional(), uid: z.string(), workspace: z.string()}); export const containerNodeCRIConfig = z.object({runtime: z.enum(["containerd", "docker"])}).nullable(); export const containerSotoonMachineTemplate = z.object({iamEnabled: z.boolean(), instanceType: z.string()}); export const containerSKEVersion = z.object({kubernetesVersion: z.string(), patchVersion: z.string()}); export const containerSotoonNodepoolSpec = z.object({allowedUnsafeSysctls: z.array(z.string()).optional(), clusterName: z.string(), cri: containerNodeCRIConfig.optional(), labels: z.record(z.string(), z.string()).optional(), replicas: z.number().int(), template: containerSotoonMachineTemplate, version: containerSKEVersion}); export const v1Condition = z.object({lastTransitionTime: v1Time, message: z.string(), observedGeneration: z.number().int().optional(), reason: z.string(), status: z.string(), type: z.string()}); export const containerSotoonNodepoolStatus = z.object({availableReplicas: z.number().int(), conditions: z.array(v1Condition).optional(), phase: z.enum(["ScalingUp", "ScalingDown", "Running", "Failed", "Provisioning", "Unknown"]), ready: z.boolean(), readyReplicas: z.number().int(), replicas: z.number().int(), unavailableReplicas: z.number().int(), updatedReplicas: z.number().int()}); export const containerSotoonNodepool = z.object({apiVersion: z.literal("ske.sotoon.ir/v1alpha1"), kind: z.literal("SotoonNodepool"), metadata: containerObjectMeta, spec: containerSotoonNodepoolSpec, status: containerSotoonNodepoolStatus}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Replace NodePool * * PUT /ske/v2alpha1/thr3-standard/workspaces/{workspaceUUID}/sotoonnodepools/{resourceId} */ export const updateApiSkeV2alpha1Thr3StandardWorkspacesWorkspaceUUIDSotoonnodepoolsResourceId = async (args: UpdateApiSkeV2alpha1Thr3StandardWorkspacesWorkspaceUUIDSotoonnodepoolsResourceIdArgs, options: UpdateApiSkeV2alpha1Thr3StandardWorkspacesWorkspaceUUIDSotoonnodepoolsResourceIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerToken !== undefined) headers.set('authorization', `Bearer ${BearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/ske/v2alpha1/thr3-standard/workspaces/${encodeURIComponent(String(args.workspaceUUID))}/sotoonnodepools/${encodeURIComponent(String(args.resourceId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(containerSotoonNodepool, await res.json()) };