mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #32126 from intelsdi-x/kvm_fw
Automatic merge from submit-queue Add port forwarding for rkt with kvm stage1 Port forwarding for rkt kvm using `socat`. cc @yifan-gu @euank @pskrzyns @lukasredynk
This commit is contained in:
commit
5b609f212c
34
pkg/kubelet/rkt/rkt.go
Normal file → Executable file
34
pkg/kubelet/rkt/rkt.go
Normal file → Executable file
@ -2102,7 +2102,6 @@ func (r *Runtime) ExecInContainer(containerID kubecontainer.ContainerID, cmd []s
|
|||||||
// - should we support nsenter + socat in a container, running with elevated privs and --pid=host?
|
// - should we support nsenter + socat in a container, running with elevated privs and --pid=host?
|
||||||
//
|
//
|
||||||
// TODO(yifan): Merge with the same function in dockertools.
|
// TODO(yifan): Merge with the same function in dockertools.
|
||||||
// TODO(yifan): If the rkt is using lkvm as the stage1 image, then this function will fail.
|
|
||||||
func (r *Runtime) PortForward(pod *kubecontainer.Pod, port uint16, stream io.ReadWriteCloser) error {
|
func (r *Runtime) PortForward(pod *kubecontainer.Pod, port uint16, stream io.ReadWriteCloser) error {
|
||||||
glog.V(4).Infof("Rkt port forwarding in container.")
|
glog.V(4).Infof("Rkt port forwarding in container.")
|
||||||
|
|
||||||
@ -2123,20 +2122,41 @@ func (r *Runtime) PortForward(pod *kubecontainer.Pod, port uint16, stream io.Rea
|
|||||||
}
|
}
|
||||||
return fmt.Errorf("more than one running rkt pod for the kubernetes pod [%s]", strings.Join(podlist, ", "))
|
return fmt.Errorf("more than one running rkt pod for the kubernetes pod [%s]", strings.Join(podlist, ", "))
|
||||||
}
|
}
|
||||||
|
listPod := listResp.Pods[0]
|
||||||
|
|
||||||
socatPath, lookupErr := exec.LookPath("socat")
|
socatPath, lookupErr := exec.LookPath("socat")
|
||||||
if lookupErr != nil {
|
if lookupErr != nil {
|
||||||
return fmt.Errorf("unable to do port forwarding: socat not found.")
|
return fmt.Errorf("unable to do port forwarding: socat not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{"-t", fmt.Sprintf("%d", listResp.Pods[0].Pid), "-n", socatPath, "-", fmt.Sprintf("TCP4:localhost:%d", port)}
|
// Check in config and in annotations if we're running kvm flavor
|
||||||
|
isKvm := strings.Contains(r.config.Stage1Image, "kvm")
|
||||||
nsenterPath, lookupErr := exec.LookPath("nsenter")
|
for _, anno := range listPod.Annotations {
|
||||||
if lookupErr != nil {
|
if anno.Key == k8sRktStage1NameAnno {
|
||||||
return fmt.Errorf("unable to do port forwarding: nsenter not found.")
|
isKvm = strings.Contains(anno.Value, "kvm")
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
command := exec.Command(nsenterPath, args...)
|
var args []string
|
||||||
|
var fwCaller string
|
||||||
|
if isKvm {
|
||||||
|
podNetworks := listPod.GetNetworks()
|
||||||
|
if podNetworks == nil {
|
||||||
|
return fmt.Errorf("unable to get networks")
|
||||||
|
}
|
||||||
|
args = []string{"-", fmt.Sprintf("TCP4:%s:%d", podNetworks[0].Ipv4, port)}
|
||||||
|
fwCaller = socatPath
|
||||||
|
} else {
|
||||||
|
args = []string{"-t", fmt.Sprintf("%d", listPod.Pid), "-n", socatPath, "-", fmt.Sprintf("TCP4:localhost:%d", port)}
|
||||||
|
nsenterPath, lookupErr := exec.LookPath("nsenter")
|
||||||
|
if lookupErr != nil {
|
||||||
|
return fmt.Errorf("unable to do port forwarding: nsenter not found")
|
||||||
|
}
|
||||||
|
fwCaller = nsenterPath
|
||||||
|
}
|
||||||
|
|
||||||
|
command := exec.Command(fwCaller, args...)
|
||||||
command.Stdout = stream
|
command.Stdout = stream
|
||||||
|
|
||||||
// If we use Stdin, command.Run() won't return until the goroutine that's copying
|
// If we use Stdin, command.Run() won't return until the goroutine that's copying
|
||||||
|
Loading…
Reference in New Issue
Block a user