-
Notifications
You must be signed in to change notification settings - Fork 563
Expand file tree
/
Copy pathraw-example.js
More file actions
37 lines (29 loc) · 1.06 KB
/
raw-example.js
File metadata and controls
37 lines (29 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import * as k8s from '@kubernetes/client-node';
import { fetch } from 'undici';
import https from 'node:https';
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const currentUser = kc.getCurrentUser();
const currentCluster = kc.getCurrentCluster();
const agent = new https.Agent({
// If caData, certData, and keyData are undefined, read the values from the
// files specified in caFile, certFile, and keyFile.
ca: Buffer.from(currentCluster?.caData ?? '', 'base64').toString('utf8'),
cert: Buffer.from(currentUser?.certData ?? '', 'base64').toString('utf8'),
keepAlive: true,
key: Buffer.from(currentUser?.keyData ?? '', 'base64').toString('utf8'),
});
const opts = {
headers: {},
agent: agent,
};
kc.applyToHTTPSOptions(opts);
const url = `${kc?.getCurrentCluster()?.server}/api/v1/namespaces/default/pods`;
try {
const response = await fetch(url, opts);
const body = await response.text();
console.log(`statusCode: ${response.status}`);
console.log(`body: ${body}`);
} catch (err) {
console.error(`error: ${err}`);
}