Skip to content

Commit c654db9

Browse files
authored
Merge pull request #90 from brendandburns/config
Remove custom fromCluster logic.
2 parents efec507 + ecde2f8 commit c654db9

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

node-client/src/config.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -326,23 +326,11 @@ export class Config {
326326
}
327327

328328
public static fromCluster(): api.Core_v1Api {
329-
const host = process.env.KUBERNETES_SERVICE_HOST;
330-
const port = process.env.KUBERNETES_SERVICE_PORT;
331-
332-
// TODO: better error checking here.
333-
const caCert = fs.readFileSync(Config.SERVICEACCOUNT_CA_PATH);
334-
const token = fs.readFileSync(Config.SERVICEACCOUNT_TOKEN_PATH);
329+
const kc = new KubeConfig();
330+
kc.loadFromCluster();
335331

336-
const k8sApi = new api.Core_v1Api('https://' + host + ':' + port);
337-
k8sApi.setDefaultAuthentication({
338-
applyToRequest: (opts) => {
339-
opts.ca = caCert;
340-
if (!opts.headers) {
341-
opts.headers = [];
342-
}
343-
opts.headers.Authorization = 'Bearer ' + token;
344-
},
345-
});
332+
const k8sApi = new api.Core_v1Api(kc.getCurrentCluster().server);
333+
k8sApi.setDefaultAuthentication(kc);
346334

347335
return k8sApi;
348336
}

0 commit comments

Comments
 (0)