minecluster/lib/k8s/k8s-config.js

15 lines
562 B
JavaScript
Raw Normal View History

import k8s from "@kubernetes/client-node";
const MCL_KUBECONFIG = process.env.MCL_KUBECONFIG;
const envConfig = MCL_KUBECONFIG ? MCL_KUBECONFIG : null;
const kc = new k8s.KubeConfig();
try {
if (!!envConfig)
kc.loadFromString(Buffer.from(envConfig, "base64").toString("utf8"));
else kc.loadFromDefault();
} catch (e) {
kc.loadFromDefault();
}
2024-08-25 11:52:25 -06:00
if(kc.contexts.length === 1) kc.setCurrentContext(kc.contexts[0].name);
if(!kc.currentContext) throw new Error("Could not infer current context! Please set it manually in the Kubeconfig!");
export default kc;