Skip to content

Commit

Permalink
fix(k8s): hanging port forward processes on Windows
Browse files Browse the repository at this point in the history
Fixes #2129
  • Loading branch information
edvald authored and thsig committed Jan 20, 2021
1 parent d61e244 commit d6dcd45
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions core/src/plugins/kubernetes/port-forward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ForwardablePort, Service } from "../../types/service"
import { isBuiltIn } from "./util"
import { LogEntry } from "../../logger/log-entry"
import { RuntimeError } from "../../exceptions"
import execa = require("execa")

// TODO: implement stopPortForward handler

Expand Down Expand Up @@ -103,11 +104,23 @@ export async function getPortForward({

log.debug(`Forwarding local port ${localPort} to ${targetResource} port ${port}`)

// TODO: use the API directly instead of kubectl (need to reverse engineer kubectl a bit to get how that works)
const portForwardArgs = ["port-forward", targetResource, portMapping]
// TODO: use the API directly instead of kubectl (need to reverse-engineer kubectl quite a bit for that)
const portForwardArgs = [
"--context",
k8sCtx.provider.config.context,
"--namespace",
namespace,
"port-forward",
targetResource,
portMapping,
]

log.silly(`Running 'kubectl ${portForwardArgs.join(" ")}'`)

const proc = await kubectl(k8sCtx, k8sCtx.provider).spawn({ log, namespace, args: portForwardArgs })
// Need to use execa directly to use its cleanup mechanism, otherwise processes can linger on Windows
const kubectlPath = await kubectl(k8sCtx, k8sCtx.provider).getPath(log)
const proc = execa(kubectlPath, portForwardArgs, { cleanup: true, buffer: false })

let output = ""

return new Promise((resolve, reject) => {
Expand Down

0 comments on commit d6dcd45

Please sign in to comment.