You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constfs=require('fs')constcertPath='/var/run/secrets/kubernetes.io/serviceaccount/ca.crt'consttokenPath='/var/run/secrets/kubernetes.io/serviceaccount/token'constnamespacePath='/var/run/secrets/kubernetes.io/serviceaccount/namespace'functiongetInClusterConfig(){consthost=process.env.KUBERNETES_SERVICE_HOSTconstport=process.env.KUBERNETES_SERVICE_PORTletcertletnamespaceletbearerif(!host||!port){throwTypeError('Unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined')}try{cert=fs.readFileSync(certPath,'utf8')}catch(err){throwTypeError('Expected to load root CA config from ${certPath}, but got err',err)}try{bearer=fs.readFileSync(tokenPath,'utf8')}catch(err){throwTypeError('Expected to load token config from ${tokenPath}, but got err',err)}try{namespace=fs.readFileSync(namespacePath,'utf8')}catch(err){throwTypeError('Expected to load namespace config from ${namespacePath}, but got err',err)}return{url: `https://${host}:${port}`,
cert,auth: { bearer },
namespace
}}
Hi,
would you be open for adding a built-in in-cluster config?
Based on:
https://github.com/kubernetes/client-go/blob/124670e99da15091e13916f0ad4b2b2df2a39cd5/rest/config.go#L274
and
http://kubernetes.io/docs/user-guide/accessing-the-cluster/#accessing-the-api-from-a-pod
Something like:
The interface could be:
I'm happy to send a PR if you like the idea.
What do you think?
The text was updated successfully, but these errors were encountered: