-
Notifications
You must be signed in to change notification settings - Fork 5
/
portforward_pod.go
92 lines (82 loc) · 2.13 KB
/
portforward_pod.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"bytes"
"context"
"fmt"
"log"
"github.com/forbearing/k8s/pod"
"github.com/forbearing/k8s/util/errors"
)
func PortForward_Pod() {
handler := pod.NewOrDie(context.Background(), "", namespace)
//defer cleanup(handler)
if _, err := handler.Create(filename); errors.IgnoreAlreadyExists(err) != nil {
log.Fatal(err)
}
fmt.Println(handler.IsReady(name)) // false
handler.WaitReady(name)
fmt.Println(handler.IsReady(name)) // true
log.Println("PortForward")
if err := handler.PortForward(name, 8080, 80); err != nil {
log.Fatal(err)
}
if err := handler.PortForward(name, 8080, 80); err != nil {
log.Fatal(err)
}
if err := handler.PortForward(name, 8080, 80); err != nil {
log.Fatal(err)
}
if err := handler.PortForward(name, 8080, 80); err != nil {
log.Fatal(err)
}
// Output
//false
//true
//Forwarding from 127.0.0.1:8080 -> 80
//Forwarding from [::1]:8080 -> 80
//Handling connection for 8080
//Handling connection for 8080
//Handling connection for 8080
//Handling connection for 8080
//if err := handler.PortForward(name, 8080, 80); err != nil {
// log.Fatal(err)
//}
fmt.Println()
log.Println("PortForwardWithStream")
stdout, stderr := new(bytes.Buffer), new(bytes.Buffer)
if err := handler.PortForwardWithStream(name, 8080, 80, stdout, stderr); err != nil {
log.Fatal(err)
}
fmt.Println(stdout)
fmt.Println(stderr)
stdout.Reset()
stderr.Reset()
if err := handler.PortForwardWithStream(name, 8080, 80, stdout, stderr); err != nil {
log.Fatal(err)
}
fmt.Println(stdout)
fmt.Println(stderr)
stdout.Reset()
stderr.Reset()
if err := handler.PortForwardWithStream(name, 8080, 80, stdout, stderr); err != nil {
log.Fatal(err)
}
fmt.Println(stdout)
fmt.Println(stderr)
stdout.Reset()
stderr.Reset()
if err := handler.PortForwardWithStream(name, 8080, 80, stdout, stderr); err != nil {
log.Fatal(err)
}
fmt.Println(stdout)
fmt.Println(stderr)
// Output:
//true
//true
//^CForwarding from 127.0.0.1:8080 -> 80
//Forwarding from [::1]:8080 -> 80
//Handling connection for 8080
//Handling connection for 8080
//Handling connection for 8080
//Handling connection for 8080
}