pulumi-kubernetes icon indicating copy to clipboard operation
pulumi-kubernetes copied to clipboard

kubectl 'exec' and 'cp' equivalent

Open saada opened this issue 5 years ago • 4 comments

I would like to be able to exec some code on-demand. This is especially relevant for use-cases where I want to use pulumi to build kubernetes operators.

Proposed APIs

exec

// concat stream buffers into entire output strings
const pods = await deployment.getPods()
const {stdout, stderr} = await pods[0].exec("echo", ["hello", "world"])
console.log(stdout, stderr)

execStream

const pods = await deployment.getPods()
const {stdout, stderr} = pods[0].execStream("echo", ["hello", "world"])
stdout.pipe(process.stdout)
stderr.pipe(process.stderr)

cp

import fs from 'fs'
const pods = await deployment.getPods()
const readStream = fs.createReadStream('myfile.txt')
await pods[0].cp(readStream, "/tmp/myfile.txt")

// or from an inline string
import { Readable } from 'stream'
const inlineStream = new Readable()
const inlineFile = `
#!/bin/bash
echo hello world
`
inlineFile.split('\n').forEach(line => inlineStream.push(line))
inlineStream.push(null)
await pods[0].cp(inlineStream, "/tmp/myfile.txt")

saada avatar Oct 13 '18 14:10 saada

I've been thinking a lot about this sort of thing too. I think it's super useful, but a key question for me is how this fits into the rest of Pulumi -- the rest of the SDK is highly declarative, and opening the door to imperative APIs that let you mutate existing resources is a huge leap, and one we should consider carefully before committing to. I'll be playing with it more over the next couple months, after which I expect to have stronger opinions.

In the meantime, the official Kubernetes JavaScript client offers these things out of the box. It should be feasible to use this stuff with Pulumi, which should bridge the gap in the short term.

hausdorff avatar Oct 14 '18 18:10 hausdorff

Thanks @hausdorff ... In the meantime, I created this: https://github.com/kubernetes-client/javascript/issues/124

saada avatar Oct 15 '18 20:10 saada

Are there any update in this? Thanks

yellowhat avatar Jul 13 '22 10:07 yellowhat

Adding this to the Kubernetes provider has not been prioritized, but I believe all of the original use cases can be covered with the use of the pulumi-command provider, or by using the Automation API.

lblackstone avatar Jul 13 '22 15:07 lblackstone