Skip to content

Commit

Permalink
fix(k8s): exec and run commands didn't work properly in interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald authored and eysi09 committed Dec 9, 2018
1 parent cbef539 commit 420953d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
13 changes: 11 additions & 2 deletions garden-service/src/plugins/kubernetes/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ export async function execInService(params: ExecInServiceParams<ContainerModule>
}

// exec in the pod via kubectl
const kubecmd = ["exec", "-i", pod.metadata.name, "--", ...command]
const opts: string[] = []

if (interactive) {
opts.push("-it")
}

const kubecmd = ["exec", ...opts, pod.metadata.name, "--", ...command]
const res = await kubectl(api.context, namespace).call(kubecmd, {
ignoreError: true,
timeout: 999999,
Expand Down Expand Up @@ -185,10 +191,13 @@ export async function runModule(
"--restart=Never",
"--command",
"--rm",
"-i",
"--quiet",
]

if (interactive) {
opts.push("-it")
}

const kubecmd = [
"run", `run-${module.name}-${Math.round(new Date().getTime())}`,
...opts,
Expand Down
14 changes: 5 additions & 9 deletions garden-service/src/plugins/kubernetes/kubectl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export class Kubectl {
}

async call(args: string[], opts: SpawnOpts = {}) {
const { data, ignoreError = false, timeout = KUBECTL_DEFAULT_TIMEOUT } = opts
const preparedArgs = this.prepareArgs(args, opts)
return spawn("kubectl", preparedArgs, { ignoreError, data, timeout })
const { data, ignoreError = false, timeout = KUBECTL_DEFAULT_TIMEOUT, tty } = opts
const preparedArgs = this.prepareArgs(args)
return spawn("kubectl", preparedArgs, { ignoreError, data, timeout, tty })
}

async json(args: string[], opts: SpawnOpts = {}): Promise<any> {
Expand All @@ -48,10 +48,10 @@ export class Kubectl {
}

spawn(args: string[]): ChildProcess {
return _spawn("kubectl", this.prepareArgs(args, {}))
return _spawn("kubectl", this.prepareArgs(args))
}

private prepareArgs(args: string[], { tty }: SpawnOpts) {
private prepareArgs(args: string[]) {
const opts: string[] = []

if (this.namespace) {
Expand All @@ -66,10 +66,6 @@ export class Kubectl {
opts.push(`--kubeconfig=${this.configPath}`)
}

if (tty) {
opts.push("--tty")
}

return opts.concat(args)
}
}
Expand Down
3 changes: 3 additions & 0 deletions garden-service/src/types/plugin/outputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,14 @@ export const execInServiceResultSchema = Joi.object()
.required()
.description("The exit code of the command executed in the service container."),
output: Joi.string()
.allow("")
.required()
.description("The output of the executed command."),
stdout: Joi.string()
.allow("")
.description("The stdout output of the executed command (if available)."),
stderr: Joi.string()
.allow("")
.description("The stderr output of the executed command (if available)."),
})

Expand Down

0 comments on commit 420953d

Please sign in to comment.