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 ContainerNetworkRanges = {cidrBlocks: Array} | null; export type ContainerClusterNetwork = {pods?: ContainerNetworkRanges | undefined, services?: ContainerNetworkRanges | undefined} | null; export type ContainerSKEVersion = {kubernetesVersion: string, patchVersion: string}; export type ContainerClusterInfrastructureSpec = {VPC: string, subnet: string, version: ContainerSKEVersion}; export type ContainerSotoonClusterSpec = {clusterNetwork?: ContainerClusterNetwork | undefined, infra: ContainerClusterInfrastructureSpec}; export type V1Condition = {lastTransitionTime: V1Time, message: string, observedGeneration?: number | undefined, reason: string, status: string, type: string}; export type ContainerLocalObjectRef = {name: string} | null; export type ContainerSotoonClusterStatus = {conditions?: Array | undefined, kubeconfigSecretName?: ContainerLocalObjectRef | undefined, phase: 'Provisioned' | 'Provisioning' | 'Initialized' | 'Ready' | 'Failed' | 'Upgrading' | 'Deleting' | 'HighlyAvailable' | 'Unknown', ready: boolean, readyReplicas: number, replicas: number, unavailableReplicas: number, updatedReplicas: number}; export type ContainerSotoonCluster = {apiVersion: 'ske.sotoon.ir/v1alpha1', kind: 'SotoonCluster', metadata: ContainerObjectMeta, spec: ContainerSotoonClusterSpec, status: ContainerSotoonClusterStatus}; export type UpdateApiSkeV2alpha1Thr3StandardWorkspacesWorkspaceUUIDSotoonclustersResourceIdArgs = {resourceId: string, workspaceUUID: string, body: ContainerSotoonCluster}; export type UpdateApiSkeV2alpha1Thr3StandardWorkspacesWorkspaceUUIDSotoonclustersResourceIdOptions = {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 containerNetworkRanges = z.object({cidrBlocks: z.array(z.string())}).nullable(); export const containerClusterNetwork = z.object({pods: containerNetworkRanges.optional(), services: containerNetworkRanges.optional()}).nullable(); export const containerSKEVersion = z.object({kubernetesVersion: z.string(), patchVersion: z.string()}); export const containerClusterInfrastructureSpec = z.object({VPC: z.string(), subnet: z.string(), version: containerSKEVersion}); export const containerSotoonClusterSpec = z.object({clusterNetwork: containerClusterNetwork.optional(), infra: containerClusterInfrastructureSpec}); 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 containerLocalObjectRef = z.object({name: z.string()}).nullable(); export const containerSotoonClusterStatus = z.object({conditions: z.array(v1Condition).optional(), kubeconfigSecretName: containerLocalObjectRef.optional(), phase: z.enum(["Provisioned", "Provisioning", "Initialized", "Ready", "Failed", "Upgrading", "Deleting", "HighlyAvailable", "Unknown"]), ready: z.boolean(), readyReplicas: z.number().int(), replicas: z.number().int(), unavailableReplicas: z.number().int(), updatedReplicas: z.number().int()}); export const containerSotoonCluster = z.object({apiVersion: z.literal("ske.sotoon.ir/v1alpha1"), kind: z.literal("SotoonCluster"), metadata: containerObjectMeta, spec: containerSotoonClusterSpec, status: containerSotoonClusterStatus}); 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 Cluster * * PUT /ske/v2alpha1/thr3-standard/workspaces/{workspaceUUID}/sotoonclusters/{resourceId} */ export const updateApiSkeV2alpha1Thr3StandardWorkspacesWorkspaceUUIDSotoonclustersResourceId = async (args: UpdateApiSkeV2alpha1Thr3StandardWorkspacesWorkspaceUUIDSotoonclustersResourceIdArgs, options: UpdateApiSkeV2alpha1Thr3StandardWorkspacesWorkspaceUUIDSotoonclustersResourceIdOptions) => { 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))}/sotoonclusters/${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(containerSotoonCluster, await res.json()) };