minecluster/lib/k8s/k8s-config.js
Dunemask 27b11fcd50
All checks were successful
Deploy USW-MC / deploy-edge (push) Successful in 2m7s
[FIX] Infer Current Context
2024-08-25 11:52:25 -06:00

14 lines
562 B
JavaScript

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();
}
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;