Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/README.md
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
- package-ecosystem: github-actions
directory: /
schedule:
interval: "weekly"
interval: monthly
57 changes: 46 additions & 11 deletions .github/workflows/deno-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches: [ main ]
pull_request: {}

permissions:
contents: read
jobs:

check:
Expand All @@ -13,10 +15,12 @@ jobs:
strategy:
matrix:
deno-version:
- v1.41
- v1.43
- v1.45
- v2.0
- v2.1
- v2.2
- v2.3
- v2.4
- v2.5
- canary
fail-fast: false # run each branch to completion

Expand All @@ -29,14 +33,14 @@ jobs:
with:
deno-version: ${{ matrix.deno-version }}

# "https" cache: code from the Internet
# External sources won't change much so we use less precise keys
- name: Cache https://
- name: Cache Deno deps
uses: actions/cache@v4
with:
path: ~/.cache/deno/deps/https
key: deno-https/v1-${{ github.sha }}
restore-keys: deno-https/v1-
path: ~/.cache/deno
key: denodir/${{ matrix.deno-version }}-${{ hashFiles('deno.lock') }}

- name: Possibly reset lockfile
run: deno install || rm deno.lock

- name: Check generation/mod.ts
run: time deno check generation/mod.ts
Expand All @@ -53,7 +57,7 @@ jobs:
- name: Test
run: time deno test

audit-lib:
check-publish-lib:
runs-on: ubuntu-latest
name: Audit ./lib

Expand All @@ -64,6 +68,37 @@ jobs:
- name: Use latest Deno
uses: denoland/setup-deno@v2

- name: Cache Deno deps
uses: actions/cache@v4
with:
path: ~/.cache/deno
key: denodir-${{ hashFiles('deno.lock') }}

- name: Check publish rules
working-directory: lib
run: ../with-jsr-deps.sh deno publish --dry-run --allow-dirty
run: deno publish --dry-run --allow-dirty

publish-lib:
runs-on: ubuntu-latest
name: Publish ./lib
needs:
- check
- check-publish-lib
if: github.event_name == 'push'

permissions:
contents: read
id-token: write

steps:
- uses: denoland/setup-deno@v2
- uses: actions/checkout@v5

- name: Cache Deno deps
uses: actions/cache@v4
with:
path: ~/.cache/deno
key: denodir-${{ hashFiles('deno.lock') }}

- name: Publish now
run: deno publish
25 changes: 0 additions & 25 deletions .github/workflows/jsr-publish-lib.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"workspace": [
"generation",
"lib"
]
}
87 changes: 87 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md → generation/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![Deno CI](https://github.com/danopia/deno-kubernetes_apis/workflows/CI/badge.svg?branch=main)
[![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)

# `/x/kubernetes_apis`
# `@cloudydeno/kubernetes-apis`

NOTE: This README is about code generation concepts.

Expand Down
12 changes: 6 additions & 6 deletions generation/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { path } from "./deps.ts";
import { join as joinPath } from "@std/path/join";
import { generateModuleTypescript } from "./codegen-mod.ts";
import { generateStructsTypescript } from "./codegen-structs.ts";
import { SurfaceApi, SurfaceMap } from "./describe-surface.ts";

export async function writeApiModule(surface: SurfaceMap, api: SurfaceApi, category: string, apisModuleRoot?: string) {
const modRoot = path.join('lib', category, api.moduleName);
const modRoot = joinPath('lib', category, api.moduleName);

function postProcess(text: string) {
if (apisModuleRoot) {
Expand All @@ -22,13 +22,13 @@ export async function writeApiModule(surface: SurfaceMap, api: SurfaceApi, categ

await Deno.mkdir(modRoot, {recursive: true});

await Deno.writeTextFile(path.join(modRoot, 'structs.ts'),
await Deno.writeTextFile(joinPath(modRoot, 'structs.ts'),
postProcess(generateStructsTypescript(surface, api)));
console.log('Wrote', path.join(modRoot, 'structs.ts'));
console.log('Wrote', joinPath(modRoot, 'structs.ts'));

if (api.operations.length > 0) {
await Deno.writeTextFile(path.join(modRoot, 'mod.ts'),
await Deno.writeTextFile(joinPath(modRoot, 'mod.ts'),
postProcess(generateModuleTypescript(surface, api)));
console.log('Wrote', path.join(modRoot, 'mod.ts'));
console.log('Wrote', joinPath(modRoot, 'mod.ts'));
}
}
7 changes: 7 additions & 0 deletions generation/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"imports": {
"@cloudydeno/kubernetes-client": "jsr:@cloudydeno/kubernetes-client@^0.7",
"@std/path": "jsr:@std/path@^1",
"@std/yaml": "jsr:@std/yaml@^1"
}
}
4 changes: 0 additions & 4 deletions generation/deps.ts

This file was deleted.

6 changes: 4 additions & 2 deletions generation/run-on-crds.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { YAML, ApiKind, JSONValue } from "./deps.ts";
import { parseAll as parseAllYAML } from "@std/yaml/parse";
import type { ApiKind, JSONValue } from "@cloudydeno/kubernetes-client/lib/contract.ts";

import type { OpenAPI2SchemaObject, OpenAPI2Methods, OpenAPI2PathMethod } from './openapi.ts';
import { writeApiModule } from "./codegen.ts";
import { SurfaceMap, SurfaceApi, OpScope } from "./describe-surface.ts";
Expand All @@ -22,7 +24,7 @@ for await (const dirEntry of Deno.readDir(Deno.args[0])) {
if (dirEntry.name.endsWith('.example.yaml')) continue;

const raw = await Deno.readFile(Deno.args[0]+'/'+dirEntry.name);
const docs = YAML.parseAll(new TextDecoder('utf-8').decode(raw)) as Array<unknown>;
const docs = parseAllYAML(new TextDecoder('utf-8').decode(raw)) as Array<unknown>;
for (const doc of docs) {

const typing = doc as ApiKind;
Expand Down
41 changes: 20 additions & 21 deletions lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@

Generated, typed interfaces to make every possible Kubernetes API request and work with richer data structures.

The actual request transports are implemented in `/x/kubernetes_client`.
The actual HTTP request logic (e.g. authentication) is handled by `@cloudydeno/kubernetes-client`.

## Usage

Here's a basic request, listing all Pods in the `default` namespace.
> [!NOTE]
> This library has no default export, so you will need to
> import the particular Kubernetes API groups that you want to work with.
> This arrangement keeps program size smaller.

This basic example lists 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/kubernetes_client@v0.7.3/mod.ts';
import { CoreV1Api } from 'https://deno.land/x/kubernetes_apis/builtin/core@v1/mod.ts';
import { autoDetectClient } from 'jsr:@cloudydeno/kubernetes-client';
import { CoreV1Api } from 'jsr:@cloudydeno/kubernetes-apis/core/v1';

const kubernetes = await autoDetectClient();
const coreApi = new CoreV1Api(kubernetes).namespace("default");
Expand All @@ -26,29 +31,23 @@ console.log(podList);
// see files in examples/ for more API demos (watching, creation, etc)
```

When running locally (with `kubectl` set up), you probably just to add `--allow-run=kubectl` to run this.
For a container being deployed onto a cluster, there's more flags to provide instead;
see `/x/kubernetes_client` for more information.

### Deno Permissions

### 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.
When running locally (with `kubectl` set up), you probably want to pass `--allow-run=kubectl` to Deno.

```ts
import { autoDetectClient } from "jsr:@cloudydeno/kubernetes-client@0.7.3";
import { CoreV1Api } from "jsr:@cloudydeno/kubernetes-apis/core/v1";

const kubernetes = await autoDetectClient();
const coreApi = new CoreV1Api(kubernetes).namespace("default");
For a container being deployed onto a cluster with a Service Account,
the minimally required Deno permission flags are:
`--allow-read=/var/run/secrets/kubernetes.io --allow-net=kubernetes.default.svc.cluster.local`

const podList = await coreApi.getPodList();
console.log(podList);
```
See [`@cloudydeno/kubernetes-client` docs](https://jsr.io/@cloudydeno/kubernetes-client)
for more information.

## Changelog

* `v0.5.5` on `2025-09-19`:
* Fully adopt JSR. Remove remnants of `/x/` and `/std/` dependencies.
*

* `v0.5.4` on `2025-01-18`:
* Includes 'builtin' APIs generated from K8s `v1.32.0`.
* Several API versions were changed, removed, or added.
Expand Down
8 changes: 4 additions & 4 deletions lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
// while users are free to pass in a different compatible client to actually call

import { toStatus, type Status } from "./builtin/meta@v1/structs.ts";
import {
import type {
ApiKind,
JSONObject,
JSONValue,
RequestOptions,
type WatchEvent
} from "./deps.ts";
WatchEvent
} from "@cloudydeno/kubernetes-client";
export {
type ApiKind,
type JSONValue,
type RestClient,
WatchEventTransformer,
type WatchEvent,
} from "./deps.ts";
} from "@cloudydeno/kubernetes-client";

// Shorthand for generated type signatures
export type WatchEventStream<T> = ReadableStream<WatchEvent<T & ApiKind, Status & ApiKind>>;
Expand Down
Loading