Skip to content

Commit 7faa498

Browse files
author
Radu Matei
committed
Add info about package
1 parent 116aa13 commit 7faa498

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
kube-exec
2+
=========
3+
4+
`kube-exec` is a library similar to [`os/exec`][1] that allows you to run commands in a Kubernetes pod, as if that command was executed locally.
5+
> It is inspired from [`go-dexec`][2] by [ahmetb][3], which does the same thing, but for a Docker engine.
6+
7+
The interface of the package is similar to `os/exec`, and essentially this:
8+
9+
- creates a new pod in Kubernetes based on a user-specified image
10+
- waits for the pod to be in [`Running`](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/) state
11+
- attaches to the pod and allows you to stream data to the pod through `stdin`, and from the pod back to the program through `stdout` and `stderr`
12+
13+
You can [find an example in here][4]
14+
15+
[1]: https://golang.org/pkg/os/exec
16+
[2]: https://github.com/ahmetb/go-dexec
17+
[3]: https://twitter.com/ahmetb
18+
19+
[4]: /examples/main.go

examples/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import (
88
kube "github.com/radu-matei/kube-exec"
99
)
1010

11-
var kubeconfig = os.Getenv("KUBECONFIG")
12-
1311
func main() {
1412

1513
cfg := kube.Config{
16-
Kubeconfig: kubeconfig,
14+
Kubeconfig: os.Getenv("KUBECONFIG"),
1715
Image: "ubuntu",
1816
Name: "kube-attach",
1917
Namespace: "default",
@@ -31,6 +29,7 @@ func main() {
3129
log.Fatalf("cannot get pipe to stdin: %v", err)
3230
}
3331

32+
// write in cmd.Stdin
3433
go func() {
3534
defer w.Close()
3635
_, err = io.Copy(w, os.Stdin)
@@ -41,6 +40,7 @@ func main() {
4140

4241
cmd.Stdout = os.Stdout
4342
cmd.Stderr = os.Stderr
43+
4444
err = cmd.Wait()
4545
if err != nil {
4646
log.Fatalf("cannot wait command: %v", err)

0 commit comments

Comments
 (0)