forked from radu-matei/kube-exec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
43 lines (33 loc) · 709 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"io"
"log"
"os"
kube "github.com/engineerd/kube-exec"
)
func main() {
cfg := kube.Config{
Kubeconfig: os.Getenv("KUBECONFIG"),
Image: "ubuntu",
Name: "kube-attach",
Namespace: "default",
}
cmd := kube.Command(cfg, "/bin/sh", "-c", "while true; read test; do echo You said: $test; sleep .5; done")
w, err := cmd.StdinPipe()
if err != nil {
log.Fatalf("cannot get pipe to stdin: %v", err)
}
// write in cmd.Stdin
go func() {
defer w.Close()
_, err = io.Copy(w, os.Stdin)
if err != nil {
log.Fatalf("cannot copy from stdin: %v", err)
}
}()
cmd.Stdout = os.Stdout
err = cmd.Run()
if err != nil {
log.Fatalf("error: %v", err)
}
}