Skip to content

Commit

Permalink
Regenerate APIs for Kubernetes 1.32 et al (#19)
Browse files Browse the repository at this point in the history
* chore: Deduplicate knownOpts into new file

* Regenerate APIs from Kubernetes 1.32.0 et al

* Update JSR imports

* Update README for 0.5.4

* fix readme typo
  • Loading branch information
danopia authored Jan 18, 2025
1 parent 9760fdc commit 562423c
Show file tree
Hide file tree
Showing 33 changed files with 3,774 additions and 3,076 deletions.
12 changes: 2 additions & 10 deletions generation/codegen-mod.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import { SurfaceMap, SurfaceApi, SurfaceOperation } from "./describe-surface.ts";
import { OpenAPI2RequestParameter } from "./openapi.ts";
import { ApiShape } from "./describe-shapes.ts";
import { knownOptsReverse } from "./known-opts.ts";

const knownOpts: Record<string,string|undefined> = {
'': 'NoOpts',
'continue,fieldSelector,labelSelector,limit,resourceVersion,resourceVersionMatch,sendInitialEvents,timeoutSeconds': 'GetListOpts',
'allowWatchBookmarks,fieldSelector,labelSelector,resourceVersion,resourceVersionMatch,sendInitialEvents,timeoutSeconds': 'WatchListOpts',
'dryRun,fieldManager,fieldValidation': 'PutOpts', // both CreateOpts and ReplaceOpts
'continue,dryRun,fieldSelector,gracePeriodSeconds,labelSelector,limit,orphanDependents,propagationPolicy,resourceVersion,resourceVersionMatch,sendInitialEvents,timeoutSeconds': 'DeleteListOpts',
'dryRun,fieldManager,fieldValidation,force': 'PatchOpts',
'exact,export': 'GetOpts',
'dryRun,gracePeriodSeconds,orphanDependents,propagationPolicy': 'DeleteOpts',
};
const knownOpts = knownOptsReverse;

export function generateModuleTypescript(surface: SurfaceMap, api: SurfaceApi): string {
const chunks = new Array<string>();
Expand Down
8 changes: 4 additions & 4 deletions generation/generate-all.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/sh -eux

# https://github.com/kubernetes/kubernetes/releases
./generation/sources/builtin.sh v1.30.4
./generation/sources/builtin.sh v1.32.0

# https://github.com/argoproj/argo-cd/releases
./generation/sources/argo-cd.sh v2.12.3
./generation/sources/argo-cd.sh v2.13.3

# https://github.com/cert-manager/cert-manager/releases
./generation/sources/cert-manager.sh v1.15.3
./generation/sources/cert-manager.sh v1.16.2

# https://github.com/kubernetes-sigs/external-dns/releases
./generation/sources/external-dns.sh v0.15.0
./generation/sources/external-dns.sh v0.15.1

# https://github.com/kubernetes/autoscaler/releases?q=vertical
./generation/sources/vpa.sh 1.2.1
21 changes: 21 additions & 0 deletions generation/known-opts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

export const knownOptsForward = {
GetListOpts: 'continue,fieldSelector,labelSelector,limit,resourceVersion,resourceVersionMatch,sendInitialEvents,timeoutSeconds',
WatchListOpts: 'allowWatchBookmarks,fieldSelector,labelSelector,resourceVersion,resourceVersionMatch,sendInitialEvents,timeoutSeconds',
PutOpts: 'dryRun,fieldManager,fieldValidation', // both CreateOpts and ReplaceOpts
DeleteListOpts: 'continue,dryRun,fieldSelector,gracePeriodSeconds,ignoreStoreReadErrorWithClusterBreakingPotential,labelSelector,limit,orphanDependents,propagationPolicy,resourceVersion,resourceVersionMatch,sendInitialEvents,timeoutSeconds',
PatchOpts: 'dryRun,fieldManager,fieldValidation,force',
GetOpts: '',
DeleteOpts: 'dryRun,gracePeriodSeconds,ignoreStoreReadErrorWithClusterBreakingPotential,orphanDependents,propagationPolicy',
};

export const knownOptsReverse: Record<string,string|undefined> = {
'': 'NoOpts',
[knownOptsForward.GetListOpts]: 'GetListOpts',
[knownOptsForward.WatchListOpts]: 'WatchListOpts',
[knownOptsForward.PutOpts]: 'PutOpts', // both CreateOpts and ReplaceOpts
[knownOptsForward.DeleteListOpts]: 'DeleteListOpts',
[knownOptsForward.PatchOpts]: 'PatchOpts',
'exact,export': 'GetOpts',
[knownOptsForward.DeleteOpts]: 'DeleteOpts',
};
13 changes: 3 additions & 10 deletions generation/run-on-crds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { OpenAPI2SchemaObject, OpenAPI2Methods, OpenAPI2PathMethod } from '
import { writeApiModule } from "./codegen.ts";
import { SurfaceMap, SurfaceApi, OpScope } from "./describe-surface.ts";
import { ShapeLibrary } from "./describe-shapes.ts";
import { knownOptsForward } from "./known-opts.ts";

import {
CustomResourceDefinition as CRDv1,
Expand All @@ -11,18 +12,10 @@ import {
CustomResourceDefinitionNames,
} from "../lib/builtin/apiextensions.k8s.io@v1/structs.ts";

const knownOpts = {
GetListOpts: 'continue,fieldSelector,labelSelector,limit,resourceVersion,resourceVersionMatch,sendInitialEvents,timeoutSeconds',
WatchListOpts: 'allowWatchBookmarks,fieldSelector,labelSelector,resourceVersion,resourceVersionMatch,sendInitialEvents,timeoutSeconds',
PutOpts: 'dryRun,fieldManager,fieldValidation', // both CreateOpts and ReplaceOpts
DeleteListOpts: 'continue,dryRun,fieldSelector,gracePeriodSeconds,labelSelector,limit,orphanDependents,propagationPolicy,resourceVersion,resourceVersionMatch,sendInitialEvents,timeoutSeconds',
PatchOpts: 'dryRun,fieldManager,fieldValidation,force',
GetOpts: '',
DeleteOpts: 'dryRun,gracePeriodSeconds,orphanDependents,propagationPolicy',
};

const v1CRDs = new Array<CRDv1>();

const knownOpts = knownOptsForward;

for await (const dirEntry of Deno.readDir(Deno.args[0])) {
if (!dirEntry.isFile) continue;
if (!dirEntry.name.endsWith('.yaml')) continue;
Expand Down
25 changes: 24 additions & 1 deletion lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Here's a basic request, listing all Pods in the `default` namespace.
It uses the `autoDetectClient()` entrypoint which returns the first usable client.

```ts
import { autoDetectClient } from 'https://deno.land/x/[email protected].0/mod.ts';
import { autoDetectClient } from 'https://deno.land/x/[email protected].3/mod.ts';
import { CoreV1Api } from 'https://deno.land/x/kubernetes_apis/builtin/core@v1/mod.ts';

const kubernetes = await autoDetectClient();
Expand All @@ -30,8 +30,31 @@ When running locally (with `kubectl` set up), you probably just to add `--allow-
For a container being deployed onto a cluster, there's more flags to provide instead;
see `/x/kubernetes_client` for more information.


### Usage with JSR Imports
Note that there is no default export, so you will need to
import the particular Kubernetes API groups that you want to work with.
This layout keeps program size smaller.

```ts
import { autoDetectClient } from "jsr:@cloudydeno/[email protected]";
import { CoreV1Api } from "jsr:@cloudydeno/kubernetes-apis/core/v1";

const kubernetes = await autoDetectClient();
const coreApi = new CoreV1Api(kubernetes).namespace("default");

const podList = await coreApi.getPodList();
console.log(podList);
```

## Changelog

* `v0.5.4` on `2025-01-18`:
* Includes 'builtin' APIs generated from K8s `v1.32.0`.
* Several API versions were changed, removed, or added.
* You may need to update imports if you used a non-stable API version which has been moved.
* `cert-manager` and `argo-cd` CRDs have been updated.

* `v0.5.3` on `2024-10-16`:
* Fix CRD codegen issues with particular definitions and when using JSR import paths.

Expand Down
Loading

0 comments on commit 562423c

Please sign in to comment.