├── .github ├── README.md ├── dependabot.yml └── workflows │ └── deno-ci.yaml ├── generation ├── api-specs │ └── .gitignore ├── deno.json ├── sources │ ├── from-cluster.sh │ ├── builtin.sh │ ├── argo-cd.sh │ ├── cert-manager.sh │ ├── flux-cd.sh │ ├── external-dns.sh │ └── vpa.sh ├── generate-all.sh ├── mod.ts ├── known-opts.ts ├── codegen.ts ├── README.md └── openapi.ts ├── deno.json ├── lib ├── deps.ts ├── examples │ ├── list-crds.ts │ ├── argocd.ts │ ├── pod-exec-output.ts │ ├── demo.ts │ ├── follow-logs.ts │ ├── pod-portforward.ts │ ├── watch-nodes.ts │ ├── pod-exec-tty.ts │ ├── watch-ingress.ts │ ├── run-job.ts │ ├── run-job-evented.ts │ └── top-nodes.ts ├── builtin │ ├── authentication.k8s.io@v1 │ │ └── mod.ts │ ├── scheduling.k8s.io@v1 │ │ ├── structs.ts │ │ └── mod.ts │ ├── storage.k8s.io@v1beta1 │ │ ├── structs.ts │ │ └── mod.ts │ ├── storage.k8s.io@v1alpha1 │ │ ├── structs.ts │ │ └── mod.ts │ ├── coordination.k8s.io@v1 │ │ ├── structs.ts │ │ └── mod.ts │ ├── coordination.k8s.io@v1beta1 │ │ ├── structs.ts │ │ └── mod.ts │ ├── coordination.k8s.io@v1alpha2 │ │ ├── structs.ts │ │ └── mod.ts │ ├── certificates.k8s.io@v1beta1 │ │ ├── structs.ts │ │ └── mod.ts │ ├── authorization.k8s.io@v1 │ │ └── mod.ts │ ├── node.k8s.io@v1 │ │ ├── structs.ts │ │ └── mod.ts │ ├── events.k8s.io@v1 │ │ ├── structs.ts │ │ └── mod.ts │ ├── resource.k8s.io@v1alpha3 │ │ ├── mod.ts │ │ └── structs.ts │ ├── storagemigration.k8s.io@v1alpha1 │ │ └── structs.ts │ ├── apiregistration.k8s.io@v1 │ │ ├── structs.ts │ │ └── mod.ts │ ├── internal.apiserver.k8s.io@v1alpha1 │ │ ├── structs.ts │ │ └── mod.ts │ ├── policy@v1 │ │ └── structs.ts │ ├── certificates.k8s.io@v1 │ │ └── structs.ts │ ├── networking.k8s.io@v1beta1 │ │ └── structs.ts │ ├── discovery.k8s.io@v1 │ │ ├── mod.ts │ │ └── structs.ts │ └── autoscaling@v1 │ │ └── structs.ts ├── external-dns │ └── externaldns.k8s.io@v1alpha1 │ │ └── structs.ts ├── deno.json └── tunnels_test.ts ├── .devcontainer └── devcontainer.json └── deno.lock /.github/README.md: -------------------------------------------------------------------------------- 1 | ../lib/README.md -------------------------------------------------------------------------------- /generation/api-specs/.gitignore: -------------------------------------------------------------------------------- 1 | *.json 2 | */*.yaml 3 | -------------------------------------------------------------------------------- /deno.json: -------------------------------------------------------------------------------- 1 | { 2 | "workspace": [ 3 | "generation", 4 | "lib" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | 4 | - package-ecosystem: github-actions 5 | directory: / 6 | schedule: 7 | interval: monthly 8 | -------------------------------------------------------------------------------- /generation/deno.json: -------------------------------------------------------------------------------- 1 | { 2 | "imports": { 3 | "@cloudydeno/kubernetes-client": "jsr:@cloudydeno/kubernetes-client@^0.8", 4 | "@std/path": "jsr:@std/path@^1", 5 | "@std/yaml": "jsr:@std/yaml@^1" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /generation/sources/from-cluster.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -eux 2 | 3 | kubectl get --raw /openapi/v2 \ 4 | | jq . \ 5 | > generation/api-specs/from-cluster.json 6 | 7 | deno run \ 8 | --allow-read="generation/api-specs" \ 9 | --allow-write="lib/builtin" \ 10 | generation/mod.ts \ 11 | "generation/api-specs/from-cluster.json" \ 12 | "builtin" 13 | 14 | # deno check lib/builtin/*/structs.ts 15 | 16 | git status lib/builtin 17 | -------------------------------------------------------------------------------- /lib/deps.ts: -------------------------------------------------------------------------------- 1 | // This file is just the entire matching kubernetes-client version. 2 | // kubernetes-apis itself only depends on specific files, 3 | // so this is provided an optional utility. 4 | 5 | export * from "@cloudydeno/kubernetes-client"; 6 | 7 | export * from "@cloudydeno/kubernetes-client/lib/contract.ts"; 8 | export { 9 | WatchEventTransformer, 10 | } from "@cloudydeno/kubernetes-client/lib/stream-transformers.ts"; 11 | -------------------------------------------------------------------------------- /lib/examples/list-crds.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S deno run --allow-net --allow-read --allow-env --allow-run --unstable 2 | 3 | import { autoDetectClient, readAllItems } from '../deps.ts'; 4 | import { ApiextensionsV1Api } from "../builtin/apiextensions.k8s.io@v1/mod.ts"; 5 | 6 | const restClient = await autoDetectClient(); 7 | 8 | const appsApi = new ApiextensionsV1Api(restClient); 9 | for await (const crd of readAllItems(t => appsApi 10 | .getCustomResourceDefinitionList({ limit: 25, continue: t }))) { 11 | 12 | console.log(crd.metadata?.name, 13 | crd.spec.versions.map(x => x.name)); 14 | } 15 | -------------------------------------------------------------------------------- /generation/sources/builtin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -eux 2 | 3 | upstream="https://github.com/kubernetes/kubernetes" 4 | if [ ! -f generation/api-specs/builtin-"$1".json ] 5 | then wget \ 6 | "$upstream/raw/$1/api/openapi-spec/swagger.json" \ 7 | -O "generation/api-specs/builtin-$1.json" 8 | fi 9 | 10 | rm -r lib/builtin/* \ 11 | || true 12 | 13 | deno run \ 14 | --allow-read="generation/api-specs" \ 15 | --allow-write="lib/builtin" \ 16 | generation/mod.ts \ 17 | "generation/api-specs/builtin-$1.json" \ 18 | "builtin" 19 | 20 | deno check lib/builtin/*/structs.ts 21 | 22 | git status lib/builtin 23 | -------------------------------------------------------------------------------- /lib/examples/argocd.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S deno run --allow-net --allow-read --allow-env --allow-run --unstable 2 | 3 | import { autoDetectClient, readAllItems } from '../deps.ts'; 4 | import { ArgoprojIoV1alpha1NamespacedApi } from "../argo-cd/argoproj.io@v1alpha1/mod.ts"; 5 | 6 | const restClient = await autoDetectClient(); 7 | 8 | const argoApi = new ArgoprojIoV1alpha1NamespacedApi(restClient, 'argocd'); 9 | for await (const app of readAllItems(t => argoApi.getApplicationList({ limit: 25, continue: t }))) { 10 | console.log(app.status?.sync?.status, '/', app.status?.health?.status, '-', app.metadata?.name); 11 | } 12 | -------------------------------------------------------------------------------- /generation/generate-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -eux 2 | 3 | # https://github.com/kubernetes/kubernetes/releases 4 | ./generation/sources/builtin.sh v1.34.2 5 | 6 | # https://github.com/argoproj/argo-cd/releases 7 | ./generation/sources/argo-cd.sh v3.2.1 8 | 9 | # https://github.com/cert-manager/cert-manager/releases 10 | ./generation/sources/cert-manager.sh v1.19.1 11 | 12 | # https://github.com/kubernetes-sigs/external-dns/releases 13 | ./generation/sources/external-dns.sh v0.20.0 14 | 15 | # https://github.com/fluxcd/flux2/releases 16 | #./generation/sources/flux-cd.sh v2.6.4 17 | 18 | # https://github.com/kubernetes/autoscaler/releases?q=vertical 19 | ./generation/sources/vpa.sh 1.5.1 20 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/devcontainer.json. For config options, see the 2 | // README at: https://github.com/devcontainers/templates/tree/main/src/debian 3 | { 4 | "name": "Debian", 5 | "image": "mcr.microsoft.com/devcontainers/base:bookworm", 6 | "features": { 7 | "ghcr.io/prulloac/devcontainer-features/deno:1": {}, 8 | "ghcr.io/devcontainers/features/git-lfs:1": {}, 9 | "ghcr.io/devcontainers-extra/features/fish-apt-get:1": {} 10 | }, 11 | "customizations": { 12 | "vscode": { 13 | "extensions": [ 14 | "denoland.vscode-deno" 15 | ], 16 | "settings": { 17 | "deno.enable": true 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /generation/sources/argo-cd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -eux 2 | 3 | gitapi="https://api.github.com" 4 | upstream="argoproj/argo-cd" 5 | crdpath="manifests/crds" 6 | projectname="argo-cd" 7 | specdir="generation/api-specs/$projectname-$1" 8 | 9 | if [ ! -d "$specdir" ] 10 | then { 11 | echo 'mkdir '"$specdir" 12 | echo 'cd '"$specdir" 13 | wget -O - "$gitapi/repos/$upstream/contents/$crdpath?ref=$1" \ 14 | | jq -r '.[] | select(.name | endswith("-crd.yaml")) | "wget \(.download_url)"' 15 | } | sh -eux 16 | fi 17 | 18 | mkdir -p "lib/$projectname" 19 | rm -r "lib/$projectname"/* \ 20 | || true 21 | 22 | deno run \ 23 | --allow-read="generation/api-specs" \ 24 | --allow-write="lib/$projectname" \ 25 | generation/run-on-crds.ts \ 26 | "$specdir" \ 27 | "$projectname" 28 | 29 | deno check "lib/$projectname"/*/mod.ts 30 | git status "lib/$projectname" 31 | -------------------------------------------------------------------------------- /lib/examples/pod-exec-output.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S deno run --allow-net --allow-read --allow-env --unstable 2 | 3 | import { autoDetectClient } from '../deps.ts'; 4 | import { CoreV1Api } from '../builtin/core@v1/mod.ts'; 5 | 6 | const restClient = await autoDetectClient(); 7 | const coreApi = new CoreV1Api(restClient); 8 | 9 | // Launch a process into a particular container 10 | const tunnel = await coreApi 11 | .namespace('media') 12 | .tunnelPodExec('sabnzbd-srv-0', { 13 | command: ['uname', '-a'], 14 | stdout: true, 15 | stderr: true, 16 | }); 17 | 18 | // Buffer & print the contents of stdout 19 | const output = await tunnel.output(); 20 | console.log(new TextDecoder().decode(output.stdout).trimEnd()); 21 | 22 | // Print any error that occurred 23 | if (output.status !== 'Success') { 24 | console.error(output.message); 25 | } 26 | -------------------------------------------------------------------------------- /generation/sources/cert-manager.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -eux 2 | 3 | gitapi="https://api.github.com" 4 | upstream="jetstack/cert-manager" 5 | crdpath="deploy/crds" 6 | projectname="cert-manager" 7 | specdir="generation/api-specs/$projectname-$1" 8 | 9 | if [ ! -d "$specdir" ] 10 | then { 11 | echo 'mkdir '"$specdir" 12 | echo 'cd '"$specdir" 13 | wget -O - "$gitapi/repos/$upstream/contents/$crdpath?ref=$1" \ 14 | | jq -r '.[] | select(.name | endswith(".yaml")) | "wget \(.download_url)"' 15 | } | sh -eux 16 | fi 17 | 18 | mkdir -p "lib/$projectname" 19 | rm -r "lib/$projectname"/* \ 20 | || true 21 | 22 | deno run \ 23 | --allow-read="generation/api-specs" \ 24 | --allow-write="lib/$projectname" \ 25 | generation/run-on-crds.ts \ 26 | "$specdir" \ 27 | "$projectname" 28 | 29 | deno check "lib/$projectname"/*/mod.ts 30 | git status "lib/$projectname" 31 | -------------------------------------------------------------------------------- /generation/sources/flux-cd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -eux 2 | 3 | rawapi="raw.githubusercontent.com" 4 | upstream="fluxcd/flux2" 5 | kustomizationpath="manifests/crds/kustomization.yaml" 6 | projectname="flux-cd" 7 | specdir="generation/api-specs/$projectname-$1" 8 | 9 | if [ ! -d "$specdir" ] 10 | then { 11 | echo 'mkdir '"$specdir" 12 | echo 'cd '"$specdir" 13 | wget -O - "https://$rawapi/$upstream/refs/tags/$1/$kustomizationpath" \ 14 | | grep -E 'https:.+[.]yaml' \ 15 | | sed 's/^- /wget /' 16 | } | sh -eux 17 | fi 18 | 19 | mkdir -p "lib/$projectname" 20 | rm -r "lib/$projectname"/* \ 21 | || true 22 | 23 | deno run \ 24 | --allow-read="generation/api-specs" \ 25 | --allow-write="lib/$projectname" \ 26 | generation/run-on-crds.ts \ 27 | "$specdir" \ 28 | "$projectname" 29 | 30 | deno check "lib/$projectname"/*/mod.ts 31 | git status "lib/$projectname" 32 | -------------------------------------------------------------------------------- /generation/sources/external-dns.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -eux 2 | 3 | gitapi="https://api.github.com" 4 | upstream="kubernetes-sigs/external-dns" 5 | crdpath="config/crd/standard" 6 | projectname="external-dns" 7 | specdir="generation/api-specs/$projectname-$1" 8 | 9 | if [ ! -d "$specdir" ] 10 | then { 11 | echo 'mkdir '"$specdir" 12 | echo 'cd '"$specdir" 13 | wget -O - "$gitapi/repos/$upstream/contents/$crdpath?ref=$1" \ 14 | | jq -r '.[] | select(.name | endswith(".yaml")) | "wget \(.download_url)"' 15 | } | sh -eux 16 | fi 17 | 18 | mkdir -p "lib/$projectname" 19 | rm -r "lib/$projectname"/* \ 20 | || true 21 | 22 | deno run \ 23 | --allow-read="generation/api-specs" \ 24 | --allow-write="lib/$projectname" \ 25 | generation/run-on-crds.ts \ 26 | "$specdir" \ 27 | "$projectname" 28 | 29 | deno check "lib/$projectname"/*/mod.ts 30 | git status "lib/$projectname" 31 | -------------------------------------------------------------------------------- /generation/sources/vpa.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -eux 2 | 3 | gitapi="https://api.github.com" 4 | upstream="kubernetes/autoscaler" 5 | crdpath="vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml" 6 | projectname="vpa" 7 | specdir="generation/api-specs/$projectname-$1" 8 | 9 | mkdir -p "$specdir" 10 | if [ ! -f generation/api-specs/$projectname-"$1"/crd.yaml ] 11 | then wget \ 12 | "https://github.com/$upstream/raw/vertical-pod-autoscaler-$1/$crdpath" \ 13 | -O "$specdir/crd.yaml" 14 | fi 15 | 16 | mkdir -p "lib/$projectname" 17 | rm -r "lib/$projectname"/* \ 18 | || true 19 | 20 | deno run \ 21 | --allow-read="generation/api-specs" \ 22 | --allow-write="lib/$projectname" \ 23 | generation/run-on-crds.ts \ 24 | "$specdir" \ 25 | "$projectname" 26 | 27 | # Let's not hang on to previous versions 28 | rm -r "lib/$projectname"/*@v1beta2 29 | 30 | deno check "lib/$projectname"/*/mod.ts 31 | git status "lib/$projectname" 32 | -------------------------------------------------------------------------------- /generation/mod.ts: -------------------------------------------------------------------------------- 1 | import type { OpenAPI2 } from './openapi.ts'; 2 | import { writeApiModule } from "./codegen.ts"; 3 | import { describeSurface } from "./describe-surface.ts"; 4 | 5 | const data = await Deno.readTextFile(Deno.args[0] ?? 'openapi.json'); 6 | const wholeSpec: OpenAPI2 = JSON.parse(data); 7 | 8 | for (const value of Object.values(wholeSpec.paths)) { 9 | if (value?.parameters) { 10 | value.parameters = value.parameters.map(x => x.$ref ? wholeSpec.parameters[x.$ref.split('/')[2]] : x); 11 | } 12 | for (const path of [value.get, value.post, value.put, value.patch, value.delete]) { 13 | if (path?.parameters) { 14 | path.parameters = path.parameters.map(x => x.$ref ? wholeSpec.parameters[x.$ref.split('/')[2]] : x); 15 | } 16 | } 17 | } 18 | 19 | const surface = describeSurface(wholeSpec); 20 | 21 | for (const api of surface.allApis) { 22 | try { 23 | await writeApiModule(surface, api, Deno.args[1] ?? 'builtin'); 24 | } catch (err) { 25 | console.error(`Error writing`, api.apiGroupVersion); 26 | console.error(err); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/examples/demo.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S deno run --allow-net --allow-read --allow-env --allow-run --unstable 2 | 3 | import { autoDetectClient, readAllItems } from '../deps.ts'; 4 | import { AppsV1Api } from "../builtin/apps@v1/mod.ts"; 5 | import { CoreV1Api } from "../builtin/core@v1/mod.ts"; 6 | 7 | const restClient = await autoDetectClient(); 8 | 9 | 10 | // Set up a client for the apps/v1 API 11 | const appsApi = new AppsV1Api(restClient); 12 | 13 | // Iterate thru all deployments with pagination (to handle large lists effectively) 14 | for await (const deploy of readAllItems(t => appsApi.getDeploymentListForAllNamespaces({ 15 | limit: 5, // note: tiny page size for demonstration purposes, 100-500 is common in practice 16 | continue: t, 17 | }))) { 18 | console.log(deploy.metadata?.namespace, deploy.metadata?.name); 19 | } 20 | 21 | 22 | // Set up a client for the core v1 API 23 | const coreApi = new CoreV1Api(restClient); 24 | 25 | // Get the first node from the cluster node list 26 | const {items: [node]} = await coreApi.getNodeList({limit: 1}); 27 | console.log(node.status); 28 | -------------------------------------------------------------------------------- /lib/examples/follow-logs.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S deno run --allow-net --allow-read --allow-env --allow-run --unstable 2 | 3 | // Breaks up a text stream into lines 4 | import { TextLineStream } from "https://deno.land/std@0.177.0/streams/text_line_stream.ts"; 5 | 6 | import { autoDetectClient } from '../deps.ts'; 7 | import { CoreV1Api } from '../builtin/core@v1/mod.ts'; 8 | 9 | const restClient = await autoDetectClient(); 10 | const coreApi = new CoreV1Api(restClient); 11 | 12 | // To run without cluster-specific info, we use the first pod we can find: 13 | const podList = await coreApi.getPodListForAllNamespaces({ limit: 1 }); 14 | const firstPod = podList.items[0]; 15 | 16 | // Get a basic text stream 17 | const logStream = await coreApi 18 | .namespace(firstPod.metadata?.namespace!) 19 | .streamPodLog(firstPod.metadata?.name!, { 20 | follow: true, 21 | tailLines: 10, 22 | timestamps: true, // prepended to each line 23 | }); 24 | 25 | // Split the stream up into lines and parse the timestamps out 26 | for await (const line of logStream.pipeThrough(new TextLineStream())) { 27 | const firstSpace = line.indexOf(' '); 28 | const date = new Date(line.slice(0, firstSpace)); 29 | const logLine = line.slice(firstSpace+1); 30 | console.log(date, logLine); 31 | } 32 | -------------------------------------------------------------------------------- /lib/examples/pod-portforward.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S deno run --allow-net --allow-read --allow-env --unstable 2 | 3 | import { autoDetectClient } from '../deps.ts'; 4 | import { CoreV1Api } from '../builtin/core@v1/mod.ts'; 5 | 6 | const restClient = await autoDetectClient(); 7 | const coreApi = new CoreV1Api(restClient); 8 | 9 | // Launch a port-forward into a particular pod 10 | const tunnel = await coreApi 11 | .namespace('media') 12 | .tunnelPodPortforward('sabnzbd-srv-0', { 13 | ports: [8080], // WebSockets work by declaring the port targets upfront 14 | }); 15 | 16 | // Connect to the port 17 | const connection = await tunnel.connectToPort(8080); 18 | connection.result.catch(x => console.log(`ERR: ${x.message}`)); 19 | 20 | // Send an HTTP request 21 | const writer = connection.writable.getWriter(); 22 | await writer.write(new TextEncoder().encode([ 23 | `GET /healthz HTTP/1.1`, 24 | `Host: localhost:8000`, 25 | `Connection: close`, 26 | `Accept: */*`, 27 | ``, ``, 28 | ].join('\r\n'))); 29 | await writer.close(); 30 | 31 | // Print the full response 32 | const resp = await new Response(connection.readable).text(); 33 | console.log(resp); 34 | 35 | // Can also serve the forwarded port locally with this helper: 36 | //tunnel.servePortforward({ port: 8080, targetPort: 8088 }); 37 | // Note that this depends on SPDY as the transport. 38 | -------------------------------------------------------------------------------- /generation/known-opts.ts: -------------------------------------------------------------------------------- 1 | 2 | export const knownOptsForward = { 3 | GetListOpts: 'continue,fieldSelector,labelSelector,limit,resourceVersion,resourceVersionMatch,sendInitialEvents,timeoutSeconds', 4 | WatchListOpts: 'allowWatchBookmarks,fieldSelector,labelSelector,resourceVersion,resourceVersionMatch,sendInitialEvents,timeoutSeconds', 5 | PutOpts: 'dryRun,fieldManager,fieldValidation', // both CreateOpts and ReplaceOpts 6 | DeleteListOpts: 'continue,dryRun,fieldSelector,gracePeriodSeconds,ignoreStoreReadErrorWithClusterBreakingPotential,labelSelector,limit,orphanDependents,propagationPolicy,resourceVersion,resourceVersionMatch,sendInitialEvents,timeoutSeconds', 7 | PatchOpts: 'dryRun,fieldManager,fieldValidation,force', 8 | GetOpts: '', 9 | DeleteOpts: 'dryRun,gracePeriodSeconds,ignoreStoreReadErrorWithClusterBreakingPotential,orphanDependents,propagationPolicy', 10 | }; 11 | 12 | export const knownOptsReverse: Record = { 13 | '': 'NoOpts', 14 | [knownOptsForward.GetListOpts]: 'GetListOpts', 15 | [knownOptsForward.WatchListOpts]: 'WatchListOpts', 16 | [knownOptsForward.PutOpts]: 'PutOpts', // both CreateOpts and ReplaceOpts 17 | [knownOptsForward.DeleteListOpts]: 'DeleteListOpts', 18 | [knownOptsForward.PatchOpts]: 'PatchOpts', 19 | 'exact,export': 'GetOpts', 20 | [knownOptsForward.DeleteOpts]: 'DeleteOpts', 21 | }; 22 | -------------------------------------------------------------------------------- /lib/examples/watch-nodes.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S deno run --allow-net --allow-read --allow-env --allow-run --unstable 2 | 3 | import { autoDetectClient, Reflector } from "../deps.ts"; 4 | // import { CoreV1Api } from "../builtin/core@v1/mod.ts"; 5 | import { CoordinationV1Api } from "../builtin/coordination.k8s.io@v1/mod.ts"; 6 | 7 | const restClient = await autoDetectClient(); 8 | // const coreApi = new CoreV1Api(restClient); 9 | const coordApi = new CoordinationV1Api(restClient).namespace("kube-node-lease"); 10 | 11 | const leaseWatcher = new Reflector( 12 | opts => coordApi.getLeaseList(opts), 13 | opts => coordApi.watchLeaseList(opts)); 14 | leaseWatcher.run(); 15 | 16 | await new Promise(ok => setTimeout(ok, 2000)); 17 | 18 | leaseWatcher.goObserveAll(async iter => { 19 | console.log('observing...'); 20 | for await (const evt of iter) { 21 | switch (evt.type) { 22 | case 'ADDED': 23 | console.log('observer added:', evt.object.spec?.holderIdentity); 24 | break; 25 | case 'MODIFIED': 26 | console.log('observer modified:', evt.object.spec?.holderIdentity); 27 | break; 28 | case 'DELETED': 29 | console.log('observer deleted:', evt.object.spec?.holderIdentity); 30 | break; 31 | default: 32 | console.log(`observer ${evt.type}:`, evt.object); 33 | break; 34 | } 35 | } 36 | console.log('observer done'); 37 | }); 38 | -------------------------------------------------------------------------------- /generation/codegen.ts: -------------------------------------------------------------------------------- 1 | import { join as joinPath } from "@std/path/join"; 2 | import { generateModuleTypescript } from "./codegen-mod.ts"; 3 | import { generateStructsTypescript } from "./codegen-structs.ts"; 4 | import { SurfaceApi, SurfaceMap } from "./describe-surface.ts"; 5 | 6 | export async function writeApiModule(surface: SurfaceMap, api: SurfaceApi, category: string, apisModuleRoot?: string) { 7 | const modRoot = joinPath('lib', category, api.moduleName); 8 | 9 | function postProcess(text: string) { 10 | if (apisModuleRoot) { 11 | const isJsrRoot = apisModuleRoot.startsWith('jsr:') || apisModuleRoot.startsWith('@'); 12 | text = text.replaceAll(/from "..\/..\/([^"]+)"/g, (_, path) => { 13 | if (isJsrRoot && path.includes('@')) { 14 | return `from "${apisModuleRoot}${path.split('/')[1].replace('@', '/')}"`; 15 | } else { 16 | return `from "${apisModuleRoot}${path}"`; 17 | } 18 | }); 19 | } 20 | return text; 21 | } 22 | 23 | await Deno.mkdir(modRoot, {recursive: true}); 24 | 25 | await Deno.writeTextFile(joinPath(modRoot, 'structs.ts'), 26 | postProcess(generateStructsTypescript(surface, api))); 27 | console.log('Wrote', joinPath(modRoot, 'structs.ts')); 28 | 29 | if (api.operations.length > 0) { 30 | await Deno.writeTextFile(joinPath(modRoot, 'mod.ts'), 31 | postProcess(generateModuleTypescript(surface, api))); 32 | console.log('Wrote', joinPath(modRoot, 'mod.ts')); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/examples/pod-exec-tty.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S deno run --unstable --allow-env --allow-read --allow-net 2 | 3 | import { autoDetectClient } from '../deps.ts'; 4 | import { CoreV1Api } from '../builtin/core@v1/mod.ts'; 5 | 6 | const restClient = await autoDetectClient(); 7 | const coreApi = new CoreV1Api(restClient); 8 | 9 | // Launch a process into a particular container 10 | const tunnel = await coreApi 11 | .namespace('media') 12 | .tunnelPodExec('sabnzbd-srv-0', { 13 | command: ['bash', '-i'], 14 | stdin: true, 15 | stdout: true, 16 | tty: true, 17 | }); 18 | 19 | // Report the initial terminal size 20 | await tunnel.ttySetSize(Deno.consoleSize()); 21 | 22 | // Set up our parent tty for passthru 23 | Deno.stdin.setRaw(true, { cbreak: true }); 24 | 25 | // Pass several signals into the container tty 26 | Deno.addSignalListener('SIGINT', () => tunnel.ttyWriteSignal('INTR')); 27 | Deno.addSignalListener('SIGQUIT', () => tunnel.ttyWriteSignal('QUIT')); 28 | Deno.addSignalListener('SIGTSTP', () => tunnel.ttyWriteSignal('SUSP')); 29 | 30 | // Connect our stdin/stdout with the tunnel's 31 | await Deno.stdin.readable.pipeThrough({ 32 | writable: tunnel.stdin, 33 | readable: tunnel.stdout, 34 | }).pipeTo(Deno.stdout.writable); 35 | 36 | // Copy the remote command's exit code, if any 37 | const status = await tunnel.status; 38 | if (typeof status.exitCode == 'number') { 39 | Deno.exit(status.exitCode); 40 | } else { 41 | console.error('Kubernetes says:', status.message); 42 | Deno.exit(1); 43 | } 44 | -------------------------------------------------------------------------------- /lib/builtin/authentication.k8s.io@v1/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./structs.ts"; 2 | 3 | // Autogenerated API file for AuthenticationV1 4 | import * as c from "../../common.ts"; 5 | import * as operations from "../../operations.ts"; 6 | import * as MetaV1 from "../meta@v1/structs.ts"; 7 | import * as AuthenticationV1 from "./structs.ts"; 8 | 9 | export class AuthenticationV1Api { 10 | #client: c.RestClient; 11 | #root = "/apis/authentication.k8s.io/v1/"; 12 | constructor(client: c.RestClient) { 13 | this.#client = client; 14 | } 15 | 16 | async createSelfSubjectReview( 17 | body: AuthenticationV1.SelfSubjectReview, 18 | opts: operations.PutOpts = {}, 19 | ): Promise { 20 | const resp = await this.#client.performRequest({ 21 | method: "POST", 22 | path: `${this.#root}selfsubjectreviews`, 23 | expectJson: true, 24 | querystring: operations.formatPutOpts(opts), 25 | bodyJson: AuthenticationV1.fromSelfSubjectReview(body), 26 | abortSignal: opts.abortSignal, 27 | }); 28 | return AuthenticationV1.toSelfSubjectReview(resp); 29 | } 30 | 31 | async createTokenReview( 32 | body: AuthenticationV1.TokenReview, 33 | opts: operations.PutOpts = {}, 34 | ): Promise { 35 | const resp = await this.#client.performRequest({ 36 | method: "POST", 37 | path: `${this.#root}tokenreviews`, 38 | expectJson: true, 39 | querystring: operations.formatPutOpts(opts), 40 | bodyJson: AuthenticationV1.fromTokenReview(body), 41 | abortSignal: opts.abortSignal, 42 | }); 43 | return AuthenticationV1.toTokenReview(resp); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /lib/examples/watch-ingress.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S deno run --allow-net --allow-read --allow-env --allow-run --unstable 2 | 3 | import { autoDetectClient, Reflector } from "../deps.ts"; 4 | import { NetworkingV1Api } from "../builtin/networking.k8s.io@v1/mod.ts"; 5 | 6 | const restClient = await autoDetectClient(); 7 | const netApi = new NetworkingV1Api(restClient); 8 | 9 | // Set up a client-side cache of cluster-wide Ingresses matching a specific label 10 | const reflector = new Reflector( 11 | opts => netApi.getIngressListForAllNamespaces({ ...opts }), 12 | opts => netApi.watchIngressListForAllNamespaces({ ...opts })); 13 | 14 | function printRouteTable() { 15 | console.log('Routing Table :)'); 16 | for (const ingress of reflector.listCached()) { 17 | console.log(ingress.metadata.namespace, ingress.metadata.name); 18 | } 19 | console.log(); 20 | } 21 | const printTableSoon = debounce(printRouteTable, 2000); 22 | 23 | reflector.goObserveAll(async iter => { 24 | console.log('observing...'); 25 | let inSync = false; 26 | for await (const evt of iter) { 27 | switch (evt.type) { 28 | case 'SYNCED': 29 | printRouteTable(); // sneak in rising-edge run 30 | inSync = true; // start allowing falling-edge runs 31 | break; 32 | case 'DESYNCED': 33 | inSync = false; // block runs during resync inconsistencies 34 | break; 35 | case 'ADDED': 36 | case 'MODIFIED': 37 | case 'DELETED': 38 | if (inSync) printTableSoon(); 39 | break; 40 | } 41 | } 42 | console.log('observer done'); 43 | }); 44 | 45 | reflector.run(); 46 | 47 | 48 | function debounce(fn: (...args: T) => void, time: number) { 49 | let timeout: number | undefined; 50 | return function(...args: T) { 51 | clearTimeout(timeout); 52 | timeout = setTimeout(() => fn(...args), time); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /lib/examples/run-job.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S deno run --allow-net --allow-read --allow-env --allow-run --unstable 2 | 3 | import { autoDetectClient } from "../deps.ts"; 4 | import { CoreV1Api } from "../builtin/core@v1/mod.ts"; 5 | import { BatchV1Api } from "../builtin/batch@v1/mod.ts"; 6 | 7 | const restClient = await autoDetectClient(); 8 | const namespace = restClient.defaultNamespace ?? 'default'; 9 | const batchApi = new BatchV1Api(restClient).namespace(namespace); 10 | const coreApi = new CoreV1Api(restClient).namespace(namespace); 11 | 12 | const job = await batchApi.createJob({ 13 | metadata: { 14 | generateName: 'deno-example-', 15 | }, 16 | spec: { 17 | ttlSecondsAfterFinished: 60 * 60, 18 | parallelism: 1, 19 | completions: 1, 20 | template: { 21 | spec: { 22 | restartPolicy: 'OnFailure', 23 | containers: [{ 24 | name: 'job', 25 | image: 'busybox', 26 | args: [ 27 | 'sh', 28 | '-euxc', 29 | 'date', 30 | ], 31 | }], 32 | }, 33 | }, 34 | }, 35 | }); 36 | console.log(`Created job`, job.metadata?.name); 37 | 38 | while (true) { 39 | const {status} = await batchApi.getJobStatus(job.metadata?.name ?? ''); 40 | console.log('active pods:', status?.active); 41 | if (status?.completionTime) break; 42 | await new Promise(ok => setTimeout(ok, 2000)); 43 | } 44 | 45 | const pods = await coreApi.getPodList({ 46 | labelSelector: Object.entries(job.spec?.selector?.matchLabels ?? {}).map(p => `${p[0]}=${p[1]}`).join(','), 47 | limit: 5, 48 | }); 49 | 50 | for (const pod of pods.items) { 51 | console.log('Logs for', pod.metadata?.name); 52 | const logs = await coreApi.getPodLog(pod.metadata?.name ?? ''); 53 | console.log(logs); 54 | } 55 | 56 | const {status} = await batchApi.deleteJob(job.metadata?.name ?? '', {}); 57 | console.log(status); 58 | -------------------------------------------------------------------------------- /lib/builtin/scheduling.k8s.io@v1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for SchedulingV1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** PriorityClass defines mapping from a priority class name to the priority integer value. The value can be any valid integer. */ 11 | export interface PriorityClass { 12 | apiVersion?: "scheduling.k8s.io/v1"; 13 | kind?: "PriorityClass"; 14 | description?: string | null; 15 | globalDefault?: boolean | null; 16 | metadata?: MetaV1.ObjectMeta | null; 17 | preemptionPolicy?: string | null; 18 | value: number; 19 | } 20 | export function toPriorityClass(input: c.JSONValue): PriorityClass & c.ApiKind { 21 | const obj = c.checkObj(input); 22 | return { 23 | ...c.assertOrAddApiVersionAndKind(obj, "scheduling.k8s.io/v1", "PriorityClass"), 24 | description: c.readOpt(obj["description"], c.checkStr), 25 | globalDefault: c.readOpt(obj["globalDefault"], c.checkBool), 26 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 27 | preemptionPolicy: c.readOpt(obj["preemptionPolicy"], c.checkStr), 28 | value: c.checkNum(obj["value"]), 29 | }} 30 | export function fromPriorityClass(input: PriorityClass): c.JSONValue { 31 | return { 32 | ...c.assertOrAddApiVersionAndKind(input, "scheduling.k8s.io/v1", "PriorityClass"), 33 | ...input, 34 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 35 | }} 36 | 37 | /** PriorityClassList is a collection of priority classes. */ 38 | export interface PriorityClassList extends ListOf { 39 | apiVersion?: "scheduling.k8s.io/v1"; 40 | kind?: "PriorityClassList"; 41 | }; 42 | export function toPriorityClassList(input: c.JSONValue): PriorityClassList & c.ApiKind { 43 | const obj = c.checkObj(input); 44 | return { 45 | ...c.assertOrAddApiVersionAndKind(obj, "scheduling.k8s.io/v1", "PriorityClassList"), 46 | metadata: MetaV1.toListMeta(obj.metadata), 47 | items: c.readList(obj.items, toPriorityClass), 48 | }} 49 | -------------------------------------------------------------------------------- /lib/builtin/storage.k8s.io@v1beta1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for StorageV1beta1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** VolumeAttributesClass represents a specification of mutable volume attributes defined by the CSI driver. The class can be specified during dynamic provisioning of PersistentVolumeClaims, and changed in the PersistentVolumeClaim spec after provisioning. */ 11 | export interface VolumeAttributesClass { 12 | apiVersion?: "storage.k8s.io/v1beta1"; 13 | kind?: "VolumeAttributesClass"; 14 | driverName: string; 15 | metadata?: MetaV1.ObjectMeta | null; 16 | parameters?: Record | null; 17 | } 18 | export function toVolumeAttributesClass(input: c.JSONValue): VolumeAttributesClass & c.ApiKind { 19 | const obj = c.checkObj(input); 20 | return { 21 | ...c.assertOrAddApiVersionAndKind(obj, "storage.k8s.io/v1beta1", "VolumeAttributesClass"), 22 | driverName: c.checkStr(obj["driverName"]), 23 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 24 | parameters: c.readOpt(obj["parameters"], x => c.readMap(x, c.checkStr)), 25 | }} 26 | export function fromVolumeAttributesClass(input: VolumeAttributesClass): c.JSONValue { 27 | return { 28 | ...c.assertOrAddApiVersionAndKind(input, "storage.k8s.io/v1beta1", "VolumeAttributesClass"), 29 | ...input, 30 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 31 | }} 32 | 33 | /** VolumeAttributesClassList is a collection of VolumeAttributesClass objects. */ 34 | export interface VolumeAttributesClassList extends ListOf { 35 | apiVersion?: "storage.k8s.io/v1beta1"; 36 | kind?: "VolumeAttributesClassList"; 37 | }; 38 | export function toVolumeAttributesClassList(input: c.JSONValue): VolumeAttributesClassList & c.ApiKind { 39 | const obj = c.checkObj(input); 40 | return { 41 | ...c.assertOrAddApiVersionAndKind(obj, "storage.k8s.io/v1beta1", "VolumeAttributesClassList"), 42 | metadata: MetaV1.toListMeta(obj.metadata), 43 | items: c.readList(obj.items, toVolumeAttributesClass), 44 | }} 45 | -------------------------------------------------------------------------------- /lib/builtin/storage.k8s.io@v1alpha1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for StorageV1alpha1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** VolumeAttributesClass represents a specification of mutable volume attributes defined by the CSI driver. The class can be specified during dynamic provisioning of PersistentVolumeClaims, and changed in the PersistentVolumeClaim spec after provisioning. */ 11 | export interface VolumeAttributesClass { 12 | apiVersion?: "storage.k8s.io/v1alpha1"; 13 | kind?: "VolumeAttributesClass"; 14 | driverName: string; 15 | metadata?: MetaV1.ObjectMeta | null; 16 | parameters?: Record | null; 17 | } 18 | export function toVolumeAttributesClass(input: c.JSONValue): VolumeAttributesClass & c.ApiKind { 19 | const obj = c.checkObj(input); 20 | return { 21 | ...c.assertOrAddApiVersionAndKind(obj, "storage.k8s.io/v1alpha1", "VolumeAttributesClass"), 22 | driverName: c.checkStr(obj["driverName"]), 23 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 24 | parameters: c.readOpt(obj["parameters"], x => c.readMap(x, c.checkStr)), 25 | }} 26 | export function fromVolumeAttributesClass(input: VolumeAttributesClass): c.JSONValue { 27 | return { 28 | ...c.assertOrAddApiVersionAndKind(input, "storage.k8s.io/v1alpha1", "VolumeAttributesClass"), 29 | ...input, 30 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 31 | }} 32 | 33 | /** VolumeAttributesClassList is a collection of VolumeAttributesClass objects. */ 34 | export interface VolumeAttributesClassList extends ListOf { 35 | apiVersion?: "storage.k8s.io/v1alpha1"; 36 | kind?: "VolumeAttributesClassList"; 37 | }; 38 | export function toVolumeAttributesClassList(input: c.JSONValue): VolumeAttributesClassList & c.ApiKind { 39 | const obj = c.checkObj(input); 40 | return { 41 | ...c.assertOrAddApiVersionAndKind(obj, "storage.k8s.io/v1alpha1", "VolumeAttributesClassList"), 42 | metadata: MetaV1.toListMeta(obj.metadata), 43 | items: c.readList(obj.items, toVolumeAttributesClass), 44 | }} 45 | -------------------------------------------------------------------------------- /.github/workflows/deno-ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: {} 7 | 8 | permissions: 9 | contents: read 10 | jobs: 11 | 12 | check: 13 | runs-on: ubuntu-latest 14 | name: Check w/ ${{ matrix.deno-version }} 15 | strategy: 16 | matrix: 17 | deno-version: 18 | - v2.0 19 | - v2.1 20 | - v2.2 21 | - v2.3 22 | - v2.4 23 | - v2.5 24 | - canary 25 | fail-fast: false # run each branch to completion 26 | 27 | steps: 28 | - name: Checkout source 29 | uses: actions/checkout@v6 30 | 31 | - name: Use Deno ${{ matrix.deno-version }} 32 | uses: denoland/setup-deno@v2 33 | with: 34 | deno-version: ${{ matrix.deno-version }} 35 | 36 | - name: Cache Deno deps 37 | uses: actions/cache@v4 38 | with: 39 | path: ~/.cache/deno 40 | key: denodir/${{ matrix.deno-version }}-${{ hashFiles('deno.lock') }} 41 | 42 | - name: Possibly reset lockfile 43 | run: deno install || rm deno.lock 44 | 45 | - name: Check generation/mod.ts 46 | run: time deno check generation/mod.ts 47 | 48 | - name: Check lib/builtin/*/mod.ts 49 | run: time deno check lib/builtin/*/mod.ts 50 | 51 | - name: Check lib/*/*/mod.ts 52 | run: time deno check lib/*/*/mod.ts 53 | 54 | - name: Check lib/examples/*.ts 55 | run: time deno check lib/examples/*.ts 56 | 57 | - name: Test 58 | run: time deno test 59 | 60 | check-publish-lib: 61 | runs-on: ubuntu-latest 62 | name: Audit ./lib 63 | 64 | steps: 65 | - name: Checkout source 66 | uses: actions/checkout@v6 67 | 68 | - name: Use latest Deno 69 | uses: denoland/setup-deno@v2 70 | 71 | - name: Cache Deno deps 72 | uses: actions/cache@v4 73 | with: 74 | path: ~/.cache/deno 75 | key: denodir-${{ hashFiles('deno.lock') }} 76 | 77 | - name: Check publish rules 78 | working-directory: lib 79 | run: deno publish --dry-run --allow-dirty 80 | 81 | publish-lib: 82 | runs-on: ubuntu-latest 83 | name: Publish ./lib 84 | needs: 85 | - check 86 | - check-publish-lib 87 | if: github.event_name == 'push' 88 | 89 | permissions: 90 | contents: read 91 | id-token: write 92 | 93 | steps: 94 | - uses: denoland/setup-deno@v2 95 | - uses: actions/checkout@v6 96 | 97 | - name: Cache Deno deps 98 | uses: actions/cache@v4 99 | with: 100 | path: ~/.cache/deno 101 | key: denodir-${{ hashFiles('deno.lock') }} 102 | 103 | - name: Publish now 104 | run: deno publish 105 | -------------------------------------------------------------------------------- /lib/builtin/coordination.k8s.io@v1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for CoordinationV1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** Lease defines a lease concept. */ 11 | export interface Lease { 12 | apiVersion?: "coordination.k8s.io/v1"; 13 | kind?: "Lease"; 14 | metadata?: MetaV1.ObjectMeta | null; 15 | spec?: LeaseSpec | null; 16 | } 17 | export function toLease(input: c.JSONValue): Lease & c.ApiKind { 18 | const obj = c.checkObj(input); 19 | return { 20 | ...c.assertOrAddApiVersionAndKind(obj, "coordination.k8s.io/v1", "Lease"), 21 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 22 | spec: c.readOpt(obj["spec"], toLeaseSpec), 23 | }} 24 | export function fromLease(input: Lease): c.JSONValue { 25 | return { 26 | ...c.assertOrAddApiVersionAndKind(input, "coordination.k8s.io/v1", "Lease"), 27 | ...input, 28 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 29 | spec: input.spec != null ? fromLeaseSpec(input.spec) : undefined, 30 | }} 31 | 32 | /** LeaseSpec is a specification of a Lease. */ 33 | export interface LeaseSpec { 34 | acquireTime?: c.MicroTime | null; 35 | holderIdentity?: string | null; 36 | leaseDurationSeconds?: number | null; 37 | leaseTransitions?: number | null; 38 | preferredHolder?: string | null; 39 | renewTime?: c.MicroTime | null; 40 | strategy?: string | null; 41 | } 42 | export function toLeaseSpec(input: c.JSONValue): LeaseSpec { 43 | const obj = c.checkObj(input); 44 | return { 45 | acquireTime: c.readOpt(obj["acquireTime"], c.toMicroTime), 46 | holderIdentity: c.readOpt(obj["holderIdentity"], c.checkStr), 47 | leaseDurationSeconds: c.readOpt(obj["leaseDurationSeconds"], c.checkNum), 48 | leaseTransitions: c.readOpt(obj["leaseTransitions"], c.checkNum), 49 | preferredHolder: c.readOpt(obj["preferredHolder"], c.checkStr), 50 | renewTime: c.readOpt(obj["renewTime"], c.toMicroTime), 51 | strategy: c.readOpt(obj["strategy"], c.checkStr), 52 | }} 53 | export function fromLeaseSpec(input: LeaseSpec): c.JSONValue { 54 | return { 55 | ...input, 56 | acquireTime: input.acquireTime != null ? c.fromMicroTime(input.acquireTime) : undefined, 57 | renewTime: input.renewTime != null ? c.fromMicroTime(input.renewTime) : undefined, 58 | }} 59 | 60 | /** LeaseList is a list of Lease objects. */ 61 | export interface LeaseList extends ListOf { 62 | apiVersion?: "coordination.k8s.io/v1"; 63 | kind?: "LeaseList"; 64 | }; 65 | export function toLeaseList(input: c.JSONValue): LeaseList & c.ApiKind { 66 | const obj = c.checkObj(input); 67 | return { 68 | ...c.assertOrAddApiVersionAndKind(obj, "coordination.k8s.io/v1", "LeaseList"), 69 | metadata: MetaV1.toListMeta(obj.metadata), 70 | items: c.readList(obj.items, toLease), 71 | }} 72 | -------------------------------------------------------------------------------- /lib/builtin/coordination.k8s.io@v1beta1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for CoordinationV1beta1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** LeaseCandidate defines a candidate for a Lease object. Candidates are created such that coordinated leader election will pick the best leader from the list of candidates. */ 11 | export interface LeaseCandidate { 12 | apiVersion?: "coordination.k8s.io/v1beta1"; 13 | kind?: "LeaseCandidate"; 14 | metadata?: MetaV1.ObjectMeta | null; 15 | spec?: LeaseCandidateSpec | null; 16 | } 17 | export function toLeaseCandidate(input: c.JSONValue): LeaseCandidate & c.ApiKind { 18 | const obj = c.checkObj(input); 19 | return { 20 | ...c.assertOrAddApiVersionAndKind(obj, "coordination.k8s.io/v1beta1", "LeaseCandidate"), 21 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 22 | spec: c.readOpt(obj["spec"], toLeaseCandidateSpec), 23 | }} 24 | export function fromLeaseCandidate(input: LeaseCandidate): c.JSONValue { 25 | return { 26 | ...c.assertOrAddApiVersionAndKind(input, "coordination.k8s.io/v1beta1", "LeaseCandidate"), 27 | ...input, 28 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 29 | spec: input.spec != null ? fromLeaseCandidateSpec(input.spec) : undefined, 30 | }} 31 | 32 | /** LeaseCandidateSpec is a specification of a Lease. */ 33 | export interface LeaseCandidateSpec { 34 | binaryVersion: string; 35 | emulationVersion?: string | null; 36 | leaseName: string; 37 | pingTime?: c.MicroTime | null; 38 | renewTime?: c.MicroTime | null; 39 | strategy: string; 40 | } 41 | export function toLeaseCandidateSpec(input: c.JSONValue): LeaseCandidateSpec { 42 | const obj = c.checkObj(input); 43 | return { 44 | binaryVersion: c.checkStr(obj["binaryVersion"]), 45 | emulationVersion: c.readOpt(obj["emulationVersion"], c.checkStr), 46 | leaseName: c.checkStr(obj["leaseName"]), 47 | pingTime: c.readOpt(obj["pingTime"], c.toMicroTime), 48 | renewTime: c.readOpt(obj["renewTime"], c.toMicroTime), 49 | strategy: c.checkStr(obj["strategy"]), 50 | }} 51 | export function fromLeaseCandidateSpec(input: LeaseCandidateSpec): c.JSONValue { 52 | return { 53 | ...input, 54 | pingTime: input.pingTime != null ? c.fromMicroTime(input.pingTime) : undefined, 55 | renewTime: input.renewTime != null ? c.fromMicroTime(input.renewTime) : undefined, 56 | }} 57 | 58 | /** LeaseCandidateList is a list of Lease objects. */ 59 | export interface LeaseCandidateList extends ListOf { 60 | apiVersion?: "coordination.k8s.io/v1beta1"; 61 | kind?: "LeaseCandidateList"; 62 | }; 63 | export function toLeaseCandidateList(input: c.JSONValue): LeaseCandidateList & c.ApiKind { 64 | const obj = c.checkObj(input); 65 | return { 66 | ...c.assertOrAddApiVersionAndKind(obj, "coordination.k8s.io/v1beta1", "LeaseCandidateList"), 67 | metadata: MetaV1.toListMeta(obj.metadata), 68 | items: c.readList(obj.items, toLeaseCandidate), 69 | }} 70 | -------------------------------------------------------------------------------- /lib/builtin/coordination.k8s.io@v1alpha2/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for CoordinationV1alpha2 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** LeaseCandidate defines a candidate for a Lease object. Candidates are created such that coordinated leader election will pick the best leader from the list of candidates. */ 11 | export interface LeaseCandidate { 12 | apiVersion?: "coordination.k8s.io/v1alpha2"; 13 | kind?: "LeaseCandidate"; 14 | metadata?: MetaV1.ObjectMeta | null; 15 | spec?: LeaseCandidateSpec | null; 16 | } 17 | export function toLeaseCandidate(input: c.JSONValue): LeaseCandidate & c.ApiKind { 18 | const obj = c.checkObj(input); 19 | return { 20 | ...c.assertOrAddApiVersionAndKind(obj, "coordination.k8s.io/v1alpha2", "LeaseCandidate"), 21 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 22 | spec: c.readOpt(obj["spec"], toLeaseCandidateSpec), 23 | }} 24 | export function fromLeaseCandidate(input: LeaseCandidate): c.JSONValue { 25 | return { 26 | ...c.assertOrAddApiVersionAndKind(input, "coordination.k8s.io/v1alpha2", "LeaseCandidate"), 27 | ...input, 28 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 29 | spec: input.spec != null ? fromLeaseCandidateSpec(input.spec) : undefined, 30 | }} 31 | 32 | /** LeaseCandidateSpec is a specification of a Lease. */ 33 | export interface LeaseCandidateSpec { 34 | binaryVersion: string; 35 | emulationVersion?: string | null; 36 | leaseName: string; 37 | pingTime?: c.MicroTime | null; 38 | renewTime?: c.MicroTime | null; 39 | strategy: string; 40 | } 41 | export function toLeaseCandidateSpec(input: c.JSONValue): LeaseCandidateSpec { 42 | const obj = c.checkObj(input); 43 | return { 44 | binaryVersion: c.checkStr(obj["binaryVersion"]), 45 | emulationVersion: c.readOpt(obj["emulationVersion"], c.checkStr), 46 | leaseName: c.checkStr(obj["leaseName"]), 47 | pingTime: c.readOpt(obj["pingTime"], c.toMicroTime), 48 | renewTime: c.readOpt(obj["renewTime"], c.toMicroTime), 49 | strategy: c.checkStr(obj["strategy"]), 50 | }} 51 | export function fromLeaseCandidateSpec(input: LeaseCandidateSpec): c.JSONValue { 52 | return { 53 | ...input, 54 | pingTime: input.pingTime != null ? c.fromMicroTime(input.pingTime) : undefined, 55 | renewTime: input.renewTime != null ? c.fromMicroTime(input.renewTime) : undefined, 56 | }} 57 | 58 | /** LeaseCandidateList is a list of Lease objects. */ 59 | export interface LeaseCandidateList extends ListOf { 60 | apiVersion?: "coordination.k8s.io/v1alpha2"; 61 | kind?: "LeaseCandidateList"; 62 | }; 63 | export function toLeaseCandidateList(input: c.JSONValue): LeaseCandidateList & c.ApiKind { 64 | const obj = c.checkObj(input); 65 | return { 66 | ...c.assertOrAddApiVersionAndKind(obj, "coordination.k8s.io/v1alpha2", "LeaseCandidateList"), 67 | metadata: MetaV1.toListMeta(obj.metadata), 68 | items: c.readList(obj.items, toLeaseCandidate), 69 | }} 70 | -------------------------------------------------------------------------------- /generation/README.md: -------------------------------------------------------------------------------- 1 | [![CI](https://github.com/cloudydeno/kubernetes-apis/actions/workflows/deno-ci.yaml/badge.svg)](https://github.com/cloudydeno/kubernetes-apis/actions/workflows/deno-ci.yaml) 2 | 3 | # `@cloudydeno/kubernetes-apis` 4 | 5 | NOTE: This README is about code generation concepts. 6 | 7 | Users of this library should click into [`lib/`](./lib) for the actual README! 8 | 9 | ## Kubernetes compatability 10 | 11 | APIs are generated from Kubernetes OpenAPI specs, which are large JSON files. 12 | 13 | You can pull your cluster's OpenAPI spec easily: 14 | 15 | `kubectl get --raw /openapi/v2 > openapi.json` 16 | 17 | API specs from Kubernetes v1.14.0 and later should work fine. 18 | Earlier releases would need some codegen changes to be compatible. 19 | 20 | ## Module Layout 21 | 22 | NOTE: This section refers to a hypothetical dynamic-codegen endpoint. 23 | The current way of using this library is importing modules from 24 | [/x/kubernetes_apis](https://deno.land/x/kubernetes_apis). 25 | The latest Kubernetes release is used to generate the published modules, 26 | so you may start noticing a lack of parity if you are using a quite old cluster. 27 | 28 | --- 29 | 30 | Versioning is tricky with Kubernetes APIs because every cluster can have a different surface. 31 | 32 | When referring to Kubernetes API surfaces, an exhuastive module path might look like this: 33 | 34 | * `https://k8s-apis.deno.dev/v1/kubernetes@v1.17.8/core@v1/mod.ts` 35 | * `https://k8s-apis.deno.dev/v1/kubernetes@v1.18.3/apps@v1beta1/mod.ts` 36 | * `https://k8s-apis.deno.dev/v1/kubernetes@v1.19.1/networking.k8s.io@v1/mod.ts` 37 | 38 | There's also third-party projects that register CRDs, such as cert-manager. 39 | OpenAPI specs are almost never published by these projects, 40 | so generating APIs for them generally means feeding CRD YAML files into the codegen and guessing. 41 | This is an imperfect art but so far works well for `cert-manager` and `exernal-dns`. 42 | Alternatively, the CRDs could be installed onto a real control plane and then the APIs extracted. 43 | 44 | Several examples of addressing third party APIs might be: 45 | 46 | * `https://k8s-apis.deno.dev/v1/cert-manager@v1.0.4/acme.cert-manager.io@v1alpha2/mod.ts` 47 | * `https://k8s-apis.deno.dev/v1/external-dns@v0.7.4/externaldns.k8s.io@v1alpha1/mod.ts` 48 | * `https://k8s-apis.deno.dev/v1/velero@v1.5.2/velero.io@v1/mod.ts` 49 | * `https://k8s-apis.deno.dev/v1/argo-cd@v2.1.7/argoproj.io@v1alpha1/mod.ts` 50 | 51 | The only sort of 'directory' of CRDs is likely [Operator Hub](https://operatorhub.io/) 52 | though it is also lacking CRDs that are not explicitly tied to an "Operator". 53 | Otherwise, there's not really any, like, directory of just CRDs, 54 | so we'll possibly need to make a further list ourselves.. 55 | 56 | Finally, for generating code within a cluster, it's pretty likely that a cluster's apis 57 | will be generated as one unit and possibly stored in S3 or similar, and the paths are more straightforward: 58 | 59 | * `//k8s_api_surface/batch@v1/mod.ts` 60 | 61 | In any case, the actual API client that works with authentication/transport 62 | will be served authoratatively from a normal deno repo: 63 | 64 | * https://deno.land/x/kubernetes_client@v0.7.0/mod.ts 65 | -------------------------------------------------------------------------------- /lib/builtin/certificates.k8s.io@v1beta1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for CertificatesV1beta1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** ClusterTrustBundle is a cluster-scoped container for X.509 trust anchors (root certificates). 11 | 12 | ClusterTrustBundle objects are considered to be readable by any authenticated user in the cluster, because they can be mounted by pods using the `clusterTrustBundle` projection. All service accounts have read access to ClusterTrustBundles by default. Users who only have namespace-level access to a cluster can read ClusterTrustBundles by impersonating a serviceaccount that they have access to. 13 | 14 | It can be optionally associated with a particular assigner, in which case it contains one valid set of trust anchors for that signer. Signers may have multiple associated ClusterTrustBundles; each is an independent set of trust anchors for that signer. Admission control is used to enforce that only users with permissions on the signer can create or modify the corresponding bundle. */ 15 | export interface ClusterTrustBundle { 16 | apiVersion?: "certificates.k8s.io/v1beta1"; 17 | kind?: "ClusterTrustBundle"; 18 | metadata?: MetaV1.ObjectMeta | null; 19 | spec: ClusterTrustBundleSpec; 20 | } 21 | export function toClusterTrustBundle(input: c.JSONValue): ClusterTrustBundle & c.ApiKind { 22 | const obj = c.checkObj(input); 23 | return { 24 | ...c.assertOrAddApiVersionAndKind(obj, "certificates.k8s.io/v1beta1", "ClusterTrustBundle"), 25 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 26 | spec: toClusterTrustBundleSpec(obj["spec"]), 27 | }} 28 | export function fromClusterTrustBundle(input: ClusterTrustBundle): c.JSONValue { 29 | return { 30 | ...c.assertOrAddApiVersionAndKind(input, "certificates.k8s.io/v1beta1", "ClusterTrustBundle"), 31 | ...input, 32 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 33 | spec: input.spec != null ? fromClusterTrustBundleSpec(input.spec) : undefined, 34 | }} 35 | 36 | /** ClusterTrustBundleSpec contains the signer and trust anchors. */ 37 | export interface ClusterTrustBundleSpec { 38 | signerName?: string | null; 39 | trustBundle: string; 40 | } 41 | export function toClusterTrustBundleSpec(input: c.JSONValue): ClusterTrustBundleSpec { 42 | const obj = c.checkObj(input); 43 | return { 44 | signerName: c.readOpt(obj["signerName"], c.checkStr), 45 | trustBundle: c.checkStr(obj["trustBundle"]), 46 | }} 47 | export function fromClusterTrustBundleSpec(input: ClusterTrustBundleSpec): c.JSONValue { 48 | return { 49 | ...input, 50 | }} 51 | 52 | /** ClusterTrustBundleList is a collection of ClusterTrustBundle objects */ 53 | export interface ClusterTrustBundleList extends ListOf { 54 | apiVersion?: "certificates.k8s.io/v1beta1"; 55 | kind?: "ClusterTrustBundleList"; 56 | }; 57 | export function toClusterTrustBundleList(input: c.JSONValue): ClusterTrustBundleList & c.ApiKind { 58 | const obj = c.checkObj(input); 59 | return { 60 | ...c.assertOrAddApiVersionAndKind(obj, "certificates.k8s.io/v1beta1", "ClusterTrustBundleList"), 61 | metadata: MetaV1.toListMeta(obj.metadata), 62 | items: c.readList(obj.items, toClusterTrustBundle), 63 | }} 64 | -------------------------------------------------------------------------------- /lib/builtin/authorization.k8s.io@v1/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./structs.ts"; 2 | 3 | // Autogenerated API file for AuthorizationV1 4 | import * as c from "../../common.ts"; 5 | import * as operations from "../../operations.ts"; 6 | import * as MetaV1 from "../meta@v1/structs.ts"; 7 | import * as AuthorizationV1 from "./structs.ts"; 8 | 9 | export class AuthorizationV1Api { 10 | #client: c.RestClient; 11 | #root = "/apis/authorization.k8s.io/v1/"; 12 | constructor(client: c.RestClient) { 13 | this.#client = client; 14 | } 15 | 16 | namespace(name: string): AuthorizationV1NamespacedApi { 17 | return new AuthorizationV1NamespacedApi(this.#client, name); 18 | } 19 | myNamespace(): AuthorizationV1NamespacedApi { 20 | if (!this.#client.defaultNamespace) throw new Error("No current namespace is set"); 21 | return new AuthorizationV1NamespacedApi(this.#client, this.#client.defaultNamespace); 22 | } 23 | 24 | async createSelfSubjectAccessReview( 25 | body: AuthorizationV1.SelfSubjectAccessReview, 26 | opts: operations.PutOpts = {}, 27 | ): Promise { 28 | const resp = await this.#client.performRequest({ 29 | method: "POST", 30 | path: `${this.#root}selfsubjectaccessreviews`, 31 | expectJson: true, 32 | querystring: operations.formatPutOpts(opts), 33 | bodyJson: AuthorizationV1.fromSelfSubjectAccessReview(body), 34 | abortSignal: opts.abortSignal, 35 | }); 36 | return AuthorizationV1.toSelfSubjectAccessReview(resp); 37 | } 38 | 39 | async createSelfSubjectRulesReview( 40 | body: AuthorizationV1.SelfSubjectRulesReview, 41 | opts: operations.PutOpts = {}, 42 | ): Promise { 43 | const resp = await this.#client.performRequest({ 44 | method: "POST", 45 | path: `${this.#root}selfsubjectrulesreviews`, 46 | expectJson: true, 47 | querystring: operations.formatPutOpts(opts), 48 | bodyJson: AuthorizationV1.fromSelfSubjectRulesReview(body), 49 | abortSignal: opts.abortSignal, 50 | }); 51 | return AuthorizationV1.toSelfSubjectRulesReview(resp); 52 | } 53 | 54 | async createSubjectAccessReview( 55 | body: AuthorizationV1.SubjectAccessReview, 56 | opts: operations.PutOpts = {}, 57 | ): Promise { 58 | const resp = await this.#client.performRequest({ 59 | method: "POST", 60 | path: `${this.#root}subjectaccessreviews`, 61 | expectJson: true, 62 | querystring: operations.formatPutOpts(opts), 63 | bodyJson: AuthorizationV1.fromSubjectAccessReview(body), 64 | abortSignal: opts.abortSignal, 65 | }); 66 | return AuthorizationV1.toSubjectAccessReview(resp); 67 | } 68 | 69 | } 70 | 71 | export class AuthorizationV1NamespacedApi { 72 | #client: c.RestClient 73 | #root: string 74 | constructor(client: c.RestClient, namespace: string) { 75 | this.#client = client; 76 | this.#root = `/apis/authorization.k8s.io/v1/namespaces/${namespace}/`; 77 | } 78 | 79 | async createLocalSubjectAccessReview( 80 | body: AuthorizationV1.LocalSubjectAccessReview, 81 | opts: operations.PutOpts = {}, 82 | ): Promise { 83 | const resp = await this.#client.performRequest({ 84 | method: "POST", 85 | path: `${this.#root}localsubjectaccessreviews`, 86 | expectJson: true, 87 | querystring: operations.formatPutOpts(opts), 88 | bodyJson: AuthorizationV1.fromLocalSubjectAccessReview(body), 89 | abortSignal: opts.abortSignal, 90 | }); 91 | return AuthorizationV1.toLocalSubjectAccessReview(resp); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /lib/external-dns/externaldns.k8s.io@v1alpha1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for ExternaldnsV1alpha1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../../builtin/meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** DNSEndpoint is a contract that a user-specified CRD must implement to be used as a source for external-dns. 11 | The user-specified CRD should also have the status sub-resource. */ 12 | export interface DNSEndpoint { 13 | apiVersion?: "externaldns.k8s.io/v1alpha1"; 14 | kind?: "DNSEndpoint"; 15 | metadata?: MetaV1.ObjectMeta | null; 16 | spec?: { 17 | endpoints?: Array<{ 18 | dnsName?: string | null; 19 | labels?: Record | null; 20 | providerSpecific?: Array<{ 21 | name?: string | null; 22 | value?: string | null; 23 | }> | null; 24 | recordTTL?: number | null; 25 | recordType?: string | null; 26 | setIdentifier?: string | null; 27 | targets?: Array | null; 28 | }> | null; 29 | } | null; 30 | status?: { 31 | observedGeneration?: number | null; 32 | } | null; 33 | } 34 | export function toDNSEndpoint(input: c.JSONValue): DNSEndpoint & c.ApiKind { 35 | const obj = c.checkObj(input); 36 | return { 37 | ...c.assertOrAddApiVersionAndKind(obj, "externaldns.k8s.io/v1alpha1", "DNSEndpoint"), 38 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 39 | spec: c.readOpt(obj["spec"], toDNSEndpoint_spec), 40 | status: c.readOpt(obj["status"], toDNSEndpoint_status), 41 | }} 42 | export function fromDNSEndpoint(input: DNSEndpoint): c.JSONValue { 43 | return { 44 | ...c.assertOrAddApiVersionAndKind(input, "externaldns.k8s.io/v1alpha1", "DNSEndpoint"), 45 | ...input, 46 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 47 | }} 48 | function toDNSEndpoint_spec(input: c.JSONValue) { 49 | const obj = c.checkObj(input); 50 | return { 51 | endpoints: c.readOpt(obj["endpoints"], x => c.readList(x, toDNSEndpoint_spec_endpoints)), 52 | }} 53 | function toDNSEndpoint_status(input: c.JSONValue) { 54 | const obj = c.checkObj(input); 55 | return { 56 | observedGeneration: c.readOpt(obj["observedGeneration"], c.checkNum), 57 | }} 58 | function toDNSEndpoint_spec_endpoints(input: c.JSONValue) { 59 | const obj = c.checkObj(input); 60 | return { 61 | dnsName: c.readOpt(obj["dnsName"], c.checkStr), 62 | labels: c.readOpt(obj["labels"], x => c.readMap(x, c.checkStr)), 63 | providerSpecific: c.readOpt(obj["providerSpecific"], x => c.readList(x, toDNSEndpoint_spec_endpoints_providerSpecific)), 64 | recordTTL: c.readOpt(obj["recordTTL"], c.checkNum), 65 | recordType: c.readOpt(obj["recordType"], c.checkStr), 66 | setIdentifier: c.readOpt(obj["setIdentifier"], c.checkStr), 67 | targets: c.readOpt(obj["targets"], x => c.readList(x, c.checkStr)), 68 | }} 69 | function toDNSEndpoint_spec_endpoints_providerSpecific(input: c.JSONValue) { 70 | const obj = c.checkObj(input); 71 | return { 72 | name: c.readOpt(obj["name"], c.checkStr), 73 | value: c.readOpt(obj["value"], c.checkStr), 74 | }} 75 | 76 | export interface DNSEndpointList extends ListOf { 77 | apiVersion?: "externaldns.k8s.io/v1alpha1"; 78 | kind?: "DNSEndpointList"; 79 | }; 80 | export function toDNSEndpointList(input: c.JSONValue): DNSEndpointList & c.ApiKind { 81 | const obj = c.checkObj(input); 82 | return { 83 | ...c.assertOrAddApiVersionAndKind(obj, "externaldns.k8s.io/v1alpha1", "DNSEndpointList"), 84 | metadata: MetaV1.toListMeta(obj.metadata), 85 | items: c.readList(obj.items, toDNSEndpoint), 86 | }} 87 | -------------------------------------------------------------------------------- /lib/deno.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@cloudydeno/kubernetes-apis", 3 | "version": "0.7.0", 4 | "imports": { 5 | "@cloudydeno/kubernetes-client": "jsr:@cloudydeno/kubernetes-client@^0.8" 6 | }, 7 | "exports": { 8 | 9 | "./admissionregistration.k8s.io/v1": "./builtin/admissionregistration.k8s.io@v1/mod.ts", 10 | "./admissionregistration.k8s.io/v1alpha1": "./builtin/admissionregistration.k8s.io@v1alpha1/mod.ts", 11 | "./admissionregistration.k8s.io/v1beta1": "./builtin/admissionregistration.k8s.io@v1beta1/mod.ts", 12 | "./apiextensions.k8s.io/v1": "./builtin/apiextensions.k8s.io@v1/mod.ts", 13 | "./apiregistration.k8s.io/v1": "./builtin/apiregistration.k8s.io@v1/mod.ts", 14 | "./apps/v1": "./builtin/apps@v1/mod.ts", 15 | "./authentication.k8s.io/v1": "./builtin/authentication.k8s.io@v1/mod.ts", 16 | "./authorization.k8s.io/v1": "./builtin/authorization.k8s.io@v1/mod.ts", 17 | "./autoscaling/v1": "./builtin/autoscaling@v1/mod.ts", 18 | "./autoscaling/v2": "./builtin/autoscaling@v2/mod.ts", 19 | "./batch/v1": "./builtin/batch@v1/mod.ts", 20 | "./certificates.k8s.io/v1": "./builtin/certificates.k8s.io@v1/mod.ts", 21 | "./certificates.k8s.io/v1alpha1": "./builtin/certificates.k8s.io@v1alpha1/mod.ts", 22 | "./certificates.k8s.io/v1beta1": "./builtin/certificates.k8s.io@v1beta1/mod.ts", 23 | "./coordination.k8s.io/v1": "./builtin/coordination.k8s.io@v1/mod.ts", 24 | "./coordination.k8s.io/v1alpha2": "./builtin/coordination.k8s.io@v1alpha2/mod.ts", 25 | "./coordination.k8s.io/v1beta1": "./builtin/coordination.k8s.io@v1beta1/mod.ts", 26 | "./core/v1": "./builtin/core@v1/mod.ts", 27 | "./discovery.k8s.io/v1": "./builtin/discovery.k8s.io@v1/mod.ts", 28 | "./events.k8s.io/v1": "./builtin/events.k8s.io@v1/mod.ts", 29 | "./flowcontrol.apiserver.k8s.io/v1": "./builtin/flowcontrol.apiserver.k8s.io@v1/mod.ts", 30 | "./internal.apiserver.k8s.io/v1alpha1": "./builtin/internal.apiserver.k8s.io@v1alpha1/mod.ts", 31 | "./meta/v1": "./builtin/meta@v1/structs.ts", 32 | "./networking.k8s.io/v1": "./builtin/networking.k8s.io@v1/mod.ts", 33 | "./networking.k8s.io/v1beta1": "./builtin/networking.k8s.io@v1beta1/mod.ts", 34 | "./node.k8s.io/v1": "./builtin/node.k8s.io@v1/mod.ts", 35 | "./policy/v1": "./builtin/policy@v1/mod.ts", 36 | "./rbac.authorization.k8s.io/v1": "./builtin/rbac.authorization.k8s.io@v1/mod.ts", 37 | "./resource.k8s.io/v1": "./builtin/resource.k8s.io@v1/mod.ts", 38 | "./resource.k8s.io/v1alpha3": "./builtin/resource.k8s.io@v1alpha3/mod.ts", 39 | "./resource.k8s.io/v1beta1": "./builtin/resource.k8s.io@v1beta1/mod.ts", 40 | "./resource.k8s.io/v1beta2": "./builtin/resource.k8s.io@v1beta2/mod.ts", 41 | "./scheduling.k8s.io/v1": "./builtin/scheduling.k8s.io@v1/mod.ts", 42 | "./storage.k8s.io/v1": "./builtin/storage.k8s.io@v1/mod.ts", 43 | "./storage.k8s.io/v1alpha1": "./builtin/storage.k8s.io@v1alpha1/mod.ts", 44 | "./storage.k8s.io/v1beta1": "./builtin/storage.k8s.io@v1beta1/mod.ts", 45 | "./storagemigration.k8s.io/v1alpha1": "./builtin/storagemigration.k8s.io@v1alpha1/mod.ts", 46 | 47 | "./argoproj.io/v1alpha1": "./argo-cd/argoproj.io@v1alpha1/mod.ts", 48 | 49 | "./acme.cert-manager.io/v1": "./cert-manager/acme.cert-manager.io@v1/mod.ts", 50 | "./cert-manager.io/v1": "./cert-manager/cert-manager.io@v1/mod.ts", 51 | 52 | "./externaldns.k8s.io/v1alpha1": "./external-dns/externaldns.k8s.io@v1alpha1/mod.ts", 53 | 54 | "./autoscaling.k8s.io/v1": "./vpa/autoscaling.k8s.io@v1/mod.ts", 55 | 56 | "./common.ts": "./common.ts", 57 | "./deps.ts": "./deps.ts", 58 | "./operations.ts": "./operations.ts", 59 | "./tunnels.ts": "./tunnels.ts" 60 | }, 61 | "publish": { 62 | "exclude": [ 63 | "examples", 64 | ] 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /lib/builtin/node.k8s.io@v1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for NodeV1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as CoreV1 from "../core@v1/structs.ts"; 5 | import * as MetaV1 from "../meta@v1/structs.ts"; 6 | type ListOf = { 7 | metadata: MetaV1.ListMeta; 8 | items: Array; 9 | }; 10 | 11 | /** Overhead structure represents the resource overhead associated with running a pod. */ 12 | export interface Overhead { 13 | podFixed?: Record | null; 14 | } 15 | export function toOverhead(input: c.JSONValue): Overhead { 16 | const obj = c.checkObj(input); 17 | return { 18 | podFixed: c.readOpt(obj["podFixed"], x => c.readMap(x, c.toQuantity)), 19 | }} 20 | export function fromOverhead(input: Overhead): c.JSONValue { 21 | return { 22 | ...input, 23 | podFixed: c.writeMap(input.podFixed, c.fromQuantity), 24 | }} 25 | 26 | /** RuntimeClass defines a class of container runtime supported in the cluster. The RuntimeClass is used to determine which container runtime is used to run all containers in a pod. RuntimeClasses are manually defined by a user or cluster provisioner, and referenced in the PodSpec. The Kubelet is responsible for resolving the RuntimeClassName reference before running the pod. For more details, see https://kubernetes.io/docs/concepts/containers/runtime-class/ */ 27 | export interface RuntimeClass { 28 | apiVersion?: "node.k8s.io/v1"; 29 | kind?: "RuntimeClass"; 30 | handler: string; 31 | metadata?: MetaV1.ObjectMeta | null; 32 | overhead?: Overhead | null; 33 | scheduling?: Scheduling | null; 34 | } 35 | export function toRuntimeClass(input: c.JSONValue): RuntimeClass & c.ApiKind { 36 | const obj = c.checkObj(input); 37 | return { 38 | ...c.assertOrAddApiVersionAndKind(obj, "node.k8s.io/v1", "RuntimeClass"), 39 | handler: c.checkStr(obj["handler"]), 40 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 41 | overhead: c.readOpt(obj["overhead"], toOverhead), 42 | scheduling: c.readOpt(obj["scheduling"], toScheduling), 43 | }} 44 | export function fromRuntimeClass(input: RuntimeClass): c.JSONValue { 45 | return { 46 | ...c.assertOrAddApiVersionAndKind(input, "node.k8s.io/v1", "RuntimeClass"), 47 | ...input, 48 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 49 | overhead: input.overhead != null ? fromOverhead(input.overhead) : undefined, 50 | scheduling: input.scheduling != null ? fromScheduling(input.scheduling) : undefined, 51 | }} 52 | 53 | /** Scheduling specifies the scheduling constraints for nodes supporting a RuntimeClass. */ 54 | export interface Scheduling { 55 | nodeSelector?: Record | null; 56 | tolerations?: Array | null; 57 | } 58 | export function toScheduling(input: c.JSONValue): Scheduling { 59 | const obj = c.checkObj(input); 60 | return { 61 | nodeSelector: c.readOpt(obj["nodeSelector"], x => c.readMap(x, c.checkStr)), 62 | tolerations: c.readOpt(obj["tolerations"], x => c.readList(x, CoreV1.toToleration)), 63 | }} 64 | export function fromScheduling(input: Scheduling): c.JSONValue { 65 | return { 66 | ...input, 67 | tolerations: input.tolerations?.map(CoreV1.fromToleration), 68 | }} 69 | 70 | /** RuntimeClassList is a list of RuntimeClass objects. */ 71 | export interface RuntimeClassList extends ListOf { 72 | apiVersion?: "node.k8s.io/v1"; 73 | kind?: "RuntimeClassList"; 74 | }; 75 | export function toRuntimeClassList(input: c.JSONValue): RuntimeClassList & c.ApiKind { 76 | const obj = c.checkObj(input); 77 | return { 78 | ...c.assertOrAddApiVersionAndKind(obj, "node.k8s.io/v1", "RuntimeClassList"), 79 | metadata: MetaV1.toListMeta(obj.metadata), 80 | items: c.readList(obj.items, toRuntimeClass), 81 | }} 82 | -------------------------------------------------------------------------------- /lib/examples/run-job-evented.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S deno run --allow-net --allow-read --allow-env --allow-run --unstable 2 | 3 | import { Reflector, autoDetectClient } from "../deps.ts"; 4 | import { CoreV1Api } from "../builtin/core@v1/mod.ts"; 5 | import { BatchV1Api } from "../builtin/batch@v1/mod.ts"; 6 | import { TextLineStream } from "https://deno.land/std@0.177.0/streams/text_line_stream.ts"; 7 | 8 | const restClient = await autoDetectClient(); 9 | const namespace = restClient.defaultNamespace ?? 'default'; 10 | const batchApi = new BatchV1Api(restClient).namespace(namespace); 11 | const coreApi = new CoreV1Api(restClient).namespace(namespace); 12 | 13 | const job = await batchApi.createJob({ 14 | metadata: { 15 | generateName: 'deno-example-', 16 | }, 17 | spec: { 18 | ttlSecondsAfterFinished: 60 * 60, 19 | parallelism: 1, 20 | completions: 1, 21 | template: { 22 | spec: { 23 | restartPolicy: 'OnFailure', 24 | containers: [{ 25 | name: 'job', 26 | image: 'busybox', 27 | args: [ 28 | 'sh', 29 | '-euxc', 30 | 'sleep 10s; date', 31 | ], 32 | }], 33 | }, 34 | }, 35 | }, 36 | }); 37 | console.log(`Created job`, job.metadata?.name); 38 | 39 | // Set up concurrency-limited background log streaming 40 | const streamedPods = new Set(); 41 | async function streamPodsLogsIfNotAlready(podName: string) { 42 | if (streamedPods.has(podName)) return; 43 | streamedPods.add(podName); 44 | console.log(podName, 'log'.padStart(10), '\\', 'Starting stream...'); 45 | const stream = await coreApi.streamPodLog(podName, { 46 | follow: true, 47 | }); 48 | try { 49 | await stream 50 | .pipeThrough(new TextLineStream()) 51 | .pipeTo(new WritableStream({ 52 | write(line) { 53 | console.log(podName, 'log'.padStart(10), '|', line); 54 | }, 55 | close() { 56 | console.log(podName, 'log'.padStart(10), '/', 'EOF'); 57 | }, 58 | })); 59 | } finally { 60 | streamedPods.delete(podName); 61 | } 62 | } 63 | 64 | // Set up an event-based Pod watcher so we can efficiently know as soon as any pod completes 65 | const podWatcher = new Reflector( 66 | opts => coreApi.getPodList({ ...opts, labelSelector: `job-name=${job.metadata?.name}` }), 67 | opts => coreApi.watchPodList({ ...opts, labelSelector: `job-name=${job.metadata?.name}` })); 68 | podWatcher.run(); 69 | for await (const x of podWatcher.observeAll()) { 70 | if (x.type == 'ERROR') throw new Error(x.object.message ?? 'Watch Error'); 71 | if (x.type == 'ADDED' || x.type == 'MODIFIED' || x.type == 'DELETED') { 72 | const pod = x.object; 73 | const containerState = pod.status?.containerStatuses?.[0].state; 74 | console.log(pod.metadata?.name, x.type.toLowerCase().padStart(10), 75 | (containerState?.waiting ?? containerState?.terminated)?.reason ?? pod.status?.phase); 76 | 77 | // Possibly up a log tail if the container is running 78 | if (containerState?.running) { 79 | streamPodsLogsIfNotAlready(pod.metadata.name); 80 | } 81 | 82 | // End the event-based loop when we see a succeeded Pod 83 | if (pod.status?.phase == 'Succeeded') { 84 | break; 85 | } 86 | } 87 | } 88 | 89 | // Delete our Job and print the final status (if we get one) 90 | const deletion = await batchApi.deleteJob(job.metadata?.name ?? '', { 91 | propagationPolicy: 'Background', // Remove child pods as well 92 | }); 93 | if (deletion.kind == 'Job') { 94 | console.log('Final job status:', deletion.status); 95 | } 96 | 97 | // Note: the "Reflector" implementation is not yet capable of shutting down cleanly. 98 | // We terminate the process as a work-around. 99 | Deno.exit(); 100 | -------------------------------------------------------------------------------- /generation/openapi.ts: -------------------------------------------------------------------------------- 1 | // partially from https://github.com/manifoldco/swagger-to-ts/blob/master/src/types/OpenAPI2.ts 2 | /** 3 | * OpenAPI2 types 4 | * These aren’t exhaustive or complete by any means; they simply provide only 5 | * the parts that swagger-to-ts needs to know about. 6 | */ 7 | 8 | export interface OpenAPI2 { 9 | paths: { [path: string]: OpenAPI2PathObject }; 10 | definitions: { [key: string]: OpenAPI2SchemaObject }; 11 | swagger: string; 12 | [key: string]: any; // handle other properties beyond swagger-to-ts’ concern 13 | } 14 | 15 | export type OpenAPI2Type = 16 | | "array" 17 | | "binary" 18 | | "boolean" 19 | | "byte" 20 | | "date" 21 | | "dateTime" 22 | | "double" 23 | | "float" 24 | | "integer" 25 | | "long" 26 | | "number" 27 | | "object" 28 | | "password" 29 | | "string"; 30 | 31 | // export type OpenAPI2Reference = { $ref: string }; 32 | 33 | export interface OpenAPI2SchemaObject { 34 | $ref?: string | null; 35 | 36 | additionalProperties?: OpenAPI2SchemaObject | boolean | null; 37 | allOf?: OpenAPI2SchemaObject[] | null; 38 | description?: string | null; 39 | enum?: string[] | null; 40 | format?: "byte" | "date-time" | "double" | "int32" | "int64" | "int-or-string" | null; 41 | items?: OpenAPI2SchemaObject | null; 42 | oneOf?: (OpenAPI2SchemaObject)[] | null; 43 | properties?: { [index: string]: OpenAPI2SchemaObject } | null; 44 | required?: string[] | null; 45 | title?: string | null; 46 | type?: OpenAPI2Type | null; // allow this to be optional to cover cases when this is missing 47 | // [key: string]: any; // allow arbitrary x-something properties 48 | 49 | // Kubernetes CRD extensions 50 | "x-kubernetes-embedded-resource"?: boolean | null; 51 | "x-kubernetes-int-or-string"?: boolean | null; 52 | "x-kubernetes-list-map-keys"?: string[] | null; 53 | "x-kubernetes-list-type"?: string | null; 54 | "x-kubernetes-preserve-unknown-fields"?: true | null; 55 | 'x-kubernetes-group-version-kind'?: GroupVersionKind[] | null; 56 | } 57 | 58 | export type OpenAPI2Methods = 59 | | "get" 60 | | "post" 61 | | "delete" 62 | | "put" 63 | | "patch" 64 | | "options" 65 | | "head"; 66 | export const MethodList: Array = [ 67 | "get", 68 | "post", 69 | "delete", 70 | "put", 71 | "patch", 72 | "options", 73 | "head", 74 | ]; 75 | 76 | export interface OpenAPI2PathObject { 77 | parameters: Array; 78 | // [method: OpenAPI2Methods]: OpenAPI2PathMethod; 79 | get: OpenAPI2PathMethod; 80 | post: OpenAPI2PathMethod; 81 | delete: OpenAPI2PathMethod; 82 | put: OpenAPI2PathMethod; 83 | patch: OpenAPI2PathMethod; 84 | options: OpenAPI2PathMethod; 85 | head: OpenAPI2PathMethod; 86 | } 87 | 88 | export interface OpenAPI2RequestParameter { 89 | $ref?: string; 90 | uniqueItems?: boolean; // set-like 91 | type?: OpenAPI2Type; 92 | schema?: OpenAPI2SchemaObject; 93 | description?: string; 94 | name: string; 95 | in: 'body' | 'header' | 'path' | 'query'; 96 | required?: boolean; 97 | } 98 | 99 | export interface OpenAPI2PathMethod { 100 | description?: string; 101 | consumes: Array; 102 | produces: Array; 103 | schemes: Array; 104 | tags?: Array; 105 | operationId: string; 106 | parameters?: Array; 107 | responses: { [status: string]: OpenAPI2PathResponse }; 108 | 'x-kubernetes-action'?: 'get' | "connect" | "delete" | "deletecollection" | "get" | "list" | "patch" | "post" | "put" | "watch" | "watchlist", 109 | 'x-kubernetes-group-version-kind'?: GroupVersionKind; 110 | } 111 | export interface OpenAPI2PathResponse { 112 | description?: string; 113 | schema?: OpenAPI2SchemaObject; 114 | } 115 | 116 | export interface GroupVersionKind { 117 | group: string; 118 | kind: string; 119 | version: string; 120 | } 121 | -------------------------------------------------------------------------------- /lib/examples/top-nodes.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S deno run --allow-net --allow-read --allow-env --allow-run --unstable 2 | 3 | /* 4 | * Pulls the latest metrics from every node and prints some high-level metrics. 5 | * This uses a 'proxy...Request' function which tunnels an HTTP request 6 | * to a Kubernetes Node's internal API, even from outside the cluster! 7 | * This API is also available for Pods and Services. 8 | * 9 | * $ deno run --allow-run lib/examples/top-nodes.ts 2>/dev/null 10 | * gke-dust-persist3-190b8935-6tf2 : 11 | * - CPU: 10 % 12 | * - Memory: 1919 Mi used, 1780 Mi avail 13 | * - Network: 35224 Mi received / 20365 Mi sent on eth0 14 | * - FS: 11334 Mi used, 4563 Mi avail of 15912 Mi capacity 15 | * - inodes: 169 k used, 868 k avail of 1037 k capacity 16 | * - pods: 22 17 | * gke-dust-volatile1-b331c9e9-wh9p : 18 | * - CPU: 7.1 % 19 | * - Memory: 949 Mi used, 2749 Mi avail 20 | * - Network: 2748 Mi received / 3457 Mi sent on eth0 21 | * - FS: 3356 Mi used, 12541 Mi avail of 15912 Mi capacity 22 | * - inodes: 68 k used, 970 k avail of 1037 k capacity 23 | * - pods: 18 24 | */ 25 | 26 | import { autoDetectClient } from "../deps.ts"; 27 | import { CoreV1Api } from "../builtin/core@v1/mod.ts"; 28 | 29 | const restClient = await autoDetectClient(); 30 | const coreApi = new CoreV1Api(restClient); 31 | 32 | // Loop over every registered node 33 | const nodeList = await coreApi.getNodeList(); 34 | for (const node of nodeList.items) { 35 | const nodeName = node.metadata?.name; 36 | if (!nodeName) continue; 37 | 38 | try { 39 | // Fetch metrics from the actual node, via the Kubernetes APIServer 40 | const summary = await coreApi.proxyNodeRequest(nodeName, { 41 | port: 10250, 42 | method: 'GET', 43 | path: '/stats/summary', 44 | expectJson: true, // runs JSON.parse on the response body 45 | }) as unknown as StatsSummary; // 'unsafe' cast :/ 46 | 47 | printStats(summary); 48 | 49 | } catch (err: unknown) { 50 | console.log(nodeName, ':'); 51 | console.log(' -', 'Failed:', (err as Error).message); 52 | } 53 | } 54 | 55 | // Process and print a retrieve stats summary 56 | function printStats(summary: StatsSummary) { 57 | const {nodeName, cpu, memory, network, fs} = summary.node; 58 | console.log(nodeName, ':'); 59 | 60 | if (cpu) console.log(' -', 'CPU:', 61 | Math.ceil(cpu.usageNanoCores / 1000 / 1000) / 10, '%'); 62 | 63 | if (memory) console.log(' -', 'Memory:', 64 | Math.ceil(memory.workingSetBytes / 1024 / 1024), 'Mi used,', 65 | Math.ceil(memory.availableBytes / 1024 / 1024), 'Mi avail'); 66 | 67 | if (network) console.log(' -', 'Network:', 68 | Math.ceil(network.rxBytes / 1024 / 1024), 'Mi received /', 69 | Math.ceil(network.txBytes / 1024 / 1024), 'Mi sent', 70 | 'on', network.name); 71 | 72 | if (fs) console.log(' -', 'FS:', 73 | Math.ceil(fs.usedBytes / 1024 / 1024), 'Mi used,', 74 | Math.ceil(fs.availableBytes / 1024 / 1024), 'Mi avail', 75 | 'of', Math.ceil(fs.capacityBytes / 1024 / 1024), 'Mi capacity'); 76 | 77 | if (fs?.inodes) console.log(' -', 'inodes:', 78 | Math.ceil(fs.inodesUsed / 1000), 'k used,', 79 | Math.ceil(fs.inodesFree / 1000), 'k avail', 80 | 'of', Math.ceil(fs.inodes / 1000), 'k capacity'); 81 | 82 | console.log(' -', 'pods:', summary.pods.length); 83 | } 84 | 85 | // This is a subset of the Kubelet API 86 | interface StatsSummary { 87 | node: { 88 | nodeName: string; 89 | startTime: string; 90 | cpu?: { 91 | time: string; 92 | usageNanoCores: number; 93 | usageCoreNanoSeconds: number; 94 | }; 95 | memory?: { 96 | time: string; 97 | availableBytes: number; 98 | workingSetBytes: number; 99 | }; 100 | network?: { 101 | time: string; 102 | name: string; 103 | rxBytes: number; 104 | rxErrors: number; 105 | txBytes: number; 106 | txErrors: number; 107 | }; 108 | fs?: { 109 | time: string; 110 | availableBytes: number; 111 | capacityBytes: number; 112 | usedBytes: number; 113 | inodesFree: number; 114 | inodes: number; 115 | inodesUsed: number; 116 | }; 117 | }; 118 | pods: unknown[]; // We only care about the list's size for this demo 119 | } 120 | -------------------------------------------------------------------------------- /lib/tunnels_test.ts: -------------------------------------------------------------------------------- 1 | import { assertEquals } from "https://deno.land/std@0.198.0/assert/mod.ts"; 2 | import { StdioTunnel, type ExecStatus, PortforwardTunnel } from "./tunnels.ts"; 3 | 4 | Deno.test('stdiotunnel output buffering', async () => { 5 | const intendedStdout = 'hello world'; 6 | 7 | const tunnel = new StdioTunnel({ 8 | getReadableStream(opts) { 9 | if (opts.index == 1) return ReadableStream 10 | .from([intendedStdout]) 11 | .pipeThrough(new TextEncoderStream()); 12 | if (opts.index == 3) return ReadableStream 13 | .from([JSON.stringify({ 14 | status: 'Success', 15 | } satisfies ExecStatus)]) 16 | .pipeThrough(new TextEncoderStream()); 17 | throw new Error(`Unexpected read stream ${opts.index}`); 18 | }, 19 | getWritableStream(opts) { 20 | throw new Error(`Unexpected write stream ${opts.index}`); 21 | }, 22 | whenReady: () => Promise.resolve(), 23 | close: () => Promise.resolve(), 24 | [Symbol.dispose]: () => Promise.resolve(), 25 | subProtocol: 'v4.tunnel.k8s.io', 26 | transportProtocol: 'Opaque', 27 | }, new URLSearchParams([ 28 | ['stdout', '1'], 29 | ])); 30 | await tunnel.ready; 31 | 32 | const output = await tunnel.output(); 33 | 34 | assertEquals(new TextDecoder().decode(output.stdout), intendedStdout); 35 | }); 36 | 37 | Deno.test('stdiotunnel stdin half-close', async () => { 38 | const startByte = 10; 39 | const echoedByte = 20; 40 | const flushByte = 30; 41 | 42 | const echoPipe = new TransformStream({ 43 | start(ctlr) { 44 | ctlr.enqueue(new Uint8Array([startByte])); 45 | }, 46 | flush(ctlr) { 47 | ctlr.enqueue(new Uint8Array([flushByte])); 48 | }, 49 | }); 50 | 51 | const tunnel = new StdioTunnel({ 52 | getReadableStream(opts) { 53 | if (opts.index == 1) return echoPipe.readable; 54 | if (opts.index == 3) return ReadableStream 55 | .from([JSON.stringify({ 56 | status: 'Success', 57 | } satisfies ExecStatus)]) 58 | .pipeThrough(new TextEncoderStream()); 59 | throw new Error(`Unexpected read stream ${opts.index}`); 60 | }, 61 | getWritableStream(opts) { 62 | if (opts.index == 0) return echoPipe.writable; 63 | throw new Error(`Unexpected write stream ${opts.index}`); 64 | }, 65 | whenReady: () => Promise.resolve(), 66 | close: () => Promise.resolve(), 67 | [Symbol.dispose]: () => Promise.resolve(), 68 | subProtocol: 'v4.tunnel.k8s.io', 69 | transportProtocol: 'Opaque', 70 | }, new URLSearchParams([ 71 | ['stdin', '1'], 72 | ['stdout', '1'], 73 | ])); 74 | await tunnel.ready; 75 | 76 | const stdin = tunnel.stdin.getWriter(); 77 | stdin.write(new Uint8Array([echoedByte])); 78 | stdin.close(); 79 | 80 | const output = await tunnel.output(); 81 | 82 | assertEquals(output.stdout, new Uint8Array([startByte, echoedByte, flushByte])); 83 | }); 84 | 85 | Deno.test('portforwardtunnel echo pipe', async () => { 86 | const echoPipe = new TransformStream({ 87 | start(ctlr) { 88 | ctlr.enqueue(new Uint8Array([0,70])); // TODO: this should fail due to mismatch 89 | }, 90 | }); 91 | 92 | const tunnel = new PortforwardTunnel({ 93 | getReadableStream(opts) { 94 | if (opts.index == 0) return echoPipe.readable; 95 | return new ReadableStream({ 96 | start(ctlr) { 97 | ctlr.close(); 98 | }, 99 | }).pipeThrough(new TextEncoderStream()); 100 | }, 101 | getWritableStream(opts) { 102 | if (opts.index == 0) return echoPipe.writable; 103 | throw new Error(`Unexpected write stream ${opts.index}`); 104 | }, 105 | whenReady: () => Promise.resolve(), 106 | close: () => Promise.resolve(), 107 | [Symbol.dispose]: () => Promise.resolve(), 108 | subProtocol: 'v4.tunnel.k8s.io', 109 | transportProtocol: 'WebSocket', // specifies semantics of tunnelled socket setup 110 | }, new URLSearchParams([ 111 | ['ports', '80'], 112 | ])); 113 | await tunnel.ready; 114 | 115 | const intendedText = 'asdf pickel'; 116 | 117 | const socket = tunnel.connectToPort(80); 118 | const [output] = await Promise.all([ 119 | new Response(socket.readable).text(), 120 | (async () => { 121 | const writer = socket.writable.getWriter(); 122 | await writer.write(new TextEncoder().encode(intendedText)); 123 | writer.close(); 124 | })(), 125 | ]); 126 | 127 | assertEquals(output, intendedText); 128 | }); 129 | -------------------------------------------------------------------------------- /lib/builtin/node.k8s.io@v1/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./structs.ts"; 2 | 3 | // Autogenerated API file for NodeV1 4 | import * as c from "../../common.ts"; 5 | import * as operations from "../../operations.ts"; 6 | import * as MetaV1 from "../meta@v1/structs.ts"; 7 | import * as NodeV1 from "./structs.ts"; 8 | 9 | export class NodeV1Api { 10 | #client: c.RestClient; 11 | #root = "/apis/node.k8s.io/v1/"; 12 | constructor(client: c.RestClient) { 13 | this.#client = client; 14 | } 15 | 16 | async getRuntimeClassList( 17 | opts: operations.GetListOpts = {}, 18 | ): Promise { 19 | const resp = await this.#client.performRequest({ 20 | method: "GET", 21 | path: `${this.#root}runtimeclasses`, 22 | expectJson: true, 23 | querystring: operations.formatGetListOpts(opts), 24 | abortSignal: opts.abortSignal, 25 | }); 26 | return NodeV1.toRuntimeClassList(resp); 27 | } 28 | 29 | async watchRuntimeClassList( 30 | opts: operations.WatchListOpts = {}, 31 | ): Promise> { 32 | const resp = await this.#client.performRequest({ 33 | method: "GET", 34 | path: `${this.#root}runtimeclasses`, 35 | expectJson: true, 36 | expectStream: true, 37 | querystring: operations.formatWatchListOpts(opts), 38 | abortSignal: opts.abortSignal, 39 | }); 40 | return resp.pipeThrough(new c.WatchEventTransformer(NodeV1.toRuntimeClass, MetaV1.toStatus)); 41 | } 42 | 43 | async createRuntimeClass( 44 | body: NodeV1.RuntimeClass, 45 | opts: operations.PutOpts = {}, 46 | ): Promise { 47 | const resp = await this.#client.performRequest({ 48 | method: "POST", 49 | path: `${this.#root}runtimeclasses`, 50 | expectJson: true, 51 | querystring: operations.formatPutOpts(opts), 52 | bodyJson: NodeV1.fromRuntimeClass(body), 53 | abortSignal: opts.abortSignal, 54 | }); 55 | return NodeV1.toRuntimeClass(resp); 56 | } 57 | 58 | async deleteRuntimeClassList( 59 | opts: operations.DeleteListOpts = {}, 60 | ): Promise { 61 | const resp = await this.#client.performRequest({ 62 | method: "DELETE", 63 | path: `${this.#root}runtimeclasses`, 64 | expectJson: true, 65 | querystring: operations.formatDeleteListOpts(opts), 66 | abortSignal: opts.abortSignal, 67 | }); 68 | return NodeV1.toRuntimeClassList(resp); 69 | } 70 | 71 | async getRuntimeClass( 72 | name: string, 73 | opts: operations.NoOpts = {}, 74 | ): Promise { 75 | const resp = await this.#client.performRequest({ 76 | method: "GET", 77 | path: `${this.#root}runtimeclasses/${name}`, 78 | expectJson: true, 79 | abortSignal: opts.abortSignal, 80 | }); 81 | return NodeV1.toRuntimeClass(resp); 82 | } 83 | 84 | async deleteRuntimeClass( 85 | name: string, 86 | opts: operations.DeleteOpts = {}, 87 | ): Promise { 88 | const resp = await this.#client.performRequest({ 89 | method: "DELETE", 90 | path: `${this.#root}runtimeclasses/${name}`, 91 | expectJson: true, 92 | querystring: operations.formatDeleteOpts(opts), 93 | abortSignal: opts.abortSignal, 94 | }); 95 | if (c.isStatusKind(resp)) return MetaV1.toStatus(resp); 96 | return NodeV1.toRuntimeClass(resp); 97 | } 98 | 99 | async replaceRuntimeClass( 100 | name: string, 101 | body: NodeV1.RuntimeClass, 102 | opts: operations.PutOpts = {}, 103 | ): Promise { 104 | const resp = await this.#client.performRequest({ 105 | method: "PUT", 106 | path: `${this.#root}runtimeclasses/${name}`, 107 | expectJson: true, 108 | querystring: operations.formatPutOpts(opts), 109 | bodyJson: NodeV1.fromRuntimeClass(body), 110 | abortSignal: opts.abortSignal, 111 | }); 112 | return NodeV1.toRuntimeClass(resp); 113 | } 114 | 115 | async patchRuntimeClass( 116 | name: string, 117 | type: c.PatchType, 118 | body: NodeV1.RuntimeClass | c.JsonPatch, 119 | opts: operations.PatchOpts = {}, 120 | ): Promise { 121 | const resp = await this.#client.performRequest({ 122 | method: "PATCH", 123 | path: `${this.#root}runtimeclasses/${name}`, 124 | expectJson: true, 125 | querystring: operations.formatPatchOpts(opts), 126 | contentType: c.getPatchContentType(type), 127 | bodyJson: Array.isArray(body) ? body : NodeV1.fromRuntimeClass(body), 128 | abortSignal: opts.abortSignal, 129 | }); 130 | return NodeV1.toRuntimeClass(resp); 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /lib/builtin/scheduling.k8s.io@v1/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./structs.ts"; 2 | 3 | // Autogenerated API file for SchedulingV1 4 | import * as c from "../../common.ts"; 5 | import * as operations from "../../operations.ts"; 6 | import * as MetaV1 from "../meta@v1/structs.ts"; 7 | import * as SchedulingV1 from "./structs.ts"; 8 | 9 | export class SchedulingV1Api { 10 | #client: c.RestClient; 11 | #root = "/apis/scheduling.k8s.io/v1/"; 12 | constructor(client: c.RestClient) { 13 | this.#client = client; 14 | } 15 | 16 | async getPriorityClassList( 17 | opts: operations.GetListOpts = {}, 18 | ): Promise { 19 | const resp = await this.#client.performRequest({ 20 | method: "GET", 21 | path: `${this.#root}priorityclasses`, 22 | expectJson: true, 23 | querystring: operations.formatGetListOpts(opts), 24 | abortSignal: opts.abortSignal, 25 | }); 26 | return SchedulingV1.toPriorityClassList(resp); 27 | } 28 | 29 | async watchPriorityClassList( 30 | opts: operations.WatchListOpts = {}, 31 | ): Promise> { 32 | const resp = await this.#client.performRequest({ 33 | method: "GET", 34 | path: `${this.#root}priorityclasses`, 35 | expectJson: true, 36 | expectStream: true, 37 | querystring: operations.formatWatchListOpts(opts), 38 | abortSignal: opts.abortSignal, 39 | }); 40 | return resp.pipeThrough(new c.WatchEventTransformer(SchedulingV1.toPriorityClass, MetaV1.toStatus)); 41 | } 42 | 43 | async createPriorityClass( 44 | body: SchedulingV1.PriorityClass, 45 | opts: operations.PutOpts = {}, 46 | ): Promise { 47 | const resp = await this.#client.performRequest({ 48 | method: "POST", 49 | path: `${this.#root}priorityclasses`, 50 | expectJson: true, 51 | querystring: operations.formatPutOpts(opts), 52 | bodyJson: SchedulingV1.fromPriorityClass(body), 53 | abortSignal: opts.abortSignal, 54 | }); 55 | return SchedulingV1.toPriorityClass(resp); 56 | } 57 | 58 | async deletePriorityClassList( 59 | opts: operations.DeleteListOpts = {}, 60 | ): Promise { 61 | const resp = await this.#client.performRequest({ 62 | method: "DELETE", 63 | path: `${this.#root}priorityclasses`, 64 | expectJson: true, 65 | querystring: operations.formatDeleteListOpts(opts), 66 | abortSignal: opts.abortSignal, 67 | }); 68 | return SchedulingV1.toPriorityClassList(resp); 69 | } 70 | 71 | async getPriorityClass( 72 | name: string, 73 | opts: operations.NoOpts = {}, 74 | ): Promise { 75 | const resp = await this.#client.performRequest({ 76 | method: "GET", 77 | path: `${this.#root}priorityclasses/${name}`, 78 | expectJson: true, 79 | abortSignal: opts.abortSignal, 80 | }); 81 | return SchedulingV1.toPriorityClass(resp); 82 | } 83 | 84 | async deletePriorityClass( 85 | name: string, 86 | opts: operations.DeleteOpts = {}, 87 | ): Promise { 88 | const resp = await this.#client.performRequest({ 89 | method: "DELETE", 90 | path: `${this.#root}priorityclasses/${name}`, 91 | expectJson: true, 92 | querystring: operations.formatDeleteOpts(opts), 93 | abortSignal: opts.abortSignal, 94 | }); 95 | if (c.isStatusKind(resp)) return MetaV1.toStatus(resp); 96 | return SchedulingV1.toPriorityClass(resp); 97 | } 98 | 99 | async replacePriorityClass( 100 | name: string, 101 | body: SchedulingV1.PriorityClass, 102 | opts: operations.PutOpts = {}, 103 | ): Promise { 104 | const resp = await this.#client.performRequest({ 105 | method: "PUT", 106 | path: `${this.#root}priorityclasses/${name}`, 107 | expectJson: true, 108 | querystring: operations.formatPutOpts(opts), 109 | bodyJson: SchedulingV1.fromPriorityClass(body), 110 | abortSignal: opts.abortSignal, 111 | }); 112 | return SchedulingV1.toPriorityClass(resp); 113 | } 114 | 115 | async patchPriorityClass( 116 | name: string, 117 | type: c.PatchType, 118 | body: SchedulingV1.PriorityClass | c.JsonPatch, 119 | opts: operations.PatchOpts = {}, 120 | ): Promise { 121 | const resp = await this.#client.performRequest({ 122 | method: "PATCH", 123 | path: `${this.#root}priorityclasses/${name}`, 124 | expectJson: true, 125 | querystring: operations.formatPatchOpts(opts), 126 | contentType: c.getPatchContentType(type), 127 | bodyJson: Array.isArray(body) ? body : SchedulingV1.fromPriorityClass(body), 128 | abortSignal: opts.abortSignal, 129 | }); 130 | return SchedulingV1.toPriorityClass(resp); 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /lib/builtin/events.k8s.io@v1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for EventsV1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as CoreV1 from "../core@v1/structs.ts"; 5 | import * as MetaV1 from "../meta@v1/structs.ts"; 6 | type ListOf = { 7 | metadata: MetaV1.ListMeta; 8 | items: Array; 9 | }; 10 | 11 | /** Event is a report of an event somewhere in the cluster. It generally denotes some state change in the system. Events have a limited retention time and triggers and messages may evolve with time. Event consumers should not rely on the timing of an event with a given Reason reflecting a consistent underlying trigger, or the continued existence of events with that Reason. Events should be treated as informative, best-effort, supplemental data. */ 12 | export interface Event { 13 | apiVersion?: "events.k8s.io/v1"; 14 | kind?: "Event"; 15 | action?: string | null; 16 | deprecatedCount?: number | null; 17 | deprecatedFirstTimestamp?: c.Time | null; 18 | deprecatedLastTimestamp?: c.Time | null; 19 | deprecatedSource?: CoreV1.EventSource | null; 20 | eventTime: c.MicroTime; 21 | metadata?: MetaV1.ObjectMeta | null; 22 | note?: string | null; 23 | reason?: string | null; 24 | regarding?: CoreV1.ObjectReference | null; 25 | related?: CoreV1.ObjectReference | null; 26 | reportingController?: string | null; 27 | reportingInstance?: string | null; 28 | series?: EventSeries | null; 29 | type?: string | null; 30 | } 31 | export function toEvent(input: c.JSONValue): Event & c.ApiKind { 32 | const obj = c.checkObj(input); 33 | return { 34 | ...c.assertOrAddApiVersionAndKind(obj, "events.k8s.io/v1", "Event"), 35 | action: c.readOpt(obj["action"], c.checkStr), 36 | deprecatedCount: c.readOpt(obj["deprecatedCount"], c.checkNum), 37 | deprecatedFirstTimestamp: c.readOpt(obj["deprecatedFirstTimestamp"], c.toTime), 38 | deprecatedLastTimestamp: c.readOpt(obj["deprecatedLastTimestamp"], c.toTime), 39 | deprecatedSource: c.readOpt(obj["deprecatedSource"], CoreV1.toEventSource), 40 | eventTime: c.toMicroTime(obj["eventTime"]), 41 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 42 | note: c.readOpt(obj["note"], c.checkStr), 43 | reason: c.readOpt(obj["reason"], c.checkStr), 44 | regarding: c.readOpt(obj["regarding"], CoreV1.toObjectReference), 45 | related: c.readOpt(obj["related"], CoreV1.toObjectReference), 46 | reportingController: c.readOpt(obj["reportingController"], c.checkStr), 47 | reportingInstance: c.readOpt(obj["reportingInstance"], c.checkStr), 48 | series: c.readOpt(obj["series"], toEventSeries), 49 | type: c.readOpt(obj["type"], c.checkStr), 50 | }} 51 | export function fromEvent(input: Event): c.JSONValue { 52 | return { 53 | ...c.assertOrAddApiVersionAndKind(input, "events.k8s.io/v1", "Event"), 54 | ...input, 55 | deprecatedFirstTimestamp: input.deprecatedFirstTimestamp != null ? c.fromTime(input.deprecatedFirstTimestamp) : undefined, 56 | deprecatedLastTimestamp: input.deprecatedLastTimestamp != null ? c.fromTime(input.deprecatedLastTimestamp) : undefined, 57 | deprecatedSource: input.deprecatedSource != null ? CoreV1.fromEventSource(input.deprecatedSource) : undefined, 58 | eventTime: input.eventTime != null ? c.fromMicroTime(input.eventTime) : undefined, 59 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 60 | regarding: input.regarding != null ? CoreV1.fromObjectReference(input.regarding) : undefined, 61 | related: input.related != null ? CoreV1.fromObjectReference(input.related) : undefined, 62 | series: input.series != null ? fromEventSeries(input.series) : undefined, 63 | }} 64 | 65 | /** EventSeries contain information on series of events, i.e. thing that was/is happening continuously for some time. How often to update the EventSeries is up to the event reporters. The default event reporter in "k8s.io/client-go/tools/events/event_broadcaster.go" shows how this struct is updated on heartbeats and can guide customized reporter implementations. */ 66 | export interface EventSeries { 67 | count: number; 68 | lastObservedTime: c.MicroTime; 69 | } 70 | export function toEventSeries(input: c.JSONValue): EventSeries { 71 | const obj = c.checkObj(input); 72 | return { 73 | count: c.checkNum(obj["count"]), 74 | lastObservedTime: c.toMicroTime(obj["lastObservedTime"]), 75 | }} 76 | export function fromEventSeries(input: EventSeries): c.JSONValue { 77 | return { 78 | ...input, 79 | lastObservedTime: input.lastObservedTime != null ? c.fromMicroTime(input.lastObservedTime) : undefined, 80 | }} 81 | 82 | /** EventList is a list of Event objects. */ 83 | export interface EventList extends ListOf { 84 | apiVersion?: "events.k8s.io/v1"; 85 | kind?: "EventList"; 86 | }; 87 | export function toEventList(input: c.JSONValue): EventList & c.ApiKind { 88 | const obj = c.checkObj(input); 89 | return { 90 | ...c.assertOrAddApiVersionAndKind(obj, "events.k8s.io/v1", "EventList"), 91 | metadata: MetaV1.toListMeta(obj.metadata), 92 | items: c.readList(obj.items, toEvent), 93 | }} 94 | -------------------------------------------------------------------------------- /lib/builtin/resource.k8s.io@v1alpha3/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./structs.ts"; 2 | 3 | // Autogenerated API file for ResourceV1alpha3 4 | import * as c from "../../common.ts"; 5 | import * as operations from "../../operations.ts"; 6 | import * as MetaV1 from "../meta@v1/structs.ts"; 7 | import * as ResourceV1alpha3 from "./structs.ts"; 8 | 9 | export class ResourceV1alpha3Api { 10 | #client: c.RestClient; 11 | #root = "/apis/resource.k8s.io/v1alpha3/"; 12 | constructor(client: c.RestClient) { 13 | this.#client = client; 14 | } 15 | 16 | async getDeviceTaintRuleList( 17 | opts: operations.GetListOpts = {}, 18 | ): Promise { 19 | const resp = await this.#client.performRequest({ 20 | method: "GET", 21 | path: `${this.#root}devicetaintrules`, 22 | expectJson: true, 23 | querystring: operations.formatGetListOpts(opts), 24 | abortSignal: opts.abortSignal, 25 | }); 26 | return ResourceV1alpha3.toDeviceTaintRuleList(resp); 27 | } 28 | 29 | async watchDeviceTaintRuleList( 30 | opts: operations.WatchListOpts = {}, 31 | ): Promise> { 32 | const resp = await this.#client.performRequest({ 33 | method: "GET", 34 | path: `${this.#root}devicetaintrules`, 35 | expectJson: true, 36 | expectStream: true, 37 | querystring: operations.formatWatchListOpts(opts), 38 | abortSignal: opts.abortSignal, 39 | }); 40 | return resp.pipeThrough(new c.WatchEventTransformer(ResourceV1alpha3.toDeviceTaintRule, MetaV1.toStatus)); 41 | } 42 | 43 | async createDeviceTaintRule( 44 | body: ResourceV1alpha3.DeviceTaintRule, 45 | opts: operations.PutOpts = {}, 46 | ): Promise { 47 | const resp = await this.#client.performRequest({ 48 | method: "POST", 49 | path: `${this.#root}devicetaintrules`, 50 | expectJson: true, 51 | querystring: operations.formatPutOpts(opts), 52 | bodyJson: ResourceV1alpha3.fromDeviceTaintRule(body), 53 | abortSignal: opts.abortSignal, 54 | }); 55 | return ResourceV1alpha3.toDeviceTaintRule(resp); 56 | } 57 | 58 | async deleteDeviceTaintRuleList( 59 | opts: operations.DeleteListOpts = {}, 60 | ): Promise { 61 | const resp = await this.#client.performRequest({ 62 | method: "DELETE", 63 | path: `${this.#root}devicetaintrules`, 64 | expectJson: true, 65 | querystring: operations.formatDeleteListOpts(opts), 66 | abortSignal: opts.abortSignal, 67 | }); 68 | return ResourceV1alpha3.toDeviceTaintRuleList(resp); 69 | } 70 | 71 | async getDeviceTaintRule( 72 | name: string, 73 | opts: operations.NoOpts = {}, 74 | ): Promise { 75 | const resp = await this.#client.performRequest({ 76 | method: "GET", 77 | path: `${this.#root}devicetaintrules/${name}`, 78 | expectJson: true, 79 | abortSignal: opts.abortSignal, 80 | }); 81 | return ResourceV1alpha3.toDeviceTaintRule(resp); 82 | } 83 | 84 | async deleteDeviceTaintRule( 85 | name: string, 86 | opts: operations.DeleteOpts = {}, 87 | ): Promise { 88 | const resp = await this.#client.performRequest({ 89 | method: "DELETE", 90 | path: `${this.#root}devicetaintrules/${name}`, 91 | expectJson: true, 92 | querystring: operations.formatDeleteOpts(opts), 93 | abortSignal: opts.abortSignal, 94 | }); 95 | if (c.isStatusKind(resp)) return MetaV1.toStatus(resp); 96 | return ResourceV1alpha3.toDeviceTaintRule(resp); 97 | } 98 | 99 | async replaceDeviceTaintRule( 100 | name: string, 101 | body: ResourceV1alpha3.DeviceTaintRule, 102 | opts: operations.PutOpts = {}, 103 | ): Promise { 104 | const resp = await this.#client.performRequest({ 105 | method: "PUT", 106 | path: `${this.#root}devicetaintrules/${name}`, 107 | expectJson: true, 108 | querystring: operations.formatPutOpts(opts), 109 | bodyJson: ResourceV1alpha3.fromDeviceTaintRule(body), 110 | abortSignal: opts.abortSignal, 111 | }); 112 | return ResourceV1alpha3.toDeviceTaintRule(resp); 113 | } 114 | 115 | async patchDeviceTaintRule( 116 | name: string, 117 | type: c.PatchType, 118 | body: ResourceV1alpha3.DeviceTaintRule | c.JsonPatch, 119 | opts: operations.PatchOpts = {}, 120 | ): Promise { 121 | const resp = await this.#client.performRequest({ 122 | method: "PATCH", 123 | path: `${this.#root}devicetaintrules/${name}`, 124 | expectJson: true, 125 | querystring: operations.formatPatchOpts(opts), 126 | contentType: c.getPatchContentType(type), 127 | bodyJson: Array.isArray(body) ? body : ResourceV1alpha3.fromDeviceTaintRule(body), 128 | abortSignal: opts.abortSignal, 129 | }); 130 | return ResourceV1alpha3.toDeviceTaintRule(resp); 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /lib/builtin/storage.k8s.io@v1beta1/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./structs.ts"; 2 | 3 | // Autogenerated API file for StorageV1beta1 4 | import * as c from "../../common.ts"; 5 | import * as operations from "../../operations.ts"; 6 | import * as MetaV1 from "../meta@v1/structs.ts"; 7 | import * as StorageV1beta1 from "./structs.ts"; 8 | 9 | export class StorageV1beta1Api { 10 | #client: c.RestClient; 11 | #root = "/apis/storage.k8s.io/v1beta1/"; 12 | constructor(client: c.RestClient) { 13 | this.#client = client; 14 | } 15 | 16 | async getVolumeAttributesClassList( 17 | opts: operations.GetListOpts = {}, 18 | ): Promise { 19 | const resp = await this.#client.performRequest({ 20 | method: "GET", 21 | path: `${this.#root}volumeattributesclasses`, 22 | expectJson: true, 23 | querystring: operations.formatGetListOpts(opts), 24 | abortSignal: opts.abortSignal, 25 | }); 26 | return StorageV1beta1.toVolumeAttributesClassList(resp); 27 | } 28 | 29 | async watchVolumeAttributesClassList( 30 | opts: operations.WatchListOpts = {}, 31 | ): Promise> { 32 | const resp = await this.#client.performRequest({ 33 | method: "GET", 34 | path: `${this.#root}volumeattributesclasses`, 35 | expectJson: true, 36 | expectStream: true, 37 | querystring: operations.formatWatchListOpts(opts), 38 | abortSignal: opts.abortSignal, 39 | }); 40 | return resp.pipeThrough(new c.WatchEventTransformer(StorageV1beta1.toVolumeAttributesClass, MetaV1.toStatus)); 41 | } 42 | 43 | async createVolumeAttributesClass( 44 | body: StorageV1beta1.VolumeAttributesClass, 45 | opts: operations.PutOpts = {}, 46 | ): Promise { 47 | const resp = await this.#client.performRequest({ 48 | method: "POST", 49 | path: `${this.#root}volumeattributesclasses`, 50 | expectJson: true, 51 | querystring: operations.formatPutOpts(opts), 52 | bodyJson: StorageV1beta1.fromVolumeAttributesClass(body), 53 | abortSignal: opts.abortSignal, 54 | }); 55 | return StorageV1beta1.toVolumeAttributesClass(resp); 56 | } 57 | 58 | async deleteVolumeAttributesClassList( 59 | opts: operations.DeleteListOpts = {}, 60 | ): Promise { 61 | const resp = await this.#client.performRequest({ 62 | method: "DELETE", 63 | path: `${this.#root}volumeattributesclasses`, 64 | expectJson: true, 65 | querystring: operations.formatDeleteListOpts(opts), 66 | abortSignal: opts.abortSignal, 67 | }); 68 | return StorageV1beta1.toVolumeAttributesClassList(resp); 69 | } 70 | 71 | async getVolumeAttributesClass( 72 | name: string, 73 | opts: operations.NoOpts = {}, 74 | ): Promise { 75 | const resp = await this.#client.performRequest({ 76 | method: "GET", 77 | path: `${this.#root}volumeattributesclasses/${name}`, 78 | expectJson: true, 79 | abortSignal: opts.abortSignal, 80 | }); 81 | return StorageV1beta1.toVolumeAttributesClass(resp); 82 | } 83 | 84 | async deleteVolumeAttributesClass( 85 | name: string, 86 | opts: operations.DeleteOpts = {}, 87 | ): Promise { 88 | const resp = await this.#client.performRequest({ 89 | method: "DELETE", 90 | path: `${this.#root}volumeattributesclasses/${name}`, 91 | expectJson: true, 92 | querystring: operations.formatDeleteOpts(opts), 93 | abortSignal: opts.abortSignal, 94 | }); 95 | if (c.isStatusKind(resp)) return MetaV1.toStatus(resp); 96 | return StorageV1beta1.toVolumeAttributesClass(resp); 97 | } 98 | 99 | async replaceVolumeAttributesClass( 100 | name: string, 101 | body: StorageV1beta1.VolumeAttributesClass, 102 | opts: operations.PutOpts = {}, 103 | ): Promise { 104 | const resp = await this.#client.performRequest({ 105 | method: "PUT", 106 | path: `${this.#root}volumeattributesclasses/${name}`, 107 | expectJson: true, 108 | querystring: operations.formatPutOpts(opts), 109 | bodyJson: StorageV1beta1.fromVolumeAttributesClass(body), 110 | abortSignal: opts.abortSignal, 111 | }); 112 | return StorageV1beta1.toVolumeAttributesClass(resp); 113 | } 114 | 115 | async patchVolumeAttributesClass( 116 | name: string, 117 | type: c.PatchType, 118 | body: StorageV1beta1.VolumeAttributesClass | c.JsonPatch, 119 | opts: operations.PatchOpts = {}, 120 | ): Promise { 121 | const resp = await this.#client.performRequest({ 122 | method: "PATCH", 123 | path: `${this.#root}volumeattributesclasses/${name}`, 124 | expectJson: true, 125 | querystring: operations.formatPatchOpts(opts), 126 | contentType: c.getPatchContentType(type), 127 | bodyJson: Array.isArray(body) ? body : StorageV1beta1.fromVolumeAttributesClass(body), 128 | abortSignal: opts.abortSignal, 129 | }); 130 | return StorageV1beta1.toVolumeAttributesClass(resp); 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /lib/builtin/certificates.k8s.io@v1beta1/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./structs.ts"; 2 | 3 | // Autogenerated API file for CertificatesV1beta1 4 | import * as c from "../../common.ts"; 5 | import * as operations from "../../operations.ts"; 6 | import * as MetaV1 from "../meta@v1/structs.ts"; 7 | import * as CertificatesV1beta1 from "./structs.ts"; 8 | 9 | export class CertificatesV1beta1Api { 10 | #client: c.RestClient; 11 | #root = "/apis/certificates.k8s.io/v1beta1/"; 12 | constructor(client: c.RestClient) { 13 | this.#client = client; 14 | } 15 | 16 | async getClusterTrustBundleList( 17 | opts: operations.GetListOpts = {}, 18 | ): Promise { 19 | const resp = await this.#client.performRequest({ 20 | method: "GET", 21 | path: `${this.#root}clustertrustbundles`, 22 | expectJson: true, 23 | querystring: operations.formatGetListOpts(opts), 24 | abortSignal: opts.abortSignal, 25 | }); 26 | return CertificatesV1beta1.toClusterTrustBundleList(resp); 27 | } 28 | 29 | async watchClusterTrustBundleList( 30 | opts: operations.WatchListOpts = {}, 31 | ): Promise> { 32 | const resp = await this.#client.performRequest({ 33 | method: "GET", 34 | path: `${this.#root}clustertrustbundles`, 35 | expectJson: true, 36 | expectStream: true, 37 | querystring: operations.formatWatchListOpts(opts), 38 | abortSignal: opts.abortSignal, 39 | }); 40 | return resp.pipeThrough(new c.WatchEventTransformer(CertificatesV1beta1.toClusterTrustBundle, MetaV1.toStatus)); 41 | } 42 | 43 | async createClusterTrustBundle( 44 | body: CertificatesV1beta1.ClusterTrustBundle, 45 | opts: operations.PutOpts = {}, 46 | ): Promise { 47 | const resp = await this.#client.performRequest({ 48 | method: "POST", 49 | path: `${this.#root}clustertrustbundles`, 50 | expectJson: true, 51 | querystring: operations.formatPutOpts(opts), 52 | bodyJson: CertificatesV1beta1.fromClusterTrustBundle(body), 53 | abortSignal: opts.abortSignal, 54 | }); 55 | return CertificatesV1beta1.toClusterTrustBundle(resp); 56 | } 57 | 58 | async deleteClusterTrustBundleList( 59 | opts: operations.DeleteListOpts = {}, 60 | ): Promise { 61 | const resp = await this.#client.performRequest({ 62 | method: "DELETE", 63 | path: `${this.#root}clustertrustbundles`, 64 | expectJson: true, 65 | querystring: operations.formatDeleteListOpts(opts), 66 | abortSignal: opts.abortSignal, 67 | }); 68 | return CertificatesV1beta1.toClusterTrustBundleList(resp); 69 | } 70 | 71 | async getClusterTrustBundle( 72 | name: string, 73 | opts: operations.NoOpts = {}, 74 | ): Promise { 75 | const resp = await this.#client.performRequest({ 76 | method: "GET", 77 | path: `${this.#root}clustertrustbundles/${name}`, 78 | expectJson: true, 79 | abortSignal: opts.abortSignal, 80 | }); 81 | return CertificatesV1beta1.toClusterTrustBundle(resp); 82 | } 83 | 84 | async deleteClusterTrustBundle( 85 | name: string, 86 | opts: operations.DeleteOpts = {}, 87 | ): Promise { 88 | const resp = await this.#client.performRequest({ 89 | method: "DELETE", 90 | path: `${this.#root}clustertrustbundles/${name}`, 91 | expectJson: true, 92 | querystring: operations.formatDeleteOpts(opts), 93 | abortSignal: opts.abortSignal, 94 | }); 95 | if (c.isStatusKind(resp)) return MetaV1.toStatus(resp); 96 | return CertificatesV1beta1.toClusterTrustBundle(resp); 97 | } 98 | 99 | async replaceClusterTrustBundle( 100 | name: string, 101 | body: CertificatesV1beta1.ClusterTrustBundle, 102 | opts: operations.PutOpts = {}, 103 | ): Promise { 104 | const resp = await this.#client.performRequest({ 105 | method: "PUT", 106 | path: `${this.#root}clustertrustbundles/${name}`, 107 | expectJson: true, 108 | querystring: operations.formatPutOpts(opts), 109 | bodyJson: CertificatesV1beta1.fromClusterTrustBundle(body), 110 | abortSignal: opts.abortSignal, 111 | }); 112 | return CertificatesV1beta1.toClusterTrustBundle(resp); 113 | } 114 | 115 | async patchClusterTrustBundle( 116 | name: string, 117 | type: c.PatchType, 118 | body: CertificatesV1beta1.ClusterTrustBundle | c.JsonPatch, 119 | opts: operations.PatchOpts = {}, 120 | ): Promise { 121 | const resp = await this.#client.performRequest({ 122 | method: "PATCH", 123 | path: `${this.#root}clustertrustbundles/${name}`, 124 | expectJson: true, 125 | querystring: operations.formatPatchOpts(opts), 126 | contentType: c.getPatchContentType(type), 127 | bodyJson: Array.isArray(body) ? body : CertificatesV1beta1.fromClusterTrustBundle(body), 128 | abortSignal: opts.abortSignal, 129 | }); 130 | return CertificatesV1beta1.toClusterTrustBundle(resp); 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /lib/builtin/storage.k8s.io@v1alpha1/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./structs.ts"; 2 | 3 | // Autogenerated API file for StorageV1alpha1 4 | import * as c from "../../common.ts"; 5 | import * as operations from "../../operations.ts"; 6 | import * as MetaV1 from "../meta@v1/structs.ts"; 7 | import * as StorageV1alpha1 from "./structs.ts"; 8 | 9 | export class StorageV1alpha1Api { 10 | #client: c.RestClient; 11 | #root = "/apis/storage.k8s.io/v1alpha1/"; 12 | constructor(client: c.RestClient) { 13 | this.#client = client; 14 | } 15 | 16 | async getVolumeAttributesClassList( 17 | opts: operations.GetListOpts = {}, 18 | ): Promise { 19 | const resp = await this.#client.performRequest({ 20 | method: "GET", 21 | path: `${this.#root}volumeattributesclasses`, 22 | expectJson: true, 23 | querystring: operations.formatGetListOpts(opts), 24 | abortSignal: opts.abortSignal, 25 | }); 26 | return StorageV1alpha1.toVolumeAttributesClassList(resp); 27 | } 28 | 29 | async watchVolumeAttributesClassList( 30 | opts: operations.WatchListOpts = {}, 31 | ): Promise> { 32 | const resp = await this.#client.performRequest({ 33 | method: "GET", 34 | path: `${this.#root}volumeattributesclasses`, 35 | expectJson: true, 36 | expectStream: true, 37 | querystring: operations.formatWatchListOpts(opts), 38 | abortSignal: opts.abortSignal, 39 | }); 40 | return resp.pipeThrough(new c.WatchEventTransformer(StorageV1alpha1.toVolumeAttributesClass, MetaV1.toStatus)); 41 | } 42 | 43 | async createVolumeAttributesClass( 44 | body: StorageV1alpha1.VolumeAttributesClass, 45 | opts: operations.PutOpts = {}, 46 | ): Promise { 47 | const resp = await this.#client.performRequest({ 48 | method: "POST", 49 | path: `${this.#root}volumeattributesclasses`, 50 | expectJson: true, 51 | querystring: operations.formatPutOpts(opts), 52 | bodyJson: StorageV1alpha1.fromVolumeAttributesClass(body), 53 | abortSignal: opts.abortSignal, 54 | }); 55 | return StorageV1alpha1.toVolumeAttributesClass(resp); 56 | } 57 | 58 | async deleteVolumeAttributesClassList( 59 | opts: operations.DeleteListOpts = {}, 60 | ): Promise { 61 | const resp = await this.#client.performRequest({ 62 | method: "DELETE", 63 | path: `${this.#root}volumeattributesclasses`, 64 | expectJson: true, 65 | querystring: operations.formatDeleteListOpts(opts), 66 | abortSignal: opts.abortSignal, 67 | }); 68 | return StorageV1alpha1.toVolumeAttributesClassList(resp); 69 | } 70 | 71 | async getVolumeAttributesClass( 72 | name: string, 73 | opts: operations.NoOpts = {}, 74 | ): Promise { 75 | const resp = await this.#client.performRequest({ 76 | method: "GET", 77 | path: `${this.#root}volumeattributesclasses/${name}`, 78 | expectJson: true, 79 | abortSignal: opts.abortSignal, 80 | }); 81 | return StorageV1alpha1.toVolumeAttributesClass(resp); 82 | } 83 | 84 | async deleteVolumeAttributesClass( 85 | name: string, 86 | opts: operations.DeleteOpts = {}, 87 | ): Promise { 88 | const resp = await this.#client.performRequest({ 89 | method: "DELETE", 90 | path: `${this.#root}volumeattributesclasses/${name}`, 91 | expectJson: true, 92 | querystring: operations.formatDeleteOpts(opts), 93 | abortSignal: opts.abortSignal, 94 | }); 95 | if (c.isStatusKind(resp)) return MetaV1.toStatus(resp); 96 | return StorageV1alpha1.toVolumeAttributesClass(resp); 97 | } 98 | 99 | async replaceVolumeAttributesClass( 100 | name: string, 101 | body: StorageV1alpha1.VolumeAttributesClass, 102 | opts: operations.PutOpts = {}, 103 | ): Promise { 104 | const resp = await this.#client.performRequest({ 105 | method: "PUT", 106 | path: `${this.#root}volumeattributesclasses/${name}`, 107 | expectJson: true, 108 | querystring: operations.formatPutOpts(opts), 109 | bodyJson: StorageV1alpha1.fromVolumeAttributesClass(body), 110 | abortSignal: opts.abortSignal, 111 | }); 112 | return StorageV1alpha1.toVolumeAttributesClass(resp); 113 | } 114 | 115 | async patchVolumeAttributesClass( 116 | name: string, 117 | type: c.PatchType, 118 | body: StorageV1alpha1.VolumeAttributesClass | c.JsonPatch, 119 | opts: operations.PatchOpts = {}, 120 | ): Promise { 121 | const resp = await this.#client.performRequest({ 122 | method: "PATCH", 123 | path: `${this.#root}volumeattributesclasses/${name}`, 124 | expectJson: true, 125 | querystring: operations.formatPatchOpts(opts), 126 | contentType: c.getPatchContentType(type), 127 | bodyJson: Array.isArray(body) ? body : StorageV1alpha1.fromVolumeAttributesClass(body), 128 | abortSignal: opts.abortSignal, 129 | }); 130 | return StorageV1alpha1.toVolumeAttributesClass(resp); 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /lib/builtin/storagemigration.k8s.io@v1alpha1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for StoragemigrationV1alpha1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** The names of the group, the version, and the resource. */ 11 | export interface GroupVersionResource { 12 | group?: string | null; 13 | resource?: string | null; 14 | version?: string | null; 15 | } 16 | export function toGroupVersionResource(input: c.JSONValue): GroupVersionResource { 17 | const obj = c.checkObj(input); 18 | return { 19 | group: c.readOpt(obj["group"], c.checkStr), 20 | resource: c.readOpt(obj["resource"], c.checkStr), 21 | version: c.readOpt(obj["version"], c.checkStr), 22 | }} 23 | export function fromGroupVersionResource(input: GroupVersionResource): c.JSONValue { 24 | return { 25 | ...input, 26 | }} 27 | 28 | /** Describes the state of a migration at a certain point. */ 29 | export interface MigrationCondition { 30 | lastUpdateTime?: c.Time | null; 31 | message?: string | null; 32 | reason?: string | null; 33 | status: string; 34 | type: string; 35 | } 36 | export function toMigrationCondition(input: c.JSONValue): MigrationCondition { 37 | const obj = c.checkObj(input); 38 | return { 39 | lastUpdateTime: c.readOpt(obj["lastUpdateTime"], c.toTime), 40 | message: c.readOpt(obj["message"], c.checkStr), 41 | reason: c.readOpt(obj["reason"], c.checkStr), 42 | status: c.checkStr(obj["status"]), 43 | type: c.checkStr(obj["type"]), 44 | }} 45 | export function fromMigrationCondition(input: MigrationCondition): c.JSONValue { 46 | return { 47 | ...input, 48 | lastUpdateTime: input.lastUpdateTime != null ? c.fromTime(input.lastUpdateTime) : undefined, 49 | }} 50 | 51 | /** StorageVersionMigration represents a migration of stored data to the latest storage version. */ 52 | export interface StorageVersionMigration { 53 | apiVersion?: "storagemigration.k8s.io/v1alpha1"; 54 | kind?: "StorageVersionMigration"; 55 | metadata?: MetaV1.ObjectMeta | null; 56 | spec?: StorageVersionMigrationSpec | null; 57 | status?: StorageVersionMigrationStatus | null; 58 | } 59 | export function toStorageVersionMigration(input: c.JSONValue): StorageVersionMigration & c.ApiKind { 60 | const obj = c.checkObj(input); 61 | return { 62 | ...c.assertOrAddApiVersionAndKind(obj, "storagemigration.k8s.io/v1alpha1", "StorageVersionMigration"), 63 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 64 | spec: c.readOpt(obj["spec"], toStorageVersionMigrationSpec), 65 | status: c.readOpt(obj["status"], toStorageVersionMigrationStatus), 66 | }} 67 | export function fromStorageVersionMigration(input: StorageVersionMigration): c.JSONValue { 68 | return { 69 | ...c.assertOrAddApiVersionAndKind(input, "storagemigration.k8s.io/v1alpha1", "StorageVersionMigration"), 70 | ...input, 71 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 72 | spec: input.spec != null ? fromStorageVersionMigrationSpec(input.spec) : undefined, 73 | status: input.status != null ? fromStorageVersionMigrationStatus(input.status) : undefined, 74 | }} 75 | 76 | /** Spec of the storage version migration. */ 77 | export interface StorageVersionMigrationSpec { 78 | continueToken?: string | null; 79 | resource: GroupVersionResource; 80 | } 81 | export function toStorageVersionMigrationSpec(input: c.JSONValue): StorageVersionMigrationSpec { 82 | const obj = c.checkObj(input); 83 | return { 84 | continueToken: c.readOpt(obj["continueToken"], c.checkStr), 85 | resource: toGroupVersionResource(obj["resource"]), 86 | }} 87 | export function fromStorageVersionMigrationSpec(input: StorageVersionMigrationSpec): c.JSONValue { 88 | return { 89 | ...input, 90 | resource: input.resource != null ? fromGroupVersionResource(input.resource) : undefined, 91 | }} 92 | 93 | /** Status of the storage version migration. */ 94 | export interface StorageVersionMigrationStatus { 95 | conditions?: Array | null; 96 | resourceVersion?: string | null; 97 | } 98 | export function toStorageVersionMigrationStatus(input: c.JSONValue): StorageVersionMigrationStatus { 99 | const obj = c.checkObj(input); 100 | return { 101 | conditions: c.readOpt(obj["conditions"], x => c.readList(x, toMigrationCondition)), 102 | resourceVersion: c.readOpt(obj["resourceVersion"], c.checkStr), 103 | }} 104 | export function fromStorageVersionMigrationStatus(input: StorageVersionMigrationStatus): c.JSONValue { 105 | return { 106 | ...input, 107 | conditions: input.conditions?.map(fromMigrationCondition), 108 | }} 109 | 110 | /** StorageVersionMigrationList is a collection of storage version migrations. */ 111 | export interface StorageVersionMigrationList extends ListOf { 112 | apiVersion?: "storagemigration.k8s.io/v1alpha1"; 113 | kind?: "StorageVersionMigrationList"; 114 | }; 115 | export function toStorageVersionMigrationList(input: c.JSONValue): StorageVersionMigrationList & c.ApiKind { 116 | const obj = c.checkObj(input); 117 | return { 118 | ...c.assertOrAddApiVersionAndKind(obj, "storagemigration.k8s.io/v1alpha1", "StorageVersionMigrationList"), 119 | metadata: MetaV1.toListMeta(obj.metadata), 120 | items: c.readList(obj.items, toStorageVersionMigration), 121 | }} 122 | -------------------------------------------------------------------------------- /deno.lock: -------------------------------------------------------------------------------- 1 | { 2 | "version": "5", 3 | "specifiers": { 4 | "jsr:@cloudydeno/kubernetes-client@0.8": "0.8.0", 5 | "jsr:@cloudydeno/stream-observables@1": "1.4.1", 6 | "jsr:@std/internal@^1.0.10": "1.0.10", 7 | "jsr:@std/path@1": "1.1.2", 8 | "jsr:@std/streams@1": "1.0.12", 9 | "jsr:@std/yaml@1": "1.0.9" 10 | }, 11 | "jsr": { 12 | "@cloudydeno/kubernetes-client@0.8.0": { 13 | "integrity": "08066abfc8f7bb17f6a81f727af1d609dc19a11b14a6c941a52bf11f7a6aea36", 14 | "dependencies": [ 15 | "jsr:@std/path", 16 | "jsr:@std/streams", 17 | "jsr:@std/yaml" 18 | ] 19 | }, 20 | "@cloudydeno/stream-observables@1.4.1": { 21 | "integrity": "555aa3d786fcfd066d096fc943ea47afc688618e95146e615705e981008f57c0" 22 | }, 23 | "@std/internal@1.0.10": { 24 | "integrity": "e3be62ce42cab0e177c27698e5d9800122f67b766a0bea6ca4867886cbde8cf7" 25 | }, 26 | "@std/path@1.1.2": { 27 | "integrity": "c0b13b97dfe06546d5e16bf3966b1cadf92e1cc83e56ba5476ad8b498d9e3038", 28 | "dependencies": [ 29 | "jsr:@std/internal" 30 | ] 31 | }, 32 | "@std/streams@1.0.12": { 33 | "integrity": "ae925fa1dc459b1abf5cbaa28cc5c7b0485853af3b2a384b0dc22d86e59dfbf4" 34 | }, 35 | "@std/yaml@1.0.9": { 36 | "integrity": "6bad3dc766dd85b4b37eabcba81b6aa4eac7a392792ae29abcfb0f90602d55bb" 37 | } 38 | }, 39 | "remote": { 40 | "https://deno.land/std@0.177.0/streams/text_line_stream.ts": "a9dd2636c6b90e626e19df26c97034c5f638bdd957cbd5c531d6278fe1d08e90", 41 | "https://deno.land/std@0.198.0/_util/diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", 42 | "https://deno.land/std@0.198.0/assert/_constants.ts": "8a9da298c26750b28b326b297316cdde860bc237533b07e1337c021379e6b2a9", 43 | "https://deno.land/std@0.198.0/assert/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", 44 | "https://deno.land/std@0.198.0/assert/assert.ts": "9a97dad6d98c238938e7540736b826440ad8c1c1e54430ca4c4e623e585607ee", 45 | "https://deno.land/std@0.198.0/assert/assert_almost_equals.ts": "e15ca1f34d0d5e0afae63b3f5d975cbd18335a132e42b0c747d282f62ad2cd6c", 46 | "https://deno.land/std@0.198.0/assert/assert_array_includes.ts": "6856d7f2c3544bc6e62fb4646dfefa3d1df5ff14744d1bca19f0cbaf3b0d66c9", 47 | "https://deno.land/std@0.198.0/assert/assert_equals.ts": "a0ee60574e437bcab2dcb79af9d48dc88845f8fd559468d9c21b15fd638ef943", 48 | "https://deno.land/std@0.198.0/assert/assert_exists.ts": "407cb6b9fb23a835cd8d5ad804e2e2edbbbf3870e322d53f79e1c7a512e2efd7", 49 | "https://deno.land/std@0.198.0/assert/assert_false.ts": "a9962749f4bf5844e3fa494257f1de73d69e4fe0e82c34d0099287552163a2dc", 50 | "https://deno.land/std@0.198.0/assert/assert_instance_of.ts": "09fd297352a5b5bbb16da2b5e1a0d8c6c44da5447772648622dcc7df7af1ddb8", 51 | "https://deno.land/std@0.198.0/assert/assert_is_error.ts": "b4eae4e5d182272efc172bf28e2e30b86bb1650cd88aea059e5d2586d4160fb9", 52 | "https://deno.land/std@0.198.0/assert/assert_match.ts": "c4083f80600bc190309903c95e397a7c9257ff8b5ae5c7ef91e834704e672e9b", 53 | "https://deno.land/std@0.198.0/assert/assert_not_equals.ts": "9f1acab95bd1f5fc9a1b17b8027d894509a745d91bac1718fdab51dc76831754", 54 | "https://deno.land/std@0.198.0/assert/assert_not_instance_of.ts": "0c14d3dfd9ab7a5276ed8ed0b18c703d79a3d106102077ec437bfe7ed912bd22", 55 | "https://deno.land/std@0.198.0/assert/assert_not_match.ts": "3796a5b0c57a1ce6c1c57883dd4286be13a26f715ea662318ab43a8491a13ab0", 56 | "https://deno.land/std@0.198.0/assert/assert_not_strict_equals.ts": "ca6c6d645e95fbc873d25320efeb8c4c6089a9a5e09f92d7c1c4b6e935c2a6ad", 57 | "https://deno.land/std@0.198.0/assert/assert_object_match.ts": "d8fc2867cfd92eeacf9cea621e10336b666de1874a6767b5ec48988838370b54", 58 | "https://deno.land/std@0.198.0/assert/assert_rejects.ts": "45c59724de2701e3b1f67c391d6c71c392363635aad3f68a1b3408f9efca0057", 59 | "https://deno.land/std@0.198.0/assert/assert_strict_equals.ts": "5cf29b38b3f8dece95287325723272aa04e04dbf158d886d662fa594fddc9ed3", 60 | "https://deno.land/std@0.198.0/assert/assert_string_includes.ts": "b821d39ebf5cb0200a348863c86d8c4c4b398e02012ce74ad15666fc4b631b0c", 61 | "https://deno.land/std@0.198.0/assert/assert_throws.ts": "63784e951475cb7bdfd59878cd25a0931e18f6dc32a6077c454b2cd94f4f4bcd", 62 | "https://deno.land/std@0.198.0/assert/assertion_error.ts": "4d0bde9b374dfbcbe8ac23f54f567b77024fb67dbb1906a852d67fe050d42f56", 63 | "https://deno.land/std@0.198.0/assert/equal.ts": "9f1a46d5993966d2596c44e5858eec821859b45f783a5ee2f7a695dfc12d8ece", 64 | "https://deno.land/std@0.198.0/assert/fail.ts": "c36353d7ae6e1f7933d45f8ea51e358c8c4b67d7e7502028598fe1fea062e278", 65 | "https://deno.land/std@0.198.0/assert/mod.ts": "08d55a652c22c5da0215054b21085cec25a5da47ce4a6f9de7d9ad36df35bdee", 66 | "https://deno.land/std@0.198.0/assert/unimplemented.ts": "d56fbeecb1f108331a380f72e3e010a1f161baa6956fd0f7cf3e095ae1a4c75a", 67 | "https://deno.land/std@0.198.0/assert/unreachable.ts": "4600dc0baf7d9c15a7f7d234f00c23bca8f3eba8b140286aaca7aa998cf9a536", 68 | "https://deno.land/std@0.198.0/fmt/colors.ts": "a7eecffdf3d1d54db890723b303847b6e0a1ab4b528ba6958b8f2e754cf1b3bc" 69 | }, 70 | "workspace": { 71 | "members": { 72 | "generation": { 73 | "dependencies": [ 74 | "jsr:@cloudydeno/kubernetes-client@0.8", 75 | "jsr:@std/path@1", 76 | "jsr:@std/yaml@1" 77 | ] 78 | }, 79 | "lib": { 80 | "dependencies": [ 81 | "jsr:@cloudydeno/kubernetes-client@0.8" 82 | ] 83 | } 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /lib/builtin/apiregistration.k8s.io@v1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for ApiregistrationV1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** APIService represents a server for a particular GroupVersion. Name must be "version.group". */ 11 | export interface APIService { 12 | apiVersion?: "apiregistration.k8s.io/v1"; 13 | kind?: "APIService"; 14 | metadata?: MetaV1.ObjectMeta | null; 15 | spec?: APIServiceSpec | null; 16 | status?: APIServiceStatus | null; 17 | } 18 | export function toAPIService(input: c.JSONValue): APIService & c.ApiKind { 19 | const obj = c.checkObj(input); 20 | return { 21 | ...c.assertOrAddApiVersionAndKind(obj, "apiregistration.k8s.io/v1", "APIService"), 22 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 23 | spec: c.readOpt(obj["spec"], toAPIServiceSpec), 24 | status: c.readOpt(obj["status"], toAPIServiceStatus), 25 | }} 26 | export function fromAPIService(input: APIService): c.JSONValue { 27 | return { 28 | ...c.assertOrAddApiVersionAndKind(input, "apiregistration.k8s.io/v1", "APIService"), 29 | ...input, 30 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 31 | spec: input.spec != null ? fromAPIServiceSpec(input.spec) : undefined, 32 | status: input.status != null ? fromAPIServiceStatus(input.status) : undefined, 33 | }} 34 | 35 | /** APIServiceSpec contains information for locating and communicating with a server. Only https is supported, though you are able to disable certificate verification. */ 36 | export interface APIServiceSpec { 37 | caBundle?: string | null; 38 | group?: string | null; 39 | groupPriorityMinimum: number; 40 | insecureSkipTLSVerify?: boolean | null; 41 | service?: ServiceReference | null; 42 | version?: string | null; 43 | versionPriority: number; 44 | } 45 | export function toAPIServiceSpec(input: c.JSONValue): APIServiceSpec { 46 | const obj = c.checkObj(input); 47 | return { 48 | caBundle: c.readOpt(obj["caBundle"], c.checkStr), 49 | group: c.readOpt(obj["group"], c.checkStr), 50 | groupPriorityMinimum: c.checkNum(obj["groupPriorityMinimum"]), 51 | insecureSkipTLSVerify: c.readOpt(obj["insecureSkipTLSVerify"], c.checkBool), 52 | service: c.readOpt(obj["service"], toServiceReference), 53 | version: c.readOpt(obj["version"], c.checkStr), 54 | versionPriority: c.checkNum(obj["versionPriority"]), 55 | }} 56 | export function fromAPIServiceSpec(input: APIServiceSpec): c.JSONValue { 57 | return { 58 | ...input, 59 | service: input.service != null ? fromServiceReference(input.service) : undefined, 60 | }} 61 | 62 | /** ServiceReference holds a reference to Service.legacy.k8s.io */ 63 | export interface ServiceReference { 64 | name?: string | null; 65 | namespace?: string | null; 66 | port?: number | null; 67 | } 68 | export function toServiceReference(input: c.JSONValue): ServiceReference { 69 | const obj = c.checkObj(input); 70 | return { 71 | name: c.readOpt(obj["name"], c.checkStr), 72 | namespace: c.readOpt(obj["namespace"], c.checkStr), 73 | port: c.readOpt(obj["port"], c.checkNum), 74 | }} 75 | export function fromServiceReference(input: ServiceReference): c.JSONValue { 76 | return { 77 | ...input, 78 | }} 79 | 80 | /** APIServiceStatus contains derived information about an API server */ 81 | export interface APIServiceStatus { 82 | conditions?: Array | null; 83 | } 84 | export function toAPIServiceStatus(input: c.JSONValue): APIServiceStatus { 85 | const obj = c.checkObj(input); 86 | return { 87 | conditions: c.readOpt(obj["conditions"], x => c.readList(x, toAPIServiceCondition)), 88 | }} 89 | export function fromAPIServiceStatus(input: APIServiceStatus): c.JSONValue { 90 | return { 91 | ...input, 92 | conditions: input.conditions?.map(fromAPIServiceCondition), 93 | }} 94 | 95 | /** APIServiceCondition describes the state of an APIService at a particular point */ 96 | export interface APIServiceCondition { 97 | lastTransitionTime?: c.Time | null; 98 | message?: string | null; 99 | reason?: string | null; 100 | status: string; 101 | type: string; 102 | } 103 | export function toAPIServiceCondition(input: c.JSONValue): APIServiceCondition { 104 | const obj = c.checkObj(input); 105 | return { 106 | lastTransitionTime: c.readOpt(obj["lastTransitionTime"], c.toTime), 107 | message: c.readOpt(obj["message"], c.checkStr), 108 | reason: c.readOpt(obj["reason"], c.checkStr), 109 | status: c.checkStr(obj["status"]), 110 | type: c.checkStr(obj["type"]), 111 | }} 112 | export function fromAPIServiceCondition(input: APIServiceCondition): c.JSONValue { 113 | return { 114 | ...input, 115 | lastTransitionTime: input.lastTransitionTime != null ? c.fromTime(input.lastTransitionTime) : undefined, 116 | }} 117 | 118 | /** APIServiceList is a list of APIService objects. */ 119 | export interface APIServiceList extends ListOf { 120 | apiVersion?: "apiregistration.k8s.io/v1"; 121 | kind?: "APIServiceList"; 122 | }; 123 | export function toAPIServiceList(input: c.JSONValue): APIServiceList & c.ApiKind { 124 | const obj = c.checkObj(input); 125 | return { 126 | ...c.assertOrAddApiVersionAndKind(obj, "apiregistration.k8s.io/v1", "APIServiceList"), 127 | metadata: MetaV1.toListMeta(obj.metadata), 128 | items: c.readList(obj.items, toAPIService), 129 | }} 130 | -------------------------------------------------------------------------------- /lib/builtin/internal.apiserver.k8s.io@v1alpha1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for InternalApiserverV1alpha1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** An API server instance reports the version it can decode and the version it encodes objects to when persisting objects in the backend. */ 11 | export interface ServerStorageVersion { 12 | apiServerID?: string | null; 13 | decodableVersions?: Array | null; 14 | encodingVersion?: string | null; 15 | servedVersions?: Array | null; 16 | } 17 | export function toServerStorageVersion(input: c.JSONValue): ServerStorageVersion { 18 | const obj = c.checkObj(input); 19 | return { 20 | apiServerID: c.readOpt(obj["apiServerID"], c.checkStr), 21 | decodableVersions: c.readOpt(obj["decodableVersions"], x => c.readList(x, c.checkStr)), 22 | encodingVersion: c.readOpt(obj["encodingVersion"], c.checkStr), 23 | servedVersions: c.readOpt(obj["servedVersions"], x => c.readList(x, c.checkStr)), 24 | }} 25 | export function fromServerStorageVersion(input: ServerStorageVersion): c.JSONValue { 26 | return { 27 | ...input, 28 | }} 29 | 30 | /** Storage version of a specific resource. */ 31 | export interface StorageVersion { 32 | apiVersion?: "internal.apiserver.k8s.io/v1alpha1"; 33 | kind?: "StorageVersion"; 34 | metadata?: MetaV1.ObjectMeta | null; 35 | spec: StorageVersionSpec; 36 | status: StorageVersionStatus; 37 | } 38 | export function toStorageVersion(input: c.JSONValue): StorageVersion & c.ApiKind { 39 | const obj = c.checkObj(input); 40 | return { 41 | ...c.assertOrAddApiVersionAndKind(obj, "internal.apiserver.k8s.io/v1alpha1", "StorageVersion"), 42 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 43 | spec: toStorageVersionSpec(obj["spec"]), 44 | status: toStorageVersionStatus(obj["status"]), 45 | }} 46 | export function fromStorageVersion(input: StorageVersion): c.JSONValue { 47 | return { 48 | ...c.assertOrAddApiVersionAndKind(input, "internal.apiserver.k8s.io/v1alpha1", "StorageVersion"), 49 | ...input, 50 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 51 | spec: input.spec != null ? fromStorageVersionSpec(input.spec) : undefined, 52 | status: input.status != null ? fromStorageVersionStatus(input.status) : undefined, 53 | }} 54 | 55 | /** StorageVersionSpec is an empty spec. */ 56 | export interface StorageVersionSpec { 57 | } 58 | export function toStorageVersionSpec(input: c.JSONValue): StorageVersionSpec { 59 | const obj = c.checkObj(input); 60 | return { 61 | }} 62 | export function fromStorageVersionSpec(input: StorageVersionSpec): c.JSONValue { 63 | return { 64 | ...input, 65 | }} 66 | 67 | /** API server instances report the versions they can decode and the version they encode objects to when persisting objects in the backend. */ 68 | export interface StorageVersionStatus { 69 | commonEncodingVersion?: string | null; 70 | conditions?: Array | null; 71 | storageVersions?: Array | null; 72 | } 73 | export function toStorageVersionStatus(input: c.JSONValue): StorageVersionStatus { 74 | const obj = c.checkObj(input); 75 | return { 76 | commonEncodingVersion: c.readOpt(obj["commonEncodingVersion"], c.checkStr), 77 | conditions: c.readOpt(obj["conditions"], x => c.readList(x, toStorageVersionCondition)), 78 | storageVersions: c.readOpt(obj["storageVersions"], x => c.readList(x, toServerStorageVersion)), 79 | }} 80 | export function fromStorageVersionStatus(input: StorageVersionStatus): c.JSONValue { 81 | return { 82 | ...input, 83 | conditions: input.conditions?.map(fromStorageVersionCondition), 84 | storageVersions: input.storageVersions?.map(fromServerStorageVersion), 85 | }} 86 | 87 | /** Describes the state of the storageVersion at a certain point. */ 88 | export interface StorageVersionCondition { 89 | lastTransitionTime?: c.Time | null; 90 | message: string; 91 | observedGeneration?: number | null; 92 | reason: string; 93 | status: string; 94 | type: string; 95 | } 96 | export function toStorageVersionCondition(input: c.JSONValue): StorageVersionCondition { 97 | const obj = c.checkObj(input); 98 | return { 99 | lastTransitionTime: c.readOpt(obj["lastTransitionTime"], c.toTime), 100 | message: c.checkStr(obj["message"]), 101 | observedGeneration: c.readOpt(obj["observedGeneration"], c.checkNum), 102 | reason: c.checkStr(obj["reason"]), 103 | status: c.checkStr(obj["status"]), 104 | type: c.checkStr(obj["type"]), 105 | }} 106 | export function fromStorageVersionCondition(input: StorageVersionCondition): c.JSONValue { 107 | return { 108 | ...input, 109 | lastTransitionTime: input.lastTransitionTime != null ? c.fromTime(input.lastTransitionTime) : undefined, 110 | }} 111 | 112 | /** A list of StorageVersions. */ 113 | export interface StorageVersionList extends ListOf { 114 | apiVersion?: "internal.apiserver.k8s.io/v1alpha1"; 115 | kind?: "StorageVersionList"; 116 | }; 117 | export function toStorageVersionList(input: c.JSONValue): StorageVersionList & c.ApiKind { 118 | const obj = c.checkObj(input); 119 | return { 120 | ...c.assertOrAddApiVersionAndKind(obj, "internal.apiserver.k8s.io/v1alpha1", "StorageVersionList"), 121 | metadata: MetaV1.toListMeta(obj.metadata), 122 | items: c.readList(obj.items, toStorageVersion), 123 | }} 124 | -------------------------------------------------------------------------------- /lib/builtin/policy@v1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for PolicyV1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** Eviction evicts a pod from its node subject to certain policies and safety constraints. This is a subresource of Pod. A request to cause such an eviction is created by POSTing to .../pods//evictions. */ 11 | export interface Eviction { 12 | apiVersion?: string | null; 13 | deleteOptions?: MetaV1.DeleteOptions | null; 14 | kind?: string | null; 15 | metadata?: MetaV1.ObjectMeta | null; 16 | } 17 | export function toEviction(input: c.JSONValue): Eviction { 18 | const obj = c.checkObj(input); 19 | return { 20 | apiVersion: c.readOpt(obj["apiVersion"], c.checkStr), 21 | deleteOptions: c.readOpt(obj["deleteOptions"], MetaV1.toDeleteOptions), 22 | kind: c.readOpt(obj["kind"], c.checkStr), 23 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 24 | }} 25 | export function fromEviction(input: Eviction): c.JSONValue { 26 | return { 27 | ...input, 28 | deleteOptions: input.deleteOptions != null ? MetaV1.fromDeleteOptions(input.deleteOptions) : undefined, 29 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 30 | }} 31 | 32 | /** PodDisruptionBudget is an object to define the max disruption that can be caused to a collection of pods */ 33 | export interface PodDisruptionBudget { 34 | apiVersion?: "policy/v1"; 35 | kind?: "PodDisruptionBudget"; 36 | metadata?: MetaV1.ObjectMeta | null; 37 | spec?: PodDisruptionBudgetSpec | null; 38 | status?: PodDisruptionBudgetStatus | null; 39 | } 40 | export function toPodDisruptionBudget(input: c.JSONValue): PodDisruptionBudget & c.ApiKind { 41 | const obj = c.checkObj(input); 42 | return { 43 | ...c.assertOrAddApiVersionAndKind(obj, "policy/v1", "PodDisruptionBudget"), 44 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 45 | spec: c.readOpt(obj["spec"], toPodDisruptionBudgetSpec), 46 | status: c.readOpt(obj["status"], toPodDisruptionBudgetStatus), 47 | }} 48 | export function fromPodDisruptionBudget(input: PodDisruptionBudget): c.JSONValue { 49 | return { 50 | ...c.assertOrAddApiVersionAndKind(input, "policy/v1", "PodDisruptionBudget"), 51 | ...input, 52 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 53 | spec: input.spec != null ? fromPodDisruptionBudgetSpec(input.spec) : undefined, 54 | status: input.status != null ? fromPodDisruptionBudgetStatus(input.status) : undefined, 55 | }} 56 | 57 | /** PodDisruptionBudgetSpec is a description of a PodDisruptionBudget. */ 58 | export interface PodDisruptionBudgetSpec { 59 | maxUnavailable?: c.IntOrString | null; 60 | minAvailable?: c.IntOrString | null; 61 | selector?: MetaV1.LabelSelector | null; 62 | unhealthyPodEvictionPolicy?: string | null; 63 | } 64 | export function toPodDisruptionBudgetSpec(input: c.JSONValue): PodDisruptionBudgetSpec { 65 | const obj = c.checkObj(input); 66 | return { 67 | maxUnavailable: c.readOpt(obj["maxUnavailable"], c.toIntOrString), 68 | minAvailable: c.readOpt(obj["minAvailable"], c.toIntOrString), 69 | selector: c.readOpt(obj["selector"], MetaV1.toLabelSelector), 70 | unhealthyPodEvictionPolicy: c.readOpt(obj["unhealthyPodEvictionPolicy"], c.checkStr), 71 | }} 72 | export function fromPodDisruptionBudgetSpec(input: PodDisruptionBudgetSpec): c.JSONValue { 73 | return { 74 | ...input, 75 | selector: input.selector != null ? MetaV1.fromLabelSelector(input.selector) : undefined, 76 | }} 77 | 78 | /** PodDisruptionBudgetStatus represents information about the status of a PodDisruptionBudget. Status may trail the actual state of a system. */ 79 | export interface PodDisruptionBudgetStatus { 80 | conditions?: Array | null; 81 | currentHealthy: number; 82 | desiredHealthy: number; 83 | disruptedPods?: Record | null; 84 | disruptionsAllowed: number; 85 | expectedPods: number; 86 | observedGeneration?: number | null; 87 | } 88 | export function toPodDisruptionBudgetStatus(input: c.JSONValue): PodDisruptionBudgetStatus { 89 | const obj = c.checkObj(input); 90 | return { 91 | conditions: c.readOpt(obj["conditions"], x => c.readList(x, MetaV1.toCondition)), 92 | currentHealthy: c.checkNum(obj["currentHealthy"]), 93 | desiredHealthy: c.checkNum(obj["desiredHealthy"]), 94 | disruptedPods: c.readOpt(obj["disruptedPods"], x => c.readMap(x, c.toTime)), 95 | disruptionsAllowed: c.checkNum(obj["disruptionsAllowed"]), 96 | expectedPods: c.checkNum(obj["expectedPods"]), 97 | observedGeneration: c.readOpt(obj["observedGeneration"], c.checkNum), 98 | }} 99 | export function fromPodDisruptionBudgetStatus(input: PodDisruptionBudgetStatus): c.JSONValue { 100 | return { 101 | ...input, 102 | conditions: input.conditions?.map(MetaV1.fromCondition), 103 | disruptedPods: c.writeMap(input.disruptedPods, c.fromTime), 104 | }} 105 | 106 | /** PodDisruptionBudgetList is a collection of PodDisruptionBudgets. */ 107 | export interface PodDisruptionBudgetList extends ListOf { 108 | apiVersion?: "policy/v1"; 109 | kind?: "PodDisruptionBudgetList"; 110 | }; 111 | export function toPodDisruptionBudgetList(input: c.JSONValue): PodDisruptionBudgetList & c.ApiKind { 112 | const obj = c.checkObj(input); 113 | return { 114 | ...c.assertOrAddApiVersionAndKind(obj, "policy/v1", "PodDisruptionBudgetList"), 115 | metadata: MetaV1.toListMeta(obj.metadata), 116 | items: c.readList(obj.items, toPodDisruptionBudget), 117 | }} 118 | -------------------------------------------------------------------------------- /lib/builtin/resource.k8s.io@v1alpha3/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for ResourceV1alpha3 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** CELDeviceSelector contains a CEL expression for selecting a device. */ 11 | export interface CELDeviceSelector { 12 | expression: string; 13 | } 14 | export function toCELDeviceSelector(input: c.JSONValue): CELDeviceSelector { 15 | const obj = c.checkObj(input); 16 | return { 17 | expression: c.checkStr(obj["expression"]), 18 | }} 19 | export function fromCELDeviceSelector(input: CELDeviceSelector): c.JSONValue { 20 | return { 21 | ...input, 22 | }} 23 | 24 | /** DeviceSelector must have exactly one field set. */ 25 | export interface DeviceSelector { 26 | cel?: CELDeviceSelector | null; 27 | } 28 | export function toDeviceSelector(input: c.JSONValue): DeviceSelector { 29 | const obj = c.checkObj(input); 30 | return { 31 | cel: c.readOpt(obj["cel"], toCELDeviceSelector), 32 | }} 33 | export function fromDeviceSelector(input: DeviceSelector): c.JSONValue { 34 | return { 35 | ...input, 36 | cel: input.cel != null ? fromCELDeviceSelector(input.cel) : undefined, 37 | }} 38 | 39 | /** The device this taint is attached to has the "effect" on any claim which does not tolerate the taint and, through the claim, to pods using the claim. */ 40 | export interface DeviceTaint { 41 | effect: string; 42 | key: string; 43 | timeAdded?: c.Time | null; 44 | value?: string | null; 45 | } 46 | export function toDeviceTaint(input: c.JSONValue): DeviceTaint { 47 | const obj = c.checkObj(input); 48 | return { 49 | effect: c.checkStr(obj["effect"]), 50 | key: c.checkStr(obj["key"]), 51 | timeAdded: c.readOpt(obj["timeAdded"], c.toTime), 52 | value: c.readOpt(obj["value"], c.checkStr), 53 | }} 54 | export function fromDeviceTaint(input: DeviceTaint): c.JSONValue { 55 | return { 56 | ...input, 57 | timeAdded: input.timeAdded != null ? c.fromTime(input.timeAdded) : undefined, 58 | }} 59 | 60 | /** DeviceTaintRule adds one taint to all devices which match the selector. This has the same effect as if the taint was specified directly in the ResourceSlice by the DRA driver. */ 61 | export interface DeviceTaintRule { 62 | apiVersion?: "resource.k8s.io/v1alpha3"; 63 | kind?: "DeviceTaintRule"; 64 | metadata?: MetaV1.ObjectMeta | null; 65 | spec: DeviceTaintRuleSpec; 66 | } 67 | export function toDeviceTaintRule(input: c.JSONValue): DeviceTaintRule & c.ApiKind { 68 | const obj = c.checkObj(input); 69 | return { 70 | ...c.assertOrAddApiVersionAndKind(obj, "resource.k8s.io/v1alpha3", "DeviceTaintRule"), 71 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 72 | spec: toDeviceTaintRuleSpec(obj["spec"]), 73 | }} 74 | export function fromDeviceTaintRule(input: DeviceTaintRule): c.JSONValue { 75 | return { 76 | ...c.assertOrAddApiVersionAndKind(input, "resource.k8s.io/v1alpha3", "DeviceTaintRule"), 77 | ...input, 78 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 79 | spec: input.spec != null ? fromDeviceTaintRuleSpec(input.spec) : undefined, 80 | }} 81 | 82 | /** DeviceTaintRuleSpec specifies the selector and one taint. */ 83 | export interface DeviceTaintRuleSpec { 84 | deviceSelector?: DeviceTaintSelector | null; 85 | taint: DeviceTaint; 86 | } 87 | export function toDeviceTaintRuleSpec(input: c.JSONValue): DeviceTaintRuleSpec { 88 | const obj = c.checkObj(input); 89 | return { 90 | deviceSelector: c.readOpt(obj["deviceSelector"], toDeviceTaintSelector), 91 | taint: toDeviceTaint(obj["taint"]), 92 | }} 93 | export function fromDeviceTaintRuleSpec(input: DeviceTaintRuleSpec): c.JSONValue { 94 | return { 95 | ...input, 96 | deviceSelector: input.deviceSelector != null ? fromDeviceTaintSelector(input.deviceSelector) : undefined, 97 | taint: input.taint != null ? fromDeviceTaint(input.taint) : undefined, 98 | }} 99 | 100 | /** DeviceTaintSelector defines which device(s) a DeviceTaintRule applies to. The empty selector matches all devices. Without a selector, no devices are matched. */ 101 | export interface DeviceTaintSelector { 102 | device?: string | null; 103 | deviceClassName?: string | null; 104 | driver?: string | null; 105 | pool?: string | null; 106 | selectors?: Array | null; 107 | } 108 | export function toDeviceTaintSelector(input: c.JSONValue): DeviceTaintSelector { 109 | const obj = c.checkObj(input); 110 | return { 111 | device: c.readOpt(obj["device"], c.checkStr), 112 | deviceClassName: c.readOpt(obj["deviceClassName"], c.checkStr), 113 | driver: c.readOpt(obj["driver"], c.checkStr), 114 | pool: c.readOpt(obj["pool"], c.checkStr), 115 | selectors: c.readOpt(obj["selectors"], x => c.readList(x, toDeviceSelector)), 116 | }} 117 | export function fromDeviceTaintSelector(input: DeviceTaintSelector): c.JSONValue { 118 | return { 119 | ...input, 120 | selectors: input.selectors?.map(fromDeviceSelector), 121 | }} 122 | 123 | /** DeviceTaintRuleList is a collection of DeviceTaintRules. */ 124 | export interface DeviceTaintRuleList extends ListOf { 125 | apiVersion?: "resource.k8s.io/v1alpha3"; 126 | kind?: "DeviceTaintRuleList"; 127 | }; 128 | export function toDeviceTaintRuleList(input: c.JSONValue): DeviceTaintRuleList & c.ApiKind { 129 | const obj = c.checkObj(input); 130 | return { 131 | ...c.assertOrAddApiVersionAndKind(obj, "resource.k8s.io/v1alpha3", "DeviceTaintRuleList"), 132 | metadata: MetaV1.toListMeta(obj.metadata), 133 | items: c.readList(obj.items, toDeviceTaintRule), 134 | }} 135 | -------------------------------------------------------------------------------- /lib/builtin/events.k8s.io@v1/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./structs.ts"; 2 | 3 | // Autogenerated API file for EventsV1 4 | import * as c from "../../common.ts"; 5 | import * as operations from "../../operations.ts"; 6 | import * as MetaV1 from "../meta@v1/structs.ts"; 7 | import * as EventsV1 from "./structs.ts"; 8 | 9 | export class EventsV1Api { 10 | #client: c.RestClient; 11 | #root = "/apis/events.k8s.io/v1/"; 12 | constructor(client: c.RestClient) { 13 | this.#client = client; 14 | } 15 | 16 | namespace(name: string): EventsV1NamespacedApi { 17 | return new EventsV1NamespacedApi(this.#client, name); 18 | } 19 | myNamespace(): EventsV1NamespacedApi { 20 | if (!this.#client.defaultNamespace) throw new Error("No current namespace is set"); 21 | return new EventsV1NamespacedApi(this.#client, this.#client.defaultNamespace); 22 | } 23 | 24 | async getEventListForAllNamespaces( 25 | opts: operations.GetListOpts = {}, 26 | ): Promise { 27 | const resp = await this.#client.performRequest({ 28 | method: "GET", 29 | path: `${this.#root}events`, 30 | expectJson: true, 31 | querystring: operations.formatGetListOpts(opts), 32 | abortSignal: opts.abortSignal, 33 | }); 34 | return EventsV1.toEventList(resp); 35 | } 36 | 37 | async watchEventListForAllNamespaces( 38 | opts: operations.WatchListOpts = {}, 39 | ): Promise> { 40 | const resp = await this.#client.performRequest({ 41 | method: "GET", 42 | path: `${this.#root}events`, 43 | expectJson: true, 44 | expectStream: true, 45 | querystring: operations.formatWatchListOpts(opts), 46 | abortSignal: opts.abortSignal, 47 | }); 48 | return resp.pipeThrough(new c.WatchEventTransformer(EventsV1.toEvent, MetaV1.toStatus)); 49 | } 50 | 51 | } 52 | 53 | export class EventsV1NamespacedApi { 54 | #client: c.RestClient 55 | #root: string 56 | constructor(client: c.RestClient, namespace: string) { 57 | this.#client = client; 58 | this.#root = `/apis/events.k8s.io/v1/namespaces/${namespace}/`; 59 | } 60 | 61 | async getEventList( 62 | opts: operations.GetListOpts = {}, 63 | ): Promise { 64 | const resp = await this.#client.performRequest({ 65 | method: "GET", 66 | path: `${this.#root}events`, 67 | expectJson: true, 68 | querystring: operations.formatGetListOpts(opts), 69 | abortSignal: opts.abortSignal, 70 | }); 71 | return EventsV1.toEventList(resp); 72 | } 73 | 74 | async watchEventList( 75 | opts: operations.WatchListOpts = {}, 76 | ): Promise> { 77 | const resp = await this.#client.performRequest({ 78 | method: "GET", 79 | path: `${this.#root}events`, 80 | expectJson: true, 81 | expectStream: true, 82 | querystring: operations.formatWatchListOpts(opts), 83 | abortSignal: opts.abortSignal, 84 | }); 85 | return resp.pipeThrough(new c.WatchEventTransformer(EventsV1.toEvent, MetaV1.toStatus)); 86 | } 87 | 88 | async createEvent( 89 | body: EventsV1.Event, 90 | opts: operations.PutOpts = {}, 91 | ): Promise { 92 | const resp = await this.#client.performRequest({ 93 | method: "POST", 94 | path: `${this.#root}events`, 95 | expectJson: true, 96 | querystring: operations.formatPutOpts(opts), 97 | bodyJson: EventsV1.fromEvent(body), 98 | abortSignal: opts.abortSignal, 99 | }); 100 | return EventsV1.toEvent(resp); 101 | } 102 | 103 | async deleteEventList( 104 | opts: operations.DeleteListOpts = {}, 105 | ): Promise { 106 | const resp = await this.#client.performRequest({ 107 | method: "DELETE", 108 | path: `${this.#root}events`, 109 | expectJson: true, 110 | querystring: operations.formatDeleteListOpts(opts), 111 | abortSignal: opts.abortSignal, 112 | }); 113 | return EventsV1.toEventList(resp); 114 | } 115 | 116 | async getEvent( 117 | name: string, 118 | opts: operations.NoOpts = {}, 119 | ): Promise { 120 | const resp = await this.#client.performRequest({ 121 | method: "GET", 122 | path: `${this.#root}events/${name}`, 123 | expectJson: true, 124 | abortSignal: opts.abortSignal, 125 | }); 126 | return EventsV1.toEvent(resp); 127 | } 128 | 129 | async deleteEvent( 130 | name: string, 131 | opts: operations.DeleteOpts = {}, 132 | ): Promise { 133 | const resp = await this.#client.performRequest({ 134 | method: "DELETE", 135 | path: `${this.#root}events/${name}`, 136 | expectJson: true, 137 | querystring: operations.formatDeleteOpts(opts), 138 | abortSignal: opts.abortSignal, 139 | }); 140 | if (c.isStatusKind(resp)) return MetaV1.toStatus(resp); 141 | return EventsV1.toEvent(resp); 142 | } 143 | 144 | async replaceEvent( 145 | name: string, 146 | body: EventsV1.Event, 147 | opts: operations.PutOpts = {}, 148 | ): Promise { 149 | const resp = await this.#client.performRequest({ 150 | method: "PUT", 151 | path: `${this.#root}events/${name}`, 152 | expectJson: true, 153 | querystring: operations.formatPutOpts(opts), 154 | bodyJson: EventsV1.fromEvent(body), 155 | abortSignal: opts.abortSignal, 156 | }); 157 | return EventsV1.toEvent(resp); 158 | } 159 | 160 | async patchEvent( 161 | name: string, 162 | type: c.PatchType, 163 | body: EventsV1.Event | c.JsonPatch, 164 | opts: operations.PatchOpts = {}, 165 | ): Promise { 166 | const resp = await this.#client.performRequest({ 167 | method: "PATCH", 168 | path: `${this.#root}events/${name}`, 169 | expectJson: true, 170 | querystring: operations.formatPatchOpts(opts), 171 | contentType: c.getPatchContentType(type), 172 | bodyJson: Array.isArray(body) ? body : EventsV1.fromEvent(body), 173 | abortSignal: opts.abortSignal, 174 | }); 175 | return EventsV1.toEvent(resp); 176 | } 177 | 178 | } 179 | -------------------------------------------------------------------------------- /lib/builtin/certificates.k8s.io@v1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for CertificatesV1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** CertificateSigningRequest objects provide a mechanism to obtain x509 certificates by submitting a certificate signing request, and having it asynchronously approved and issued. 11 | 12 | Kubelets use this API to obtain: 13 | 1. client certificates to authenticate to kube-apiserver (with the "kubernetes.io/kube-apiserver-client-kubelet" signerName). 14 | 2. serving certificates for TLS endpoints kube-apiserver can connect to securely (with the "kubernetes.io/kubelet-serving" signerName). 15 | 16 | This API can be used to request client certificates to authenticate to kube-apiserver (with the "kubernetes.io/kube-apiserver-client" signerName), or to obtain certificates from custom non-Kubernetes signers. */ 17 | export interface CertificateSigningRequest { 18 | apiVersion?: "certificates.k8s.io/v1"; 19 | kind?: "CertificateSigningRequest"; 20 | metadata?: MetaV1.ObjectMeta | null; 21 | spec: CertificateSigningRequestSpec; 22 | status?: CertificateSigningRequestStatus | null; 23 | } 24 | export function toCertificateSigningRequest(input: c.JSONValue): CertificateSigningRequest & c.ApiKind { 25 | const obj = c.checkObj(input); 26 | return { 27 | ...c.assertOrAddApiVersionAndKind(obj, "certificates.k8s.io/v1", "CertificateSigningRequest"), 28 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 29 | spec: toCertificateSigningRequestSpec(obj["spec"]), 30 | status: c.readOpt(obj["status"], toCertificateSigningRequestStatus), 31 | }} 32 | export function fromCertificateSigningRequest(input: CertificateSigningRequest): c.JSONValue { 33 | return { 34 | ...c.assertOrAddApiVersionAndKind(input, "certificates.k8s.io/v1", "CertificateSigningRequest"), 35 | ...input, 36 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 37 | spec: input.spec != null ? fromCertificateSigningRequestSpec(input.spec) : undefined, 38 | status: input.status != null ? fromCertificateSigningRequestStatus(input.status) : undefined, 39 | }} 40 | 41 | /** CertificateSigningRequestSpec contains the certificate request. */ 42 | export interface CertificateSigningRequestSpec { 43 | expirationSeconds?: number | null; 44 | extra?: Record> | null; 45 | groups?: Array | null; 46 | request: string; 47 | signerName: string; 48 | uid?: string | null; 49 | usages?: Array | null; 50 | username?: string | null; 51 | } 52 | export function toCertificateSigningRequestSpec(input: c.JSONValue): CertificateSigningRequestSpec { 53 | const obj = c.checkObj(input); 54 | return { 55 | expirationSeconds: c.readOpt(obj["expirationSeconds"], c.checkNum), 56 | extra: c.readOpt(obj["extra"], y => c.readMap(y, x => c.readList(x, c.checkStr))), 57 | groups: c.readOpt(obj["groups"], x => c.readList(x, c.checkStr)), 58 | request: c.checkStr(obj["request"]), 59 | signerName: c.checkStr(obj["signerName"]), 60 | uid: c.readOpt(obj["uid"], c.checkStr), 61 | usages: c.readOpt(obj["usages"], x => c.readList(x, c.checkStr)), 62 | username: c.readOpt(obj["username"], c.checkStr), 63 | }} 64 | export function fromCertificateSigningRequestSpec(input: CertificateSigningRequestSpec): c.JSONValue { 65 | return { 66 | ...input, 67 | }} 68 | 69 | /** CertificateSigningRequestStatus contains conditions used to indicate approved/denied/failed status of the request, and the issued certificate. */ 70 | export interface CertificateSigningRequestStatus { 71 | certificate?: string | null; 72 | conditions?: Array | null; 73 | } 74 | export function toCertificateSigningRequestStatus(input: c.JSONValue): CertificateSigningRequestStatus { 75 | const obj = c.checkObj(input); 76 | return { 77 | certificate: c.readOpt(obj["certificate"], c.checkStr), 78 | conditions: c.readOpt(obj["conditions"], x => c.readList(x, toCertificateSigningRequestCondition)), 79 | }} 80 | export function fromCertificateSigningRequestStatus(input: CertificateSigningRequestStatus): c.JSONValue { 81 | return { 82 | ...input, 83 | conditions: input.conditions?.map(fromCertificateSigningRequestCondition), 84 | }} 85 | 86 | /** CertificateSigningRequestCondition describes a condition of a CertificateSigningRequest object */ 87 | export interface CertificateSigningRequestCondition { 88 | lastTransitionTime?: c.Time | null; 89 | lastUpdateTime?: c.Time | null; 90 | message?: string | null; 91 | reason?: string | null; 92 | status: string; 93 | type: string; 94 | } 95 | export function toCertificateSigningRequestCondition(input: c.JSONValue): CertificateSigningRequestCondition { 96 | const obj = c.checkObj(input); 97 | return { 98 | lastTransitionTime: c.readOpt(obj["lastTransitionTime"], c.toTime), 99 | lastUpdateTime: c.readOpt(obj["lastUpdateTime"], c.toTime), 100 | message: c.readOpt(obj["message"], c.checkStr), 101 | reason: c.readOpt(obj["reason"], c.checkStr), 102 | status: c.checkStr(obj["status"]), 103 | type: c.checkStr(obj["type"]), 104 | }} 105 | export function fromCertificateSigningRequestCondition(input: CertificateSigningRequestCondition): c.JSONValue { 106 | return { 107 | ...input, 108 | lastTransitionTime: input.lastTransitionTime != null ? c.fromTime(input.lastTransitionTime) : undefined, 109 | lastUpdateTime: input.lastUpdateTime != null ? c.fromTime(input.lastUpdateTime) : undefined, 110 | }} 111 | 112 | /** CertificateSigningRequestList is a collection of CertificateSigningRequest objects */ 113 | export interface CertificateSigningRequestList extends ListOf { 114 | apiVersion?: "certificates.k8s.io/v1"; 115 | kind?: "CertificateSigningRequestList"; 116 | }; 117 | export function toCertificateSigningRequestList(input: c.JSONValue): CertificateSigningRequestList & c.ApiKind { 118 | const obj = c.checkObj(input); 119 | return { 120 | ...c.assertOrAddApiVersionAndKind(obj, "certificates.k8s.io/v1", "CertificateSigningRequestList"), 121 | metadata: MetaV1.toListMeta(obj.metadata), 122 | items: c.readList(obj.items, toCertificateSigningRequest), 123 | }} 124 | -------------------------------------------------------------------------------- /lib/builtin/coordination.k8s.io@v1/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./structs.ts"; 2 | 3 | // Autogenerated API file for CoordinationV1 4 | import * as c from "../../common.ts"; 5 | import * as operations from "../../operations.ts"; 6 | import * as MetaV1 from "../meta@v1/structs.ts"; 7 | import * as CoordinationV1 from "./structs.ts"; 8 | 9 | export class CoordinationV1Api { 10 | #client: c.RestClient; 11 | #root = "/apis/coordination.k8s.io/v1/"; 12 | constructor(client: c.RestClient) { 13 | this.#client = client; 14 | } 15 | 16 | namespace(name: string): CoordinationV1NamespacedApi { 17 | return new CoordinationV1NamespacedApi(this.#client, name); 18 | } 19 | myNamespace(): CoordinationV1NamespacedApi { 20 | if (!this.#client.defaultNamespace) throw new Error("No current namespace is set"); 21 | return new CoordinationV1NamespacedApi(this.#client, this.#client.defaultNamespace); 22 | } 23 | 24 | async getLeaseListForAllNamespaces( 25 | opts: operations.GetListOpts = {}, 26 | ): Promise { 27 | const resp = await this.#client.performRequest({ 28 | method: "GET", 29 | path: `${this.#root}leases`, 30 | expectJson: true, 31 | querystring: operations.formatGetListOpts(opts), 32 | abortSignal: opts.abortSignal, 33 | }); 34 | return CoordinationV1.toLeaseList(resp); 35 | } 36 | 37 | async watchLeaseListForAllNamespaces( 38 | opts: operations.WatchListOpts = {}, 39 | ): Promise> { 40 | const resp = await this.#client.performRequest({ 41 | method: "GET", 42 | path: `${this.#root}leases`, 43 | expectJson: true, 44 | expectStream: true, 45 | querystring: operations.formatWatchListOpts(opts), 46 | abortSignal: opts.abortSignal, 47 | }); 48 | return resp.pipeThrough(new c.WatchEventTransformer(CoordinationV1.toLease, MetaV1.toStatus)); 49 | } 50 | 51 | } 52 | 53 | export class CoordinationV1NamespacedApi { 54 | #client: c.RestClient 55 | #root: string 56 | constructor(client: c.RestClient, namespace: string) { 57 | this.#client = client; 58 | this.#root = `/apis/coordination.k8s.io/v1/namespaces/${namespace}/`; 59 | } 60 | 61 | async getLeaseList( 62 | opts: operations.GetListOpts = {}, 63 | ): Promise { 64 | const resp = await this.#client.performRequest({ 65 | method: "GET", 66 | path: `${this.#root}leases`, 67 | expectJson: true, 68 | querystring: operations.formatGetListOpts(opts), 69 | abortSignal: opts.abortSignal, 70 | }); 71 | return CoordinationV1.toLeaseList(resp); 72 | } 73 | 74 | async watchLeaseList( 75 | opts: operations.WatchListOpts = {}, 76 | ): Promise> { 77 | const resp = await this.#client.performRequest({ 78 | method: "GET", 79 | path: `${this.#root}leases`, 80 | expectJson: true, 81 | expectStream: true, 82 | querystring: operations.formatWatchListOpts(opts), 83 | abortSignal: opts.abortSignal, 84 | }); 85 | return resp.pipeThrough(new c.WatchEventTransformer(CoordinationV1.toLease, MetaV1.toStatus)); 86 | } 87 | 88 | async createLease( 89 | body: CoordinationV1.Lease, 90 | opts: operations.PutOpts = {}, 91 | ): Promise { 92 | const resp = await this.#client.performRequest({ 93 | method: "POST", 94 | path: `${this.#root}leases`, 95 | expectJson: true, 96 | querystring: operations.formatPutOpts(opts), 97 | bodyJson: CoordinationV1.fromLease(body), 98 | abortSignal: opts.abortSignal, 99 | }); 100 | return CoordinationV1.toLease(resp); 101 | } 102 | 103 | async deleteLeaseList( 104 | opts: operations.DeleteListOpts = {}, 105 | ): Promise { 106 | const resp = await this.#client.performRequest({ 107 | method: "DELETE", 108 | path: `${this.#root}leases`, 109 | expectJson: true, 110 | querystring: operations.formatDeleteListOpts(opts), 111 | abortSignal: opts.abortSignal, 112 | }); 113 | return CoordinationV1.toLeaseList(resp); 114 | } 115 | 116 | async getLease( 117 | name: string, 118 | opts: operations.NoOpts = {}, 119 | ): Promise { 120 | const resp = await this.#client.performRequest({ 121 | method: "GET", 122 | path: `${this.#root}leases/${name}`, 123 | expectJson: true, 124 | abortSignal: opts.abortSignal, 125 | }); 126 | return CoordinationV1.toLease(resp); 127 | } 128 | 129 | async deleteLease( 130 | name: string, 131 | opts: operations.DeleteOpts = {}, 132 | ): Promise { 133 | const resp = await this.#client.performRequest({ 134 | method: "DELETE", 135 | path: `${this.#root}leases/${name}`, 136 | expectJson: true, 137 | querystring: operations.formatDeleteOpts(opts), 138 | abortSignal: opts.abortSignal, 139 | }); 140 | if (c.isStatusKind(resp)) return MetaV1.toStatus(resp); 141 | return CoordinationV1.toLease(resp); 142 | } 143 | 144 | async replaceLease( 145 | name: string, 146 | body: CoordinationV1.Lease, 147 | opts: operations.PutOpts = {}, 148 | ): Promise { 149 | const resp = await this.#client.performRequest({ 150 | method: "PUT", 151 | path: `${this.#root}leases/${name}`, 152 | expectJson: true, 153 | querystring: operations.formatPutOpts(opts), 154 | bodyJson: CoordinationV1.fromLease(body), 155 | abortSignal: opts.abortSignal, 156 | }); 157 | return CoordinationV1.toLease(resp); 158 | } 159 | 160 | async patchLease( 161 | name: string, 162 | type: c.PatchType, 163 | body: CoordinationV1.Lease | c.JsonPatch, 164 | opts: operations.PatchOpts = {}, 165 | ): Promise { 166 | const resp = await this.#client.performRequest({ 167 | method: "PATCH", 168 | path: `${this.#root}leases/${name}`, 169 | expectJson: true, 170 | querystring: operations.formatPatchOpts(opts), 171 | contentType: c.getPatchContentType(type), 172 | bodyJson: Array.isArray(body) ? body : CoordinationV1.fromLease(body), 173 | abortSignal: opts.abortSignal, 174 | }); 175 | return CoordinationV1.toLease(resp); 176 | } 177 | 178 | } 179 | -------------------------------------------------------------------------------- /lib/builtin/networking.k8s.io@v1beta1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for NetworkingV1beta1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** IPAddress represents a single IP of a single IP Family. The object is designed to be used by APIs that operate on IP addresses. The object is used by the Service core API for allocation of IP addresses. An IP address can be represented in different formats, to guarantee the uniqueness of the IP, the name of the object is the IP address in canonical format, four decimal digits separated by dots suppressing leading zeros for IPv4 and the representation defined by RFC 5952 for IPv6. Valid: 192.168.1.5 or 2001:db8::1 or 2001:db8:aaaa:bbbb:cccc:dddd:eeee:1 Invalid: 10.01.2.3 or 2001:db8:0:0:0::1 */ 11 | export interface IPAddress { 12 | apiVersion?: "networking.k8s.io/v1beta1"; 13 | kind?: "IPAddress"; 14 | metadata?: MetaV1.ObjectMeta | null; 15 | spec?: IPAddressSpec | null; 16 | } 17 | export function toIPAddress(input: c.JSONValue): IPAddress & c.ApiKind { 18 | const obj = c.checkObj(input); 19 | return { 20 | ...c.assertOrAddApiVersionAndKind(obj, "networking.k8s.io/v1beta1", "IPAddress"), 21 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 22 | spec: c.readOpt(obj["spec"], toIPAddressSpec), 23 | }} 24 | export function fromIPAddress(input: IPAddress): c.JSONValue { 25 | return { 26 | ...c.assertOrAddApiVersionAndKind(input, "networking.k8s.io/v1beta1", "IPAddress"), 27 | ...input, 28 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 29 | spec: input.spec != null ? fromIPAddressSpec(input.spec) : undefined, 30 | }} 31 | 32 | /** IPAddressSpec describe the attributes in an IP Address. */ 33 | export interface IPAddressSpec { 34 | parentRef: ParentReference; 35 | } 36 | export function toIPAddressSpec(input: c.JSONValue): IPAddressSpec { 37 | const obj = c.checkObj(input); 38 | return { 39 | parentRef: toParentReference(obj["parentRef"]), 40 | }} 41 | export function fromIPAddressSpec(input: IPAddressSpec): c.JSONValue { 42 | return { 43 | ...input, 44 | parentRef: input.parentRef != null ? fromParentReference(input.parentRef) : undefined, 45 | }} 46 | 47 | /** ParentReference describes a reference to a parent object. */ 48 | export interface ParentReference { 49 | group?: string | null; 50 | name: string; 51 | namespace?: string | null; 52 | resource: string; 53 | } 54 | export function toParentReference(input: c.JSONValue): ParentReference { 55 | const obj = c.checkObj(input); 56 | return { 57 | group: c.readOpt(obj["group"], c.checkStr), 58 | name: c.checkStr(obj["name"]), 59 | namespace: c.readOpt(obj["namespace"], c.checkStr), 60 | resource: c.checkStr(obj["resource"]), 61 | }} 62 | export function fromParentReference(input: ParentReference): c.JSONValue { 63 | return { 64 | ...input, 65 | }} 66 | 67 | /** IPAddressList contains a list of IPAddress. */ 68 | export interface IPAddressList extends ListOf { 69 | apiVersion?: "networking.k8s.io/v1beta1"; 70 | kind?: "IPAddressList"; 71 | }; 72 | export function toIPAddressList(input: c.JSONValue): IPAddressList & c.ApiKind { 73 | const obj = c.checkObj(input); 74 | return { 75 | ...c.assertOrAddApiVersionAndKind(obj, "networking.k8s.io/v1beta1", "IPAddressList"), 76 | metadata: MetaV1.toListMeta(obj.metadata), 77 | items: c.readList(obj.items, toIPAddress), 78 | }} 79 | 80 | /** ServiceCIDR defines a range of IP addresses using CIDR format (e.g. 192.168.0.0/24 or 2001:db2::/64). This range is used to allocate ClusterIPs to Service objects. */ 81 | export interface ServiceCIDR { 82 | apiVersion?: "networking.k8s.io/v1beta1"; 83 | kind?: "ServiceCIDR"; 84 | metadata?: MetaV1.ObjectMeta | null; 85 | spec?: ServiceCIDRSpec | null; 86 | status?: ServiceCIDRStatus | null; 87 | } 88 | export function toServiceCIDR(input: c.JSONValue): ServiceCIDR & c.ApiKind { 89 | const obj = c.checkObj(input); 90 | return { 91 | ...c.assertOrAddApiVersionAndKind(obj, "networking.k8s.io/v1beta1", "ServiceCIDR"), 92 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 93 | spec: c.readOpt(obj["spec"], toServiceCIDRSpec), 94 | status: c.readOpt(obj["status"], toServiceCIDRStatus), 95 | }} 96 | export function fromServiceCIDR(input: ServiceCIDR): c.JSONValue { 97 | return { 98 | ...c.assertOrAddApiVersionAndKind(input, "networking.k8s.io/v1beta1", "ServiceCIDR"), 99 | ...input, 100 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 101 | spec: input.spec != null ? fromServiceCIDRSpec(input.spec) : undefined, 102 | status: input.status != null ? fromServiceCIDRStatus(input.status) : undefined, 103 | }} 104 | 105 | /** ServiceCIDRSpec define the CIDRs the user wants to use for allocating ClusterIPs for Services. */ 106 | export interface ServiceCIDRSpec { 107 | cidrs?: Array | null; 108 | } 109 | export function toServiceCIDRSpec(input: c.JSONValue): ServiceCIDRSpec { 110 | const obj = c.checkObj(input); 111 | return { 112 | cidrs: c.readOpt(obj["cidrs"], x => c.readList(x, c.checkStr)), 113 | }} 114 | export function fromServiceCIDRSpec(input: ServiceCIDRSpec): c.JSONValue { 115 | return { 116 | ...input, 117 | }} 118 | 119 | /** ServiceCIDRStatus describes the current state of the ServiceCIDR. */ 120 | export interface ServiceCIDRStatus { 121 | conditions?: Array | null; 122 | } 123 | export function toServiceCIDRStatus(input: c.JSONValue): ServiceCIDRStatus { 124 | const obj = c.checkObj(input); 125 | return { 126 | conditions: c.readOpt(obj["conditions"], x => c.readList(x, MetaV1.toCondition)), 127 | }} 128 | export function fromServiceCIDRStatus(input: ServiceCIDRStatus): c.JSONValue { 129 | return { 130 | ...input, 131 | conditions: input.conditions?.map(MetaV1.fromCondition), 132 | }} 133 | 134 | /** ServiceCIDRList contains a list of ServiceCIDR objects. */ 135 | export interface ServiceCIDRList extends ListOf { 136 | apiVersion?: "networking.k8s.io/v1beta1"; 137 | kind?: "ServiceCIDRList"; 138 | }; 139 | export function toServiceCIDRList(input: c.JSONValue): ServiceCIDRList & c.ApiKind { 140 | const obj = c.checkObj(input); 141 | return { 142 | ...c.assertOrAddApiVersionAndKind(obj, "networking.k8s.io/v1beta1", "ServiceCIDRList"), 143 | metadata: MetaV1.toListMeta(obj.metadata), 144 | items: c.readList(obj.items, toServiceCIDR), 145 | }} 146 | -------------------------------------------------------------------------------- /lib/builtin/discovery.k8s.io@v1/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./structs.ts"; 2 | 3 | // Autogenerated API file for DiscoveryV1 4 | import * as c from "../../common.ts"; 5 | import * as operations from "../../operations.ts"; 6 | import * as MetaV1 from "../meta@v1/structs.ts"; 7 | import * as DiscoveryV1 from "./structs.ts"; 8 | 9 | export class DiscoveryV1Api { 10 | #client: c.RestClient; 11 | #root = "/apis/discovery.k8s.io/v1/"; 12 | constructor(client: c.RestClient) { 13 | this.#client = client; 14 | } 15 | 16 | namespace(name: string): DiscoveryV1NamespacedApi { 17 | return new DiscoveryV1NamespacedApi(this.#client, name); 18 | } 19 | myNamespace(): DiscoveryV1NamespacedApi { 20 | if (!this.#client.defaultNamespace) throw new Error("No current namespace is set"); 21 | return new DiscoveryV1NamespacedApi(this.#client, this.#client.defaultNamespace); 22 | } 23 | 24 | async getEndpointSliceListForAllNamespaces( 25 | opts: operations.GetListOpts = {}, 26 | ): Promise { 27 | const resp = await this.#client.performRequest({ 28 | method: "GET", 29 | path: `${this.#root}endpointslices`, 30 | expectJson: true, 31 | querystring: operations.formatGetListOpts(opts), 32 | abortSignal: opts.abortSignal, 33 | }); 34 | return DiscoveryV1.toEndpointSliceList(resp); 35 | } 36 | 37 | async watchEndpointSliceListForAllNamespaces( 38 | opts: operations.WatchListOpts = {}, 39 | ): Promise> { 40 | const resp = await this.#client.performRequest({ 41 | method: "GET", 42 | path: `${this.#root}endpointslices`, 43 | expectJson: true, 44 | expectStream: true, 45 | querystring: operations.formatWatchListOpts(opts), 46 | abortSignal: opts.abortSignal, 47 | }); 48 | return resp.pipeThrough(new c.WatchEventTransformer(DiscoveryV1.toEndpointSlice, MetaV1.toStatus)); 49 | } 50 | 51 | } 52 | 53 | export class DiscoveryV1NamespacedApi { 54 | #client: c.RestClient 55 | #root: string 56 | constructor(client: c.RestClient, namespace: string) { 57 | this.#client = client; 58 | this.#root = `/apis/discovery.k8s.io/v1/namespaces/${namespace}/`; 59 | } 60 | 61 | async getEndpointSliceList( 62 | opts: operations.GetListOpts = {}, 63 | ): Promise { 64 | const resp = await this.#client.performRequest({ 65 | method: "GET", 66 | path: `${this.#root}endpointslices`, 67 | expectJson: true, 68 | querystring: operations.formatGetListOpts(opts), 69 | abortSignal: opts.abortSignal, 70 | }); 71 | return DiscoveryV1.toEndpointSliceList(resp); 72 | } 73 | 74 | async watchEndpointSliceList( 75 | opts: operations.WatchListOpts = {}, 76 | ): Promise> { 77 | const resp = await this.#client.performRequest({ 78 | method: "GET", 79 | path: `${this.#root}endpointslices`, 80 | expectJson: true, 81 | expectStream: true, 82 | querystring: operations.formatWatchListOpts(opts), 83 | abortSignal: opts.abortSignal, 84 | }); 85 | return resp.pipeThrough(new c.WatchEventTransformer(DiscoveryV1.toEndpointSlice, MetaV1.toStatus)); 86 | } 87 | 88 | async createEndpointSlice( 89 | body: DiscoveryV1.EndpointSlice, 90 | opts: operations.PutOpts = {}, 91 | ): Promise { 92 | const resp = await this.#client.performRequest({ 93 | method: "POST", 94 | path: `${this.#root}endpointslices`, 95 | expectJson: true, 96 | querystring: operations.formatPutOpts(opts), 97 | bodyJson: DiscoveryV1.fromEndpointSlice(body), 98 | abortSignal: opts.abortSignal, 99 | }); 100 | return DiscoveryV1.toEndpointSlice(resp); 101 | } 102 | 103 | async deleteEndpointSliceList( 104 | opts: operations.DeleteListOpts = {}, 105 | ): Promise { 106 | const resp = await this.#client.performRequest({ 107 | method: "DELETE", 108 | path: `${this.#root}endpointslices`, 109 | expectJson: true, 110 | querystring: operations.formatDeleteListOpts(opts), 111 | abortSignal: opts.abortSignal, 112 | }); 113 | return DiscoveryV1.toEndpointSliceList(resp); 114 | } 115 | 116 | async getEndpointSlice( 117 | name: string, 118 | opts: operations.NoOpts = {}, 119 | ): Promise { 120 | const resp = await this.#client.performRequest({ 121 | method: "GET", 122 | path: `${this.#root}endpointslices/${name}`, 123 | expectJson: true, 124 | abortSignal: opts.abortSignal, 125 | }); 126 | return DiscoveryV1.toEndpointSlice(resp); 127 | } 128 | 129 | async deleteEndpointSlice( 130 | name: string, 131 | opts: operations.DeleteOpts = {}, 132 | ): Promise { 133 | const resp = await this.#client.performRequest({ 134 | method: "DELETE", 135 | path: `${this.#root}endpointslices/${name}`, 136 | expectJson: true, 137 | querystring: operations.formatDeleteOpts(opts), 138 | abortSignal: opts.abortSignal, 139 | }); 140 | if (c.isStatusKind(resp)) return MetaV1.toStatus(resp); 141 | return DiscoveryV1.toEndpointSlice(resp); 142 | } 143 | 144 | async replaceEndpointSlice( 145 | name: string, 146 | body: DiscoveryV1.EndpointSlice, 147 | opts: operations.PutOpts = {}, 148 | ): Promise { 149 | const resp = await this.#client.performRequest({ 150 | method: "PUT", 151 | path: `${this.#root}endpointslices/${name}`, 152 | expectJson: true, 153 | querystring: operations.formatPutOpts(opts), 154 | bodyJson: DiscoveryV1.fromEndpointSlice(body), 155 | abortSignal: opts.abortSignal, 156 | }); 157 | return DiscoveryV1.toEndpointSlice(resp); 158 | } 159 | 160 | async patchEndpointSlice( 161 | name: string, 162 | type: c.PatchType, 163 | body: DiscoveryV1.EndpointSlice | c.JsonPatch, 164 | opts: operations.PatchOpts = {}, 165 | ): Promise { 166 | const resp = await this.#client.performRequest({ 167 | method: "PATCH", 168 | path: `${this.#root}endpointslices/${name}`, 169 | expectJson: true, 170 | querystring: operations.formatPatchOpts(opts), 171 | contentType: c.getPatchContentType(type), 172 | bodyJson: Array.isArray(body) ? body : DiscoveryV1.fromEndpointSlice(body), 173 | abortSignal: opts.abortSignal, 174 | }); 175 | return DiscoveryV1.toEndpointSlice(resp); 176 | } 177 | 178 | } 179 | -------------------------------------------------------------------------------- /lib/builtin/apiregistration.k8s.io@v1/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./structs.ts"; 2 | 3 | // Autogenerated API file for ApiregistrationV1 4 | import * as c from "../../common.ts"; 5 | import * as operations from "../../operations.ts"; 6 | import * as MetaV1 from "../meta@v1/structs.ts"; 7 | import * as ApiregistrationV1 from "./structs.ts"; 8 | 9 | export class ApiregistrationV1Api { 10 | #client: c.RestClient; 11 | #root = "/apis/apiregistration.k8s.io/v1/"; 12 | constructor(client: c.RestClient) { 13 | this.#client = client; 14 | } 15 | 16 | async getAPIServiceList( 17 | opts: operations.GetListOpts = {}, 18 | ): Promise { 19 | const resp = await this.#client.performRequest({ 20 | method: "GET", 21 | path: `${this.#root}apiservices`, 22 | expectJson: true, 23 | querystring: operations.formatGetListOpts(opts), 24 | abortSignal: opts.abortSignal, 25 | }); 26 | return ApiregistrationV1.toAPIServiceList(resp); 27 | } 28 | 29 | async watchAPIServiceList( 30 | opts: operations.WatchListOpts = {}, 31 | ): Promise> { 32 | const resp = await this.#client.performRequest({ 33 | method: "GET", 34 | path: `${this.#root}apiservices`, 35 | expectJson: true, 36 | expectStream: true, 37 | querystring: operations.formatWatchListOpts(opts), 38 | abortSignal: opts.abortSignal, 39 | }); 40 | return resp.pipeThrough(new c.WatchEventTransformer(ApiregistrationV1.toAPIService, MetaV1.toStatus)); 41 | } 42 | 43 | async createAPIService( 44 | body: ApiregistrationV1.APIService, 45 | opts: operations.PutOpts = {}, 46 | ): Promise { 47 | const resp = await this.#client.performRequest({ 48 | method: "POST", 49 | path: `${this.#root}apiservices`, 50 | expectJson: true, 51 | querystring: operations.formatPutOpts(opts), 52 | bodyJson: ApiregistrationV1.fromAPIService(body), 53 | abortSignal: opts.abortSignal, 54 | }); 55 | return ApiregistrationV1.toAPIService(resp); 56 | } 57 | 58 | async deleteAPIServiceList( 59 | opts: operations.DeleteListOpts = {}, 60 | ): Promise { 61 | const resp = await this.#client.performRequest({ 62 | method: "DELETE", 63 | path: `${this.#root}apiservices`, 64 | expectJson: true, 65 | querystring: operations.formatDeleteListOpts(opts), 66 | abortSignal: opts.abortSignal, 67 | }); 68 | return ApiregistrationV1.toAPIServiceList(resp); 69 | } 70 | 71 | async getAPIService( 72 | name: string, 73 | opts: operations.NoOpts = {}, 74 | ): Promise { 75 | const resp = await this.#client.performRequest({ 76 | method: "GET", 77 | path: `${this.#root}apiservices/${name}`, 78 | expectJson: true, 79 | abortSignal: opts.abortSignal, 80 | }); 81 | return ApiregistrationV1.toAPIService(resp); 82 | } 83 | 84 | async deleteAPIService( 85 | name: string, 86 | opts: operations.DeleteOpts = {}, 87 | ): Promise { 88 | const resp = await this.#client.performRequest({ 89 | method: "DELETE", 90 | path: `${this.#root}apiservices/${name}`, 91 | expectJson: true, 92 | querystring: operations.formatDeleteOpts(opts), 93 | abortSignal: opts.abortSignal, 94 | }); 95 | if (c.isStatusKind(resp)) return MetaV1.toStatus(resp); 96 | return ApiregistrationV1.toAPIService(resp); 97 | } 98 | 99 | async replaceAPIService( 100 | name: string, 101 | body: ApiregistrationV1.APIService, 102 | opts: operations.PutOpts = {}, 103 | ): Promise { 104 | const resp = await this.#client.performRequest({ 105 | method: "PUT", 106 | path: `${this.#root}apiservices/${name}`, 107 | expectJson: true, 108 | querystring: operations.formatPutOpts(opts), 109 | bodyJson: ApiregistrationV1.fromAPIService(body), 110 | abortSignal: opts.abortSignal, 111 | }); 112 | return ApiregistrationV1.toAPIService(resp); 113 | } 114 | 115 | async patchAPIService( 116 | name: string, 117 | type: c.PatchType, 118 | body: ApiregistrationV1.APIService | c.JsonPatch, 119 | opts: operations.PatchOpts = {}, 120 | ): Promise { 121 | const resp = await this.#client.performRequest({ 122 | method: "PATCH", 123 | path: `${this.#root}apiservices/${name}`, 124 | expectJson: true, 125 | querystring: operations.formatPatchOpts(opts), 126 | contentType: c.getPatchContentType(type), 127 | bodyJson: Array.isArray(body) ? body : ApiregistrationV1.fromAPIService(body), 128 | abortSignal: opts.abortSignal, 129 | }); 130 | return ApiregistrationV1.toAPIService(resp); 131 | } 132 | 133 | async getAPIServiceStatus( 134 | name: string, 135 | opts: operations.NoOpts = {}, 136 | ): Promise { 137 | const resp = await this.#client.performRequest({ 138 | method: "GET", 139 | path: `${this.#root}apiservices/${name}/status`, 140 | expectJson: true, 141 | abortSignal: opts.abortSignal, 142 | }); 143 | return ApiregistrationV1.toAPIService(resp); 144 | } 145 | 146 | async replaceAPIServiceStatus( 147 | name: string, 148 | body: ApiregistrationV1.APIService, 149 | opts: operations.PutOpts = {}, 150 | ): Promise { 151 | const resp = await this.#client.performRequest({ 152 | method: "PUT", 153 | path: `${this.#root}apiservices/${name}/status`, 154 | expectJson: true, 155 | querystring: operations.formatPutOpts(opts), 156 | bodyJson: ApiregistrationV1.fromAPIService(body), 157 | abortSignal: opts.abortSignal, 158 | }); 159 | return ApiregistrationV1.toAPIService(resp); 160 | } 161 | 162 | async patchAPIServiceStatus( 163 | name: string, 164 | type: c.PatchType, 165 | body: ApiregistrationV1.APIService | c.JsonPatch, 166 | opts: operations.PatchOpts = {}, 167 | ): Promise { 168 | const resp = await this.#client.performRequest({ 169 | method: "PATCH", 170 | path: `${this.#root}apiservices/${name}/status`, 171 | expectJson: true, 172 | querystring: operations.formatPatchOpts(opts), 173 | contentType: c.getPatchContentType(type), 174 | bodyJson: Array.isArray(body) ? body : ApiregistrationV1.fromAPIService(body), 175 | abortSignal: opts.abortSignal, 176 | }); 177 | return ApiregistrationV1.toAPIService(resp); 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /lib/builtin/coordination.k8s.io@v1beta1/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./structs.ts"; 2 | 3 | // Autogenerated API file for CoordinationV1beta1 4 | import * as c from "../../common.ts"; 5 | import * as operations from "../../operations.ts"; 6 | import * as MetaV1 from "../meta@v1/structs.ts"; 7 | import * as CoordinationV1beta1 from "./structs.ts"; 8 | 9 | export class CoordinationV1beta1Api { 10 | #client: c.RestClient; 11 | #root = "/apis/coordination.k8s.io/v1beta1/"; 12 | constructor(client: c.RestClient) { 13 | this.#client = client; 14 | } 15 | 16 | namespace(name: string): CoordinationV1beta1NamespacedApi { 17 | return new CoordinationV1beta1NamespacedApi(this.#client, name); 18 | } 19 | myNamespace(): CoordinationV1beta1NamespacedApi { 20 | if (!this.#client.defaultNamespace) throw new Error("No current namespace is set"); 21 | return new CoordinationV1beta1NamespacedApi(this.#client, this.#client.defaultNamespace); 22 | } 23 | 24 | async getLeaseCandidateListForAllNamespaces( 25 | opts: operations.GetListOpts = {}, 26 | ): Promise { 27 | const resp = await this.#client.performRequest({ 28 | method: "GET", 29 | path: `${this.#root}leasecandidates`, 30 | expectJson: true, 31 | querystring: operations.formatGetListOpts(opts), 32 | abortSignal: opts.abortSignal, 33 | }); 34 | return CoordinationV1beta1.toLeaseCandidateList(resp); 35 | } 36 | 37 | async watchLeaseCandidateListForAllNamespaces( 38 | opts: operations.WatchListOpts = {}, 39 | ): Promise> { 40 | const resp = await this.#client.performRequest({ 41 | method: "GET", 42 | path: `${this.#root}leasecandidates`, 43 | expectJson: true, 44 | expectStream: true, 45 | querystring: operations.formatWatchListOpts(opts), 46 | abortSignal: opts.abortSignal, 47 | }); 48 | return resp.pipeThrough(new c.WatchEventTransformer(CoordinationV1beta1.toLeaseCandidate, MetaV1.toStatus)); 49 | } 50 | 51 | } 52 | 53 | export class CoordinationV1beta1NamespacedApi { 54 | #client: c.RestClient 55 | #root: string 56 | constructor(client: c.RestClient, namespace: string) { 57 | this.#client = client; 58 | this.#root = `/apis/coordination.k8s.io/v1beta1/namespaces/${namespace}/`; 59 | } 60 | 61 | async getLeaseCandidateList( 62 | opts: operations.GetListOpts = {}, 63 | ): Promise { 64 | const resp = await this.#client.performRequest({ 65 | method: "GET", 66 | path: `${this.#root}leasecandidates`, 67 | expectJson: true, 68 | querystring: operations.formatGetListOpts(opts), 69 | abortSignal: opts.abortSignal, 70 | }); 71 | return CoordinationV1beta1.toLeaseCandidateList(resp); 72 | } 73 | 74 | async watchLeaseCandidateList( 75 | opts: operations.WatchListOpts = {}, 76 | ): Promise> { 77 | const resp = await this.#client.performRequest({ 78 | method: "GET", 79 | path: `${this.#root}leasecandidates`, 80 | expectJson: true, 81 | expectStream: true, 82 | querystring: operations.formatWatchListOpts(opts), 83 | abortSignal: opts.abortSignal, 84 | }); 85 | return resp.pipeThrough(new c.WatchEventTransformer(CoordinationV1beta1.toLeaseCandidate, MetaV1.toStatus)); 86 | } 87 | 88 | async createLeaseCandidate( 89 | body: CoordinationV1beta1.LeaseCandidate, 90 | opts: operations.PutOpts = {}, 91 | ): Promise { 92 | const resp = await this.#client.performRequest({ 93 | method: "POST", 94 | path: `${this.#root}leasecandidates`, 95 | expectJson: true, 96 | querystring: operations.formatPutOpts(opts), 97 | bodyJson: CoordinationV1beta1.fromLeaseCandidate(body), 98 | abortSignal: opts.abortSignal, 99 | }); 100 | return CoordinationV1beta1.toLeaseCandidate(resp); 101 | } 102 | 103 | async deleteLeaseCandidateList( 104 | opts: operations.DeleteListOpts = {}, 105 | ): Promise { 106 | const resp = await this.#client.performRequest({ 107 | method: "DELETE", 108 | path: `${this.#root}leasecandidates`, 109 | expectJson: true, 110 | querystring: operations.formatDeleteListOpts(opts), 111 | abortSignal: opts.abortSignal, 112 | }); 113 | return CoordinationV1beta1.toLeaseCandidateList(resp); 114 | } 115 | 116 | async getLeaseCandidate( 117 | name: string, 118 | opts: operations.NoOpts = {}, 119 | ): Promise { 120 | const resp = await this.#client.performRequest({ 121 | method: "GET", 122 | path: `${this.#root}leasecandidates/${name}`, 123 | expectJson: true, 124 | abortSignal: opts.abortSignal, 125 | }); 126 | return CoordinationV1beta1.toLeaseCandidate(resp); 127 | } 128 | 129 | async deleteLeaseCandidate( 130 | name: string, 131 | opts: operations.DeleteOpts = {}, 132 | ): Promise { 133 | const resp = await this.#client.performRequest({ 134 | method: "DELETE", 135 | path: `${this.#root}leasecandidates/${name}`, 136 | expectJson: true, 137 | querystring: operations.formatDeleteOpts(opts), 138 | abortSignal: opts.abortSignal, 139 | }); 140 | if (c.isStatusKind(resp)) return MetaV1.toStatus(resp); 141 | return CoordinationV1beta1.toLeaseCandidate(resp); 142 | } 143 | 144 | async replaceLeaseCandidate( 145 | name: string, 146 | body: CoordinationV1beta1.LeaseCandidate, 147 | opts: operations.PutOpts = {}, 148 | ): Promise { 149 | const resp = await this.#client.performRequest({ 150 | method: "PUT", 151 | path: `${this.#root}leasecandidates/${name}`, 152 | expectJson: true, 153 | querystring: operations.formatPutOpts(opts), 154 | bodyJson: CoordinationV1beta1.fromLeaseCandidate(body), 155 | abortSignal: opts.abortSignal, 156 | }); 157 | return CoordinationV1beta1.toLeaseCandidate(resp); 158 | } 159 | 160 | async patchLeaseCandidate( 161 | name: string, 162 | type: c.PatchType, 163 | body: CoordinationV1beta1.LeaseCandidate | c.JsonPatch, 164 | opts: operations.PatchOpts = {}, 165 | ): Promise { 166 | const resp = await this.#client.performRequest({ 167 | method: "PATCH", 168 | path: `${this.#root}leasecandidates/${name}`, 169 | expectJson: true, 170 | querystring: operations.formatPatchOpts(opts), 171 | contentType: c.getPatchContentType(type), 172 | bodyJson: Array.isArray(body) ? body : CoordinationV1beta1.fromLeaseCandidate(body), 173 | abortSignal: opts.abortSignal, 174 | }); 175 | return CoordinationV1beta1.toLeaseCandidate(resp); 176 | } 177 | 178 | } 179 | -------------------------------------------------------------------------------- /lib/builtin/coordination.k8s.io@v1alpha2/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./structs.ts"; 2 | 3 | // Autogenerated API file for CoordinationV1alpha2 4 | import * as c from "../../common.ts"; 5 | import * as operations from "../../operations.ts"; 6 | import * as MetaV1 from "../meta@v1/structs.ts"; 7 | import * as CoordinationV1alpha2 from "./structs.ts"; 8 | 9 | export class CoordinationV1alpha2Api { 10 | #client: c.RestClient; 11 | #root = "/apis/coordination.k8s.io/v1alpha2/"; 12 | constructor(client: c.RestClient) { 13 | this.#client = client; 14 | } 15 | 16 | namespace(name: string): CoordinationV1alpha2NamespacedApi { 17 | return new CoordinationV1alpha2NamespacedApi(this.#client, name); 18 | } 19 | myNamespace(): CoordinationV1alpha2NamespacedApi { 20 | if (!this.#client.defaultNamespace) throw new Error("No current namespace is set"); 21 | return new CoordinationV1alpha2NamespacedApi(this.#client, this.#client.defaultNamespace); 22 | } 23 | 24 | async getLeaseCandidateListForAllNamespaces( 25 | opts: operations.GetListOpts = {}, 26 | ): Promise { 27 | const resp = await this.#client.performRequest({ 28 | method: "GET", 29 | path: `${this.#root}leasecandidates`, 30 | expectJson: true, 31 | querystring: operations.formatGetListOpts(opts), 32 | abortSignal: opts.abortSignal, 33 | }); 34 | return CoordinationV1alpha2.toLeaseCandidateList(resp); 35 | } 36 | 37 | async watchLeaseCandidateListForAllNamespaces( 38 | opts: operations.WatchListOpts = {}, 39 | ): Promise> { 40 | const resp = await this.#client.performRequest({ 41 | method: "GET", 42 | path: `${this.#root}leasecandidates`, 43 | expectJson: true, 44 | expectStream: true, 45 | querystring: operations.formatWatchListOpts(opts), 46 | abortSignal: opts.abortSignal, 47 | }); 48 | return resp.pipeThrough(new c.WatchEventTransformer(CoordinationV1alpha2.toLeaseCandidate, MetaV1.toStatus)); 49 | } 50 | 51 | } 52 | 53 | export class CoordinationV1alpha2NamespacedApi { 54 | #client: c.RestClient 55 | #root: string 56 | constructor(client: c.RestClient, namespace: string) { 57 | this.#client = client; 58 | this.#root = `/apis/coordination.k8s.io/v1alpha2/namespaces/${namespace}/`; 59 | } 60 | 61 | async getLeaseCandidateList( 62 | opts: operations.GetListOpts = {}, 63 | ): Promise { 64 | const resp = await this.#client.performRequest({ 65 | method: "GET", 66 | path: `${this.#root}leasecandidates`, 67 | expectJson: true, 68 | querystring: operations.formatGetListOpts(opts), 69 | abortSignal: opts.abortSignal, 70 | }); 71 | return CoordinationV1alpha2.toLeaseCandidateList(resp); 72 | } 73 | 74 | async watchLeaseCandidateList( 75 | opts: operations.WatchListOpts = {}, 76 | ): Promise> { 77 | const resp = await this.#client.performRequest({ 78 | method: "GET", 79 | path: `${this.#root}leasecandidates`, 80 | expectJson: true, 81 | expectStream: true, 82 | querystring: operations.formatWatchListOpts(opts), 83 | abortSignal: opts.abortSignal, 84 | }); 85 | return resp.pipeThrough(new c.WatchEventTransformer(CoordinationV1alpha2.toLeaseCandidate, MetaV1.toStatus)); 86 | } 87 | 88 | async createLeaseCandidate( 89 | body: CoordinationV1alpha2.LeaseCandidate, 90 | opts: operations.PutOpts = {}, 91 | ): Promise { 92 | const resp = await this.#client.performRequest({ 93 | method: "POST", 94 | path: `${this.#root}leasecandidates`, 95 | expectJson: true, 96 | querystring: operations.formatPutOpts(opts), 97 | bodyJson: CoordinationV1alpha2.fromLeaseCandidate(body), 98 | abortSignal: opts.abortSignal, 99 | }); 100 | return CoordinationV1alpha2.toLeaseCandidate(resp); 101 | } 102 | 103 | async deleteLeaseCandidateList( 104 | opts: operations.DeleteListOpts = {}, 105 | ): Promise { 106 | const resp = await this.#client.performRequest({ 107 | method: "DELETE", 108 | path: `${this.#root}leasecandidates`, 109 | expectJson: true, 110 | querystring: operations.formatDeleteListOpts(opts), 111 | abortSignal: opts.abortSignal, 112 | }); 113 | return CoordinationV1alpha2.toLeaseCandidateList(resp); 114 | } 115 | 116 | async getLeaseCandidate( 117 | name: string, 118 | opts: operations.NoOpts = {}, 119 | ): Promise { 120 | const resp = await this.#client.performRequest({ 121 | method: "GET", 122 | path: `${this.#root}leasecandidates/${name}`, 123 | expectJson: true, 124 | abortSignal: opts.abortSignal, 125 | }); 126 | return CoordinationV1alpha2.toLeaseCandidate(resp); 127 | } 128 | 129 | async deleteLeaseCandidate( 130 | name: string, 131 | opts: operations.DeleteOpts = {}, 132 | ): Promise { 133 | const resp = await this.#client.performRequest({ 134 | method: "DELETE", 135 | path: `${this.#root}leasecandidates/${name}`, 136 | expectJson: true, 137 | querystring: operations.formatDeleteOpts(opts), 138 | abortSignal: opts.abortSignal, 139 | }); 140 | if (c.isStatusKind(resp)) return MetaV1.toStatus(resp); 141 | return CoordinationV1alpha2.toLeaseCandidate(resp); 142 | } 143 | 144 | async replaceLeaseCandidate( 145 | name: string, 146 | body: CoordinationV1alpha2.LeaseCandidate, 147 | opts: operations.PutOpts = {}, 148 | ): Promise { 149 | const resp = await this.#client.performRequest({ 150 | method: "PUT", 151 | path: `${this.#root}leasecandidates/${name}`, 152 | expectJson: true, 153 | querystring: operations.formatPutOpts(opts), 154 | bodyJson: CoordinationV1alpha2.fromLeaseCandidate(body), 155 | abortSignal: opts.abortSignal, 156 | }); 157 | return CoordinationV1alpha2.toLeaseCandidate(resp); 158 | } 159 | 160 | async patchLeaseCandidate( 161 | name: string, 162 | type: c.PatchType, 163 | body: CoordinationV1alpha2.LeaseCandidate | c.JsonPatch, 164 | opts: operations.PatchOpts = {}, 165 | ): Promise { 166 | const resp = await this.#client.performRequest({ 167 | method: "PATCH", 168 | path: `${this.#root}leasecandidates/${name}`, 169 | expectJson: true, 170 | querystring: operations.formatPatchOpts(opts), 171 | contentType: c.getPatchContentType(type), 172 | bodyJson: Array.isArray(body) ? body : CoordinationV1alpha2.fromLeaseCandidate(body), 173 | abortSignal: opts.abortSignal, 174 | }); 175 | return CoordinationV1alpha2.toLeaseCandidate(resp); 176 | } 177 | 178 | } 179 | -------------------------------------------------------------------------------- /lib/builtin/discovery.k8s.io@v1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for DiscoveryV1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as CoreV1 from "../core@v1/structs.ts"; 5 | import * as MetaV1 from "../meta@v1/structs.ts"; 6 | type ListOf = { 7 | metadata: MetaV1.ListMeta; 8 | items: Array; 9 | }; 10 | 11 | /** Endpoint represents a single logical "backend" implementing a service. */ 12 | export interface Endpoint { 13 | addresses: Array; 14 | conditions?: EndpointConditions | null; 15 | deprecatedTopology?: Record | null; 16 | hints?: EndpointHints | null; 17 | hostname?: string | null; 18 | nodeName?: string | null; 19 | targetRef?: CoreV1.ObjectReference | null; 20 | zone?: string | null; 21 | } 22 | export function toEndpoint(input: c.JSONValue): Endpoint { 23 | const obj = c.checkObj(input); 24 | return { 25 | addresses: c.readList(obj["addresses"], c.checkStr), 26 | conditions: c.readOpt(obj["conditions"], toEndpointConditions), 27 | deprecatedTopology: c.readOpt(obj["deprecatedTopology"], x => c.readMap(x, c.checkStr)), 28 | hints: c.readOpt(obj["hints"], toEndpointHints), 29 | hostname: c.readOpt(obj["hostname"], c.checkStr), 30 | nodeName: c.readOpt(obj["nodeName"], c.checkStr), 31 | targetRef: c.readOpt(obj["targetRef"], CoreV1.toObjectReference), 32 | zone: c.readOpt(obj["zone"], c.checkStr), 33 | }} 34 | export function fromEndpoint(input: Endpoint): c.JSONValue { 35 | return { 36 | ...input, 37 | conditions: input.conditions != null ? fromEndpointConditions(input.conditions) : undefined, 38 | hints: input.hints != null ? fromEndpointHints(input.hints) : undefined, 39 | targetRef: input.targetRef != null ? CoreV1.fromObjectReference(input.targetRef) : undefined, 40 | }} 41 | 42 | /** EndpointConditions represents the current condition of an endpoint. */ 43 | export interface EndpointConditions { 44 | ready?: boolean | null; 45 | serving?: boolean | null; 46 | terminating?: boolean | null; 47 | } 48 | export function toEndpointConditions(input: c.JSONValue): EndpointConditions { 49 | const obj = c.checkObj(input); 50 | return { 51 | ready: c.readOpt(obj["ready"], c.checkBool), 52 | serving: c.readOpt(obj["serving"], c.checkBool), 53 | terminating: c.readOpt(obj["terminating"], c.checkBool), 54 | }} 55 | export function fromEndpointConditions(input: EndpointConditions): c.JSONValue { 56 | return { 57 | ...input, 58 | }} 59 | 60 | /** EndpointHints provides hints describing how an endpoint should be consumed. */ 61 | export interface EndpointHints { 62 | forNodes?: Array | null; 63 | forZones?: Array | null; 64 | } 65 | export function toEndpointHints(input: c.JSONValue): EndpointHints { 66 | const obj = c.checkObj(input); 67 | return { 68 | forNodes: c.readOpt(obj["forNodes"], x => c.readList(x, toForNode)), 69 | forZones: c.readOpt(obj["forZones"], x => c.readList(x, toForZone)), 70 | }} 71 | export function fromEndpointHints(input: EndpointHints): c.JSONValue { 72 | return { 73 | ...input, 74 | forNodes: input.forNodes?.map(fromForNode), 75 | forZones: input.forZones?.map(fromForZone), 76 | }} 77 | 78 | /** ForNode provides information about which nodes should consume this endpoint. */ 79 | export interface ForNode { 80 | name: string; 81 | } 82 | export function toForNode(input: c.JSONValue): ForNode { 83 | const obj = c.checkObj(input); 84 | return { 85 | name: c.checkStr(obj["name"]), 86 | }} 87 | export function fromForNode(input: ForNode): c.JSONValue { 88 | return { 89 | ...input, 90 | }} 91 | 92 | /** ForZone provides information about which zones should consume this endpoint. */ 93 | export interface ForZone { 94 | name: string; 95 | } 96 | export function toForZone(input: c.JSONValue): ForZone { 97 | const obj = c.checkObj(input); 98 | return { 99 | name: c.checkStr(obj["name"]), 100 | }} 101 | export function fromForZone(input: ForZone): c.JSONValue { 102 | return { 103 | ...input, 104 | }} 105 | 106 | /** EndpointPort represents a Port used by an EndpointSlice */ 107 | export interface EndpointPort { 108 | appProtocol?: string | null; 109 | name?: string | null; 110 | port?: number | null; 111 | protocol?: string | null; 112 | } 113 | export function toEndpointPort(input: c.JSONValue): EndpointPort { 114 | const obj = c.checkObj(input); 115 | return { 116 | appProtocol: c.readOpt(obj["appProtocol"], c.checkStr), 117 | name: c.readOpt(obj["name"], c.checkStr), 118 | port: c.readOpt(obj["port"], c.checkNum), 119 | protocol: c.readOpt(obj["protocol"], c.checkStr), 120 | }} 121 | export function fromEndpointPort(input: EndpointPort): c.JSONValue { 122 | return { 123 | ...input, 124 | }} 125 | 126 | /** EndpointSlice represents a set of service endpoints. Most EndpointSlices are created by the EndpointSlice controller to represent the Pods selected by Service objects. For a given service there may be multiple EndpointSlice objects which must be joined to produce the full set of endpoints; you can find all of the slices for a given service by listing EndpointSlices in the service's namespace whose `kubernetes.io/service-name` label contains the service's name. */ 127 | export interface EndpointSlice { 128 | apiVersion?: "discovery.k8s.io/v1"; 129 | kind?: "EndpointSlice"; 130 | addressType: string; 131 | endpoints: Array; 132 | metadata?: MetaV1.ObjectMeta | null; 133 | ports?: Array | null; 134 | } 135 | export function toEndpointSlice(input: c.JSONValue): EndpointSlice & c.ApiKind { 136 | const obj = c.checkObj(input); 137 | return { 138 | ...c.assertOrAddApiVersionAndKind(obj, "discovery.k8s.io/v1", "EndpointSlice"), 139 | addressType: c.checkStr(obj["addressType"]), 140 | endpoints: c.readList(obj["endpoints"], toEndpoint), 141 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 142 | ports: c.readOpt(obj["ports"], x => c.readList(x, toEndpointPort)), 143 | }} 144 | export function fromEndpointSlice(input: EndpointSlice): c.JSONValue { 145 | return { 146 | ...c.assertOrAddApiVersionAndKind(input, "discovery.k8s.io/v1", "EndpointSlice"), 147 | ...input, 148 | endpoints: input.endpoints?.map(fromEndpoint), 149 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 150 | ports: input.ports?.map(fromEndpointPort), 151 | }} 152 | 153 | /** EndpointSliceList represents a list of endpoint slices */ 154 | export interface EndpointSliceList extends ListOf { 155 | apiVersion?: "discovery.k8s.io/v1"; 156 | kind?: "EndpointSliceList"; 157 | }; 158 | export function toEndpointSliceList(input: c.JSONValue): EndpointSliceList & c.ApiKind { 159 | const obj = c.checkObj(input); 160 | return { 161 | ...c.assertOrAddApiVersionAndKind(obj, "discovery.k8s.io/v1", "EndpointSliceList"), 162 | metadata: MetaV1.toListMeta(obj.metadata), 163 | items: c.readList(obj.items, toEndpointSlice), 164 | }} 165 | -------------------------------------------------------------------------------- /lib/builtin/autoscaling@v1/structs.ts: -------------------------------------------------------------------------------- 1 | // Autogenerated Schema file for AutoscalingV1 2 | import * as c from "../../common.ts"; 3 | 4 | import * as MetaV1 from "../meta@v1/structs.ts"; 5 | type ListOf = { 6 | metadata: MetaV1.ListMeta; 7 | items: Array; 8 | }; 9 | 10 | /** CrossVersionObjectReference contains enough information to let you identify the referred resource. */ 11 | export interface CrossVersionObjectReference { 12 | apiVersion?: string | null; 13 | kind: string; 14 | name: string; 15 | } 16 | export function toCrossVersionObjectReference(input: c.JSONValue): CrossVersionObjectReference { 17 | const obj = c.checkObj(input); 18 | return { 19 | apiVersion: c.readOpt(obj["apiVersion"], c.checkStr), 20 | kind: c.checkStr(obj["kind"]), 21 | name: c.checkStr(obj["name"]), 22 | }} 23 | export function fromCrossVersionObjectReference(input: CrossVersionObjectReference): c.JSONValue { 24 | return { 25 | ...input, 26 | }} 27 | 28 | /** configuration of a horizontal pod autoscaler. */ 29 | export interface HorizontalPodAutoscaler { 30 | apiVersion?: "autoscaling/v1"; 31 | kind?: "HorizontalPodAutoscaler"; 32 | metadata?: MetaV1.ObjectMeta | null; 33 | spec?: HorizontalPodAutoscalerSpec | null; 34 | status?: HorizontalPodAutoscalerStatus | null; 35 | } 36 | export function toHorizontalPodAutoscaler(input: c.JSONValue): HorizontalPodAutoscaler & c.ApiKind { 37 | const obj = c.checkObj(input); 38 | return { 39 | ...c.assertOrAddApiVersionAndKind(obj, "autoscaling/v1", "HorizontalPodAutoscaler"), 40 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 41 | spec: c.readOpt(obj["spec"], toHorizontalPodAutoscalerSpec), 42 | status: c.readOpt(obj["status"], toHorizontalPodAutoscalerStatus), 43 | }} 44 | export function fromHorizontalPodAutoscaler(input: HorizontalPodAutoscaler): c.JSONValue { 45 | return { 46 | ...c.assertOrAddApiVersionAndKind(input, "autoscaling/v1", "HorizontalPodAutoscaler"), 47 | ...input, 48 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 49 | spec: input.spec != null ? fromHorizontalPodAutoscalerSpec(input.spec) : undefined, 50 | status: input.status != null ? fromHorizontalPodAutoscalerStatus(input.status) : undefined, 51 | }} 52 | 53 | /** specification of a horizontal pod autoscaler. */ 54 | export interface HorizontalPodAutoscalerSpec { 55 | maxReplicas: number; 56 | minReplicas?: number | null; 57 | scaleTargetRef: CrossVersionObjectReference; 58 | targetCPUUtilizationPercentage?: number | null; 59 | } 60 | export function toHorizontalPodAutoscalerSpec(input: c.JSONValue): HorizontalPodAutoscalerSpec { 61 | const obj = c.checkObj(input); 62 | return { 63 | maxReplicas: c.checkNum(obj["maxReplicas"]), 64 | minReplicas: c.readOpt(obj["minReplicas"], c.checkNum), 65 | scaleTargetRef: toCrossVersionObjectReference(obj["scaleTargetRef"]), 66 | targetCPUUtilizationPercentage: c.readOpt(obj["targetCPUUtilizationPercentage"], c.checkNum), 67 | }} 68 | export function fromHorizontalPodAutoscalerSpec(input: HorizontalPodAutoscalerSpec): c.JSONValue { 69 | return { 70 | ...input, 71 | scaleTargetRef: input.scaleTargetRef != null ? fromCrossVersionObjectReference(input.scaleTargetRef) : undefined, 72 | }} 73 | 74 | /** current status of a horizontal pod autoscaler */ 75 | export interface HorizontalPodAutoscalerStatus { 76 | currentCPUUtilizationPercentage?: number | null; 77 | currentReplicas: number; 78 | desiredReplicas: number; 79 | lastScaleTime?: c.Time | null; 80 | observedGeneration?: number | null; 81 | } 82 | export function toHorizontalPodAutoscalerStatus(input: c.JSONValue): HorizontalPodAutoscalerStatus { 83 | const obj = c.checkObj(input); 84 | return { 85 | currentCPUUtilizationPercentage: c.readOpt(obj["currentCPUUtilizationPercentage"], c.checkNum), 86 | currentReplicas: c.checkNum(obj["currentReplicas"]), 87 | desiredReplicas: c.checkNum(obj["desiredReplicas"]), 88 | lastScaleTime: c.readOpt(obj["lastScaleTime"], c.toTime), 89 | observedGeneration: c.readOpt(obj["observedGeneration"], c.checkNum), 90 | }} 91 | export function fromHorizontalPodAutoscalerStatus(input: HorizontalPodAutoscalerStatus): c.JSONValue { 92 | return { 93 | ...input, 94 | lastScaleTime: input.lastScaleTime != null ? c.fromTime(input.lastScaleTime) : undefined, 95 | }} 96 | 97 | /** list of horizontal pod autoscaler objects. */ 98 | export interface HorizontalPodAutoscalerList extends ListOf { 99 | apiVersion?: "autoscaling/v1"; 100 | kind?: "HorizontalPodAutoscalerList"; 101 | }; 102 | export function toHorizontalPodAutoscalerList(input: c.JSONValue): HorizontalPodAutoscalerList & c.ApiKind { 103 | const obj = c.checkObj(input); 104 | return { 105 | ...c.assertOrAddApiVersionAndKind(obj, "autoscaling/v1", "HorizontalPodAutoscalerList"), 106 | metadata: MetaV1.toListMeta(obj.metadata), 107 | items: c.readList(obj.items, toHorizontalPodAutoscaler), 108 | }} 109 | 110 | /** Scale represents a scaling request for a resource. */ 111 | export interface Scale { 112 | apiVersion?: string | null; 113 | kind?: string | null; 114 | metadata?: MetaV1.ObjectMeta | null; 115 | spec?: ScaleSpec | null; 116 | status?: ScaleStatus | null; 117 | } 118 | export function toScale(input: c.JSONValue): Scale { 119 | const obj = c.checkObj(input); 120 | return { 121 | apiVersion: c.readOpt(obj["apiVersion"], c.checkStr), 122 | kind: c.readOpt(obj["kind"], c.checkStr), 123 | metadata: c.readOpt(obj["metadata"], MetaV1.toObjectMeta), 124 | spec: c.readOpt(obj["spec"], toScaleSpec), 125 | status: c.readOpt(obj["status"], toScaleStatus), 126 | }} 127 | export function fromScale(input: Scale): c.JSONValue { 128 | return { 129 | ...input, 130 | metadata: input.metadata != null ? MetaV1.fromObjectMeta(input.metadata) : undefined, 131 | spec: input.spec != null ? fromScaleSpec(input.spec) : undefined, 132 | status: input.status != null ? fromScaleStatus(input.status) : undefined, 133 | }} 134 | 135 | /** ScaleSpec describes the attributes of a scale subresource. */ 136 | export interface ScaleSpec { 137 | replicas?: number | null; 138 | } 139 | export function toScaleSpec(input: c.JSONValue): ScaleSpec { 140 | const obj = c.checkObj(input); 141 | return { 142 | replicas: c.readOpt(obj["replicas"], c.checkNum), 143 | }} 144 | export function fromScaleSpec(input: ScaleSpec): c.JSONValue { 145 | return { 146 | ...input, 147 | }} 148 | 149 | /** ScaleStatus represents the current status of a scale subresource. */ 150 | export interface ScaleStatus { 151 | replicas: number; 152 | selector?: string | null; 153 | } 154 | export function toScaleStatus(input: c.JSONValue): ScaleStatus { 155 | const obj = c.checkObj(input); 156 | return { 157 | replicas: c.checkNum(obj["replicas"]), 158 | selector: c.readOpt(obj["selector"], c.checkStr), 159 | }} 160 | export function fromScaleStatus(input: ScaleStatus): c.JSONValue { 161 | return { 162 | ...input, 163 | }} 164 | -------------------------------------------------------------------------------- /lib/builtin/internal.apiserver.k8s.io@v1alpha1/mod.ts: -------------------------------------------------------------------------------- 1 | export * from "./structs.ts"; 2 | 3 | // Autogenerated API file for InternalApiserverV1alpha1 4 | import * as c from "../../common.ts"; 5 | import * as operations from "../../operations.ts"; 6 | import * as MetaV1 from "../meta@v1/structs.ts"; 7 | import * as InternalApiserverV1alpha1 from "./structs.ts"; 8 | 9 | export class InternalApiserverV1alpha1Api { 10 | #client: c.RestClient; 11 | #root = "/apis/internal.apiserver.k8s.io/v1alpha1/"; 12 | constructor(client: c.RestClient) { 13 | this.#client = client; 14 | } 15 | 16 | async getStorageVersionList( 17 | opts: operations.GetListOpts = {}, 18 | ): Promise { 19 | const resp = await this.#client.performRequest({ 20 | method: "GET", 21 | path: `${this.#root}storageversions`, 22 | expectJson: true, 23 | querystring: operations.formatGetListOpts(opts), 24 | abortSignal: opts.abortSignal, 25 | }); 26 | return InternalApiserverV1alpha1.toStorageVersionList(resp); 27 | } 28 | 29 | async watchStorageVersionList( 30 | opts: operations.WatchListOpts = {}, 31 | ): Promise> { 32 | const resp = await this.#client.performRequest({ 33 | method: "GET", 34 | path: `${this.#root}storageversions`, 35 | expectJson: true, 36 | expectStream: true, 37 | querystring: operations.formatWatchListOpts(opts), 38 | abortSignal: opts.abortSignal, 39 | }); 40 | return resp.pipeThrough(new c.WatchEventTransformer(InternalApiserverV1alpha1.toStorageVersion, MetaV1.toStatus)); 41 | } 42 | 43 | async createStorageVersion( 44 | body: InternalApiserverV1alpha1.StorageVersion, 45 | opts: operations.PutOpts = {}, 46 | ): Promise { 47 | const resp = await this.#client.performRequest({ 48 | method: "POST", 49 | path: `${this.#root}storageversions`, 50 | expectJson: true, 51 | querystring: operations.formatPutOpts(opts), 52 | bodyJson: InternalApiserverV1alpha1.fromStorageVersion(body), 53 | abortSignal: opts.abortSignal, 54 | }); 55 | return InternalApiserverV1alpha1.toStorageVersion(resp); 56 | } 57 | 58 | async deleteStorageVersionList( 59 | opts: operations.DeleteListOpts = {}, 60 | ): Promise { 61 | const resp = await this.#client.performRequest({ 62 | method: "DELETE", 63 | path: `${this.#root}storageversions`, 64 | expectJson: true, 65 | querystring: operations.formatDeleteListOpts(opts), 66 | abortSignal: opts.abortSignal, 67 | }); 68 | return InternalApiserverV1alpha1.toStorageVersionList(resp); 69 | } 70 | 71 | async getStorageVersion( 72 | name: string, 73 | opts: operations.NoOpts = {}, 74 | ): Promise { 75 | const resp = await this.#client.performRequest({ 76 | method: "GET", 77 | path: `${this.#root}storageversions/${name}`, 78 | expectJson: true, 79 | abortSignal: opts.abortSignal, 80 | }); 81 | return InternalApiserverV1alpha1.toStorageVersion(resp); 82 | } 83 | 84 | async deleteStorageVersion( 85 | name: string, 86 | opts: operations.DeleteOpts = {}, 87 | ): Promise { 88 | const resp = await this.#client.performRequest({ 89 | method: "DELETE", 90 | path: `${this.#root}storageversions/${name}`, 91 | expectJson: true, 92 | querystring: operations.formatDeleteOpts(opts), 93 | abortSignal: opts.abortSignal, 94 | }); 95 | if (c.isStatusKind(resp)) return MetaV1.toStatus(resp); 96 | return InternalApiserverV1alpha1.toStorageVersion(resp); 97 | } 98 | 99 | async replaceStorageVersion( 100 | name: string, 101 | body: InternalApiserverV1alpha1.StorageVersion, 102 | opts: operations.PutOpts = {}, 103 | ): Promise { 104 | const resp = await this.#client.performRequest({ 105 | method: "PUT", 106 | path: `${this.#root}storageversions/${name}`, 107 | expectJson: true, 108 | querystring: operations.formatPutOpts(opts), 109 | bodyJson: InternalApiserverV1alpha1.fromStorageVersion(body), 110 | abortSignal: opts.abortSignal, 111 | }); 112 | return InternalApiserverV1alpha1.toStorageVersion(resp); 113 | } 114 | 115 | async patchStorageVersion( 116 | name: string, 117 | type: c.PatchType, 118 | body: InternalApiserverV1alpha1.StorageVersion | c.JsonPatch, 119 | opts: operations.PatchOpts = {}, 120 | ): Promise { 121 | const resp = await this.#client.performRequest({ 122 | method: "PATCH", 123 | path: `${this.#root}storageversions/${name}`, 124 | expectJson: true, 125 | querystring: operations.formatPatchOpts(opts), 126 | contentType: c.getPatchContentType(type), 127 | bodyJson: Array.isArray(body) ? body : InternalApiserverV1alpha1.fromStorageVersion(body), 128 | abortSignal: opts.abortSignal, 129 | }); 130 | return InternalApiserverV1alpha1.toStorageVersion(resp); 131 | } 132 | 133 | async getStorageVersionStatus( 134 | name: string, 135 | opts: operations.NoOpts = {}, 136 | ): Promise { 137 | const resp = await this.#client.performRequest({ 138 | method: "GET", 139 | path: `${this.#root}storageversions/${name}/status`, 140 | expectJson: true, 141 | abortSignal: opts.abortSignal, 142 | }); 143 | return InternalApiserverV1alpha1.toStorageVersion(resp); 144 | } 145 | 146 | async replaceStorageVersionStatus( 147 | name: string, 148 | body: InternalApiserverV1alpha1.StorageVersion, 149 | opts: operations.PutOpts = {}, 150 | ): Promise { 151 | const resp = await this.#client.performRequest({ 152 | method: "PUT", 153 | path: `${this.#root}storageversions/${name}/status`, 154 | expectJson: true, 155 | querystring: operations.formatPutOpts(opts), 156 | bodyJson: InternalApiserverV1alpha1.fromStorageVersion(body), 157 | abortSignal: opts.abortSignal, 158 | }); 159 | return InternalApiserverV1alpha1.toStorageVersion(resp); 160 | } 161 | 162 | async patchStorageVersionStatus( 163 | name: string, 164 | type: c.PatchType, 165 | body: InternalApiserverV1alpha1.StorageVersion | c.JsonPatch, 166 | opts: operations.PatchOpts = {}, 167 | ): Promise { 168 | const resp = await this.#client.performRequest({ 169 | method: "PATCH", 170 | path: `${this.#root}storageversions/${name}/status`, 171 | expectJson: true, 172 | querystring: operations.formatPatchOpts(opts), 173 | contentType: c.getPatchContentType(type), 174 | bodyJson: Array.isArray(body) ? body : InternalApiserverV1alpha1.fromStorageVersion(body), 175 | abortSignal: opts.abortSignal, 176 | }); 177 | return InternalApiserverV1alpha1.toStorageVersion(resp); 178 | } 179 | 180 | } 181 | --------------------------------------------------------------------------------