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
4 changes: 0 additions & 4 deletions examples/cache-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

const namespace = 'default';

const path = '/api/v1/pods';
const watch = new k8s.Watch(kc);

const listFn = () => k8sApi.listPodForAllNamespaces();

const cache = new k8s.ListWatch(path, watch, listFn);

const looper = () => {
Expand Down
2 changes: 0 additions & 2 deletions examples/follow-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const log = new k8s.Log(kc);

const logStream = new stream.PassThrough();

const namespace = 'default';
const pod = 'pod1';
const container = 'container1';
Expand Down
8 changes: 3 additions & 5 deletions examples/in-cluster-create-job-from-cronjob.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import * as k8s from '@kubernetes/client-node';

const namespace = 'default';

const kc = new k8s.KubeConfig();
kc.loadFromCluster();

const batchV1Api = kc.makeApiClient(k8s.BatchV1Api);
const batchV1beta1Api = kc.makeApiClient(k8s.BatchV1beta1Api);
const cronJobName = 'cronjob';
const jobName = 'myjob';
const namespace = 'default';

const job = new k8s.V1Job();
const metadata = new k8s.V1ObjectMeta();
Expand All @@ -21,9 +19,9 @@ metadata.annotations = {
job.metadata = metadata;

try {
const cronJobRes = await batchV1beta1Api.readNamespacedCronJob({ name: cronJobName, namespace });
const cronJobRes = await batchV1Api.readNamespacedCronJob({ name: cronJobName, namespace });
job.spec = cronJobRes?.spec?.jobTemplate.spec;
const res = await batchV1Api..createNamespacedJob({ namespace, body: job });
const res = await batchV1Api.createNamespacedJob({ namespace, body: job });
console.log(res);
} catch (err) {
console.error(err);
Expand Down
2 changes: 0 additions & 2 deletions examples/in-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ const kc = new k8s.KubeConfig();
kc.loadFromCluster();

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

const namespace = 'default';

try {
const res = await k8sApi.listNamespacedPod({ namespace });

console.log(res);
} catch (err) {
console.error(err);
Expand Down
10 changes: 4 additions & 6 deletions examples/patch-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

const namespace = 'default';

try {
Expand Down Expand Up @@ -45,11 +44,10 @@ try {
},
});

await k8sApi
.patchNamespacedPod(
{ name: res?.items?.[0].metadata?.name ?? '', namespace, body: patch },
configuration,
)
await k8sApi.patchNamespacedPod(
{ name: res?.items?.[0]?.metadata?.name ?? '', namespace, body: patch },
configuration,
);
console.log('Patched.');
} catch (err) {
console.error('Error: ');
Expand Down
4 changes: 3 additions & 1 deletion examples/raw-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ 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,
Expand All @@ -31,5 +33,5 @@ try {
console.log(`statusCode: ${response.status}`);
console.log(`body: ${body}`);
} catch (err) {
console.error(`error: ${error}`);
console.error(`error: ${err}`);
}
3 changes: 0 additions & 3 deletions examples/scale-deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ async function scale(namespace, name, replicas) {
namespace,
});

if (!deployment || !deployment.spec) {
throw new Error(`Deployment ${name} not found in namespace ${namespace}`);
}
// edit
const newDeployment = {
...deployment,
Expand Down
1 change: 0 additions & 1 deletion examples/top.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

const obj = await k8s.topNodes(k8sApi);
console.log(obj);
2 changes: 1 addition & 1 deletion examples/yaml-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ try {
console.log(response);
const res = await k8sApi.readNamespace({ name: yamlNamespace.metadata.name });
console.log(res);
await k8sApi.deleteNamespace({ name: yamlNamespace.metadata.name }, {} /* delete options */);
await k8sApi.deleteNamespace({ name: yamlNamespace.metadata.name });
} catch (err) {
console.error('Error!: ' + err);
}
Loading