-
Notifications
You must be signed in to change notification settings - Fork 1
/
pod.go
47 lines (42 loc) · 916 Bytes
/
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
package forward
import (
"fmt"
"time"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func Pod(spec Spec) *v1.Pod {
return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "port-forward-remote-",
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: "socat",
Image: "alpine/socat",
Command: command(spec.Timeout, []string{
"socat",
fmt.Sprintf("tcp-listen:%d,fork,reuseaddr", spec.RemotePort),
fmt.Sprintf("tcp-connect:%s:%d", spec.RemoteHost, spec.RemotePort),
}),
Ports: []v1.ContainerPort{
{
Name: "forwarded",
ContainerPort: int32(spec.RemotePort),
},
},
},
},
},
}
}
func command(timeout time.Duration, args []string) []string {
if timeout == 0 {
return args
}
return append([]string{
"timeout",
fmt.Sprintf("%fs", timeout.Seconds()),
}, args...)
}