kubernetes-client icon indicating copy to clipboard operation
kubernetes-client copied to clipboard

Error: no auth mechanism defined with GKE in certain moments

Open ps-aux opened this issue 7 years ago • 8 comments

I run the following code on CI with GKE authentication and I get the error below. When I SSH into machine where this error happened or when I run it locally it works.

const Client = require('kubernetes-client').Client
const config = require('kubernetes-client').config
const client = new Client({config: config.fromKubeconfig(), version: '1.10'})
const yaml = require('js-yaml')
const fs = require('fs')

const deployFromYaml = ({file, version, env}) => {
    console.log(`Deploying ${version} from ${file} to ${env}`)
    const fileContent = fs.readFileSync(file).toString()

    const dep = yaml.safeLoad(fileContent)

    const container = dep.spec.template.spec.containers[0]
    container.image = container.image.split(':')[0] + `:${version}`

    return client.apis.apps.v1beta2.namespaces(env)
        .deployments(dep.metadata.name).put({body: dep})
}

Error: no auth mechanism defined
    at Auth.onRequest (/home/circleci/project/node_modules/request/lib/auth.js:132:32)
    at Request.auth (/home/circleci/project/node_modules/request/request.js:1343:14)
    at Request.init (/home/circleci/project/node_modules/request/request.js:374:10)
    at new Request (/home/circleci/project/node_modules/request/request.js:127:8)
    at request (/home/circleci/project/node_modules/request/index.js:53:10)
    at Request.request (/home/circleci/project/node_modules/kubernetes-client/lib/request.js:92:12)
    at Promise (/home/circleci/project/node_modules/kubernetes-client/lib/swagger-client.js:266:17)
    at new Promise (<anonymous>)
    at Component._requestAsync (/home/circleci/project/node_modules/kubernetes-client/lib/swagger-client.js:265:12)
    at Component._put (/home/circleci/project/node_modules/kubernetes-client/lib/swagger-client.js:340:17)

ps-aux avatar Jul 17 '18 08:07 ps-aux

I'm not sure. We have a relatively high priority issue about something similar: https://github.com/godaddy/kubernetes-client/issues/262

I wonder if that could help you, or if adding something like that to kubernetes-client would help resolve your issue.

silasbw avatar Jul 18 '18 17:07 silasbw

this line helped my solve the issue delete localConfig.auth.request;

dorshay6 avatar Nov 11 '18 18:11 dorshay6

@dorshay6 I'm facing the same issue. How does this line of code prevent the error?

tobinski avatar Jan 15 '19 14:01 tobinski

@tobinski I don't remember for sure, but as far as I remember there is an empty object there by default so there is no auth mechanism defined inside, removing it will use the default one. Which works well.

Again this is all by memory, I will be happy to add a more detailed comment later this week.

dorshay6 avatar Jan 16 '19 09:01 dorshay6

@dorshay6 thanks for your help. I now use the snipped of https://github.com/godaddy/kubernetes-client/issues/262#issue-320928825 to auth with gce

tobinski avatar Jan 17 '19 14:01 tobinski

Doesn't seem to be any solution here, any update @dorshay6 @tobinski ?

frostebite avatar Jun 15 '20 21:06 frostebite

I fixed my issue by running a kubectl command before using my kubeconfig with this package. This is required for some reason because the access-token isn't populated within the config until one command has run.

frostebite avatar Jun 15 '20 23:06 frostebite

I fixed my issue by running a kubectl command before using my kubeconfig with this package. This is required for some reason because the access-token isn't populated within the config until one command has run.

We do this too, but it's sooooooooooooooooooo hacky. I'd love to find a better solution

Stono avatar Sep 17 '20 17:09 Stono