Skip to content

Commit

Permalink
Green the CI, Require Deno v1.41+ (#22)
Browse files Browse the repository at this point in the history
* Ignore type error around TLS client certs

* Not like that

* Add deno v1.45 to CI

* Update for Deno 2 removals

* Update how mTls is provided for Deno 1.41+
  • Loading branch information
danopia authored Sep 10, 2024
1 parent 3a23db7 commit 1596ffa
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 45 deletions.
36 changes: 3 additions & 33 deletions .github/workflows/deno-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ jobs:
strategy:
matrix:
deno-version:
- v1.28
- v1.30
- v1.32
- v1.35
- v1.39
- v1.41
- v1.43
- v1.45
- canary
fail-fast: false # run each branch to completion

Expand Down Expand Up @@ -45,33 +43,5 @@ jobs:
- name: Check demo.ts
run: time deno check --unstable demo.ts

check-unstable:
runs-on: ubuntu-latest
name: Check Unstable w/ ${{ matrix.deno-version }}
strategy:
matrix:
deno-version:
- v1.39
- canary
fail-fast: false # run each branch to completion

steps:
- name: Checkout source
uses: actions/checkout@v4

- name: Use Deno ${{ matrix.deno-version }}
uses: denoland/setup-deno@v1
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://
uses: actions/cache@v4
with:
path: ~/.cache/deno/deps/https
key: deno-https/v1-${{ github.sha }}
restore-keys: deno-https/v1-

- name: Check tunnel-beta/examples/ws-exec-poc.ts
run: time deno check --unstable tunnel-beta/examples/ws-exec-poc.ts
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ Check out `lib/contract.ts` to see the type/API contract.

## Changelog


* `v0.7.0` on `2023-08-13`:
Port `KubectlRawRestClient` over to newer `Deno.Command()` API.
Support patching subresources & opening PodExec tunnels in `KubectlRawRestClient`.
Expand All @@ -61,6 +60,7 @@ Check out `lib/contract.ts` to see the type/API contract.

* `v0.7.1` on `2023-09-24`: Update std dependencies to `/[email protected]`
* `v0.7.2` on `2023-12-29`: Fix `WebsocketTunnel` for Deno v1.38 change
* `v0.7.3` on `2024-09-10`: Drop support for Deno v1.40 and earlier.

* `v0.6.0` on `2023-08-08`:
Introduce an API for opening Kubernetes tunnels, useful for `PodExec` and others.
Expand Down
12 changes: 6 additions & 6 deletions lib/kubeconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class KubeConfig {
const defaultPath = joinPath(Deno.env.get("HOME") || Deno.env.get("USERPROFILE") || "/root", ".kube", "config");
try {
return await KubeConfig.readFromPath(defaultPath);
} catch (err) {
if (err.name === 'NotFound') {
} catch (err: unknown) {
if ((err as Error).name === 'NotFound') {
return new KubeConfig(mergeKubeConfigs([]));
}
throw err;
Expand Down Expand Up @@ -193,12 +193,12 @@ export class KubeConfigContext {
if (expiresAt.valueOf() > Date.now()) {
return `Bearer ${config['access-token']}`;
} else throw new Error(
`TODO: GCP auth-provider token expired, use a kubectl command to refresh for now`);
`GCP "auth-provider" token expired, run a kubectl command to refresh. Or consider updating to "exec"`);
} else throw new Error(
`TODO: GCP auth-provider lacks a cached token, use a kubectl command to refresh for now`);
`GCP "auth-provider" lacks a cached token, run a kubectl command to refresh. Or consider updating to "exec"`);

default: throw new Error(
`TODO: this kubeconfig's auth-provider (${name}) isn't supported yet`);
`This kubeconfig's "auth-provider" (${name}) isn't supported. Consider updating to "exec"`);
}

} else if (this.user['exec']) {
Expand All @@ -221,7 +221,7 @@ export class KubeConfigContext {
const execConfig = this.user['exec'];
if (!execConfig) throw new Error(`BUG: execConfig disappeared`);

const isTTY = Deno.isatty(Deno.stdin.rid);
const isTTY = Deno.stdin.isTerminal();
const stdinPolicy = execConfig.interactiveMode ?? 'IfAvailable';
if (stdinPolicy == 'Always' && !isTTY) {
throw new Error(`KubeConfig exec plugin wants a TTY, but stdin is not a TTY`);
Expand Down
5 changes: 3 additions & 2 deletions transports/via-kubeconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ export class KubeConfigRestClient implements RestClient {
if (Deno.createHttpClient) {
httpClient = Deno.createHttpClient({
caCerts: serverTls ? [serverTls.serverCert] : [],
certChain: tlsAuth?.userCert,
privateKey: tlsAuth?.userKey,
//@ts-ignore-error deno unstable API. Not typed?
cert: tlsAuth?.userCert,
key: tlsAuth?.userKey,
});
} else if (tlsAuth) {
console.error('WARN: cannot use certificate-based auth without --unstable');
Expand Down
2 changes: 1 addition & 1 deletion tunnel-beta/examples/ws-exec-poc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S deno run --unstable --allow-env --allow-read --allow-net
#!/usr/bin/env -S deno run --unstable-net --allow-env --allow-read --allow-net --cert=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt

import { WebsocketRestClient } from "../via-websocket.ts";

Expand Down
5 changes: 3 additions & 2 deletions tunnel-beta/via-spdy-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export class SpdyEnabledRestClient extends KubeConfigRestClient {
port: url.port ? parseInt(url.port) : 443,
alpnProtocols: ['http/1.1'],
caCerts: serverTls?.serverCert ? [serverTls.serverCert] : [],
certChain: clientTls?.userCert,
privateKey: clientTls?.userKey,
//@ts-ignore-error deno unstable API. Not typed?
cert: clientTls?.userCert,
key: clientTls?.userKey,
});

const transport = await dialSpdyTunnel({
Expand Down
3 changes: 3 additions & 0 deletions tunnel-beta/via-websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { KubeConfigRestClient } from "../transports/via-kubeconfig.ts";
* WebSockets have various limits within the Kubernetes and Deno ecosystem,
* but they work quite well in several situations and have good backpressure support.
*
* * Run Deno with `--unstable-net` to enable the required WebSocketStream API.
*
* * For most clusters, you'll need to have Deno trust the cluster CA.
* Otherwise you'll get an `UnknownIssuer` error.
* In-cluster, you just need to pass `--cert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt`
Expand All @@ -22,6 +24,7 @@ import { KubeConfigRestClient } from "../transports/via-kubeconfig.ts";
* (TODO: find or create Kubernetes ticket to track this)
*
* * stdin restricted for exec/attach due to lack of EOF signal.
* Addressed in Kubernetes v1.29 via new `v5.channel.k8s.io` protocol.
* Upstream work: https://github.com/kubernetes/kubernetes/pull/119157
*/
export class WebsocketRestClient extends KubeConfigRestClient {
Expand Down

0 comments on commit 1596ffa

Please sign in to comment.