godaddy / kubernetes-client

Simplified Kubernetes API client for Node.js.
MIT License
961 stars 192 forks source link

Issue in sample: Client not found #577

Open LakshanKarunathilake opened 4 years ago

LakshanKarunathilake commented 4 years ago

If I execute the sample code given in the Github readme. The node application throws error that client is not defined.

The code I executed is

const config = { apiVersion: 'v1', clusters: [], contexts: [], 'current-context': '', kind: 'Config', users: [] } const { KubeConfig } = require('kubernetes-client') const kubeconfig = new KubeConfig() kubeconfig.loadFromString(JSON.stringify(config))

const Request = require('kubernetes-client/backends/request') const backend = new Request({ kubeconfig }) const client = new Client({ backend, version: '1.13' })

The error I got is

(node:11776) UnhandledPromiseRejectionWarning: ReferenceError: Client is not defined at getNamespaces (F:\Docker\PARSEC-TOOL\TaskRunner.js:84:18) at Object. (F:\Docker\PARSEC-TOOL\app.js:28:1) at Module._compile (internal/modules/cjs/loader.js:778:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Function.Module.runMain (internal/modules/cjs/loader.js:831:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3) (node:11776) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:11776) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Can someone help me out

LakshanKarunathilake commented 4 years ago

And I am new to Kubernetes, I just copied the configuration from the kubectl config view. What's the best way of getting authenticated to my cluster

Plus when I give the configuration for users how is it done

Whipgit commented 4 years ago

Bump, same issue

ravizombie commented 3 years ago

In case if others are still looking, client wasnt initialized properly const Client = require('kubernetes-client').Client;