Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying a Custom Config as an object fails #222

Closed
lholmquist opened this issue May 28, 2020 · 1 comment
Closed

Specifying a Custom Config as an object fails #222

lholmquist opened this issue May 28, 2020 · 1 comment
Labels

Comments

@lholmquist
Copy link
Member

If a user passes in a custom config as an object(that is in the valid kube config format), they will get this error:

TypeError: kubeconfig.getCurrentContext is not a function
    at convertKubeconfig (/var/task/node_modules/kubernetes-client/backends/request/config.js:16:30)
    at new Request (/var/task/node_modules/kubernetes-client/backends/request/client.js:118:26)
    at openshiftClient (/var/task/node_modules/openshift-rest-client/lib/openshift-rest-client.js:138:30)
    at setup (/var/task/node_modules/nodeshift/lib/nodeshift-config.js:35:28)
    at async run (/var/task/node_modules/nodeshift/bin/cli.js:36:20)
    at async Express.openShiftBuild (/var/task/openshift/openShiftBuild.js:53:3)
    at async Express.deploy (/var/task/serverless.js:68:5)
    at async Runtime.module.exports [as handler] (/opt/nodejs/node_modules/@serverless/core/handler.js:273:24)

It is happening here: https://github.com/nodeshift/openshift-rest-client/blob/master/lib/openshift-rest-client.js#L145

It looks like we just need to do this instead:

kubeconfig.loadFromString(JSON.stringify(config));
clientConfig.backend = new Request({ kubeconfig });

If they don't add an apiVersion or kind then the underlying library errors, so we could inject those properties if they are not there?

@lholmquist lholmquist added the bug label May 28, 2020
@lholmquist
Copy link
Member Author

If a user passes in an actual KubeConfig object,

config: new (require('kubernetes-client').KubeConfig)()
,

Then this wouldn't error. They would be doing something like this:

const openshiftRestClient = require('openshift-rest-client').OpenshiftClient;
const k8Config = require('openshift-rest-client').config;

const config = {
  apiVersion: 'v1',
  kind: 'Config',
  clusters: [ ],
  users: [],
  contexts: [ ],
  'current-context': '...'
};

k8Config.loadFromString(JSON.stringify(config));


openshiftRestClient({config: k8Config}).then((client) => {
  console.log(client);
})

That is fine, but they should also be able to pass in a regular object without having to do the loadFromString themselves

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant