diff --git a/examples/cache-example.js b/examples/cache-example.js index 59896fc3ee..78e9a88755 100644 --- a/examples/cache-example.js +++ b/examples/cache-example.js @@ -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 = () => { diff --git a/examples/follow-logs.js b/examples/follow-logs.js index cce452ab01..c6aec08c98 100644 --- a/examples/follow-logs.js +++ b/examples/follow-logs.js @@ -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'; diff --git a/examples/in-cluster-create-job-from-cronjob.js b/examples/in-cluster-create-job-from-cronjob.js index 1265f37caf..c78e0c56fb 100644 --- a/examples/in-cluster-create-job-from-cronjob.js +++ b/examples/in-cluster-create-job-from-cronjob.js @@ -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(); @@ -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); diff --git a/examples/in-cluster.js b/examples/in-cluster.js index 4eccb0e7e9..5e707b9cd1 100644 --- a/examples/in-cluster.js +++ b/examples/in-cluster.js @@ -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); diff --git a/examples/patch-example.js b/examples/patch-example.js index b97b796587..9f2ab55b9c 100644 --- a/examples/patch-example.js +++ b/examples/patch-example.js @@ -5,7 +5,6 @@ const kc = new k8s.KubeConfig(); kc.loadFromDefault(); const k8sApi = kc.makeApiClient(k8s.CoreV1Api); - const namespace = 'default'; try { @@ -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: '); diff --git a/examples/raw-example.js b/examples/raw-example.js index 2be6269b98..a1e3c8182b 100644 --- a/examples/raw-example.js +++ b/examples/raw-example.js @@ -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, @@ -31,5 +33,5 @@ try { console.log(`statusCode: ${response.status}`); console.log(`body: ${body}`); } catch (err) { - console.error(`error: ${error}`); + console.error(`error: ${err}`); } diff --git a/examples/scale-deployment.js b/examples/scale-deployment.js index 5a5ab6a918..4b74094db7 100644 --- a/examples/scale-deployment.js +++ b/examples/scale-deployment.js @@ -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, diff --git a/examples/top.js b/examples/top.js index 1ff337357c..4e3484ec3b 100644 --- a/examples/top.js +++ b/examples/top.js @@ -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); diff --git a/examples/yaml-example.js b/examples/yaml-example.js index 7dc95c3eb7..73e60ed1de 100644 --- a/examples/yaml-example.js +++ b/examples/yaml-example.js @@ -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); }