Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as k8s from '@kubernetes/client-node';
import * as net from 'net';
const command = process.argv[2];
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const forward = new k8s.PortForward(kc);
// This simple server just forwards traffic from itself to a service running in kubernetes
// -> localhost:8080 -> port-forward-tunnel -> kubernetes-pod
// This is basically equivalent to 'kubectl port-forward ...' but in TypeScript.
const server = net.createServer((socket) => {
forward.portForward('default', 'demo', [8080], socket, null, socket);
});
server.listen(8080, '127.0.0.1');
function prepareK8sToolsWithCluster(cluster) {
let kubeConfig
try {
kubeConfig = buildKubeConfig(cluster.config)
} catch (error) {
const message = typeof error.message === 'string'
? `\nError message:\n---\n${error.message.substr(0, 1000)}`
: null
throw buildSentryIgnoredError(`Cluster config is invalid.${message}`)
}
const k8sPortForward = new k8s.PortForward(kubeConfig)
patchForward(k8sPortForward)
return { k8sPortForward, kubeConfig }
}