Getting rid of socat
Signed-off-by: abhi <abhi@docker.com>
This commit is contained in:
parent
aeef99a76e
commit
02b952ec17
@ -17,11 +17,10 @@ limitations under the License.
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"net"
|
||||||
"strings"
|
"sync"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -34,7 +33,6 @@ import (
|
|||||||
|
|
||||||
// PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address.
|
// PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address.
|
||||||
func (c *criService) PortForward(ctx context.Context, r *runtime.PortForwardRequest) (retRes *runtime.PortForwardResponse, retErr error) {
|
func (c *criService) PortForward(ctx context.Context, r *runtime.PortForwardRequest) (retRes *runtime.PortForwardResponse, retErr error) {
|
||||||
// TODO(random-liu): Run a socat container inside the sandbox to do portforward.
|
|
||||||
sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId())
|
sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to find sandbox %q", r.GetPodSandboxId())
|
return nil, errors.Wrapf(err, "failed to find sandbox %q", r.GetPodSandboxId())
|
||||||
@ -53,34 +51,32 @@ func (c *criService) portForward(id string, port int32, stream io.ReadWriteClose
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to find sandbox %q in store", id)
|
return errors.Wrapf(err, "failed to find sandbox %q in store", id)
|
||||||
}
|
}
|
||||||
if s.NetNS == nil {
|
if s.NetNS == nil || s.NetNS.Closed() {
|
||||||
return errors.Errorf("failed to find network namespace fo sandbox %q in store", id)
|
return errors.Errorf("network namespace for sandbox %q is closed", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.NetNS.GetNs().Do(func(_ ns.NetNS) error {
|
err = s.NetNS.GetNs().Do(func(_ ns.NetNS) error {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
client, err := net.Dial("tcp4", fmt.Sprintf("localhost:%d", port))
|
client, err := net.Dial("tcp4", fmt.Sprintf("localhost:%d", port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to dial")
|
return errors.Wrapf(err, "failed to dial %q", port)
|
||||||
}
|
}
|
||||||
defer client.Close()
|
|
||||||
defer stream.Close()
|
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
|
defer client.Close()
|
||||||
if _, err := io.Copy(client, stream); err != nil {
|
if _, err := io.Copy(client, stream); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to copy port forward input from %q port %d", id, port)
|
logrus.WithError(err).Errorf("Failed to copy port forward input for %q port %d", id, port)
|
||||||
}
|
}
|
||||||
logrus.Infof("Finish copy port forward input for %q port %d: %v", id, port)
|
logrus.Infof("Finish copy port forward input for %q port %d", id, port)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
|
defer stream.Close()
|
||||||
if _, err := io.Copy(stream, client); err != nil {
|
if _, err := io.Copy(stream, client); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to copy port forward output for %q port %d", id, port)
|
logrus.WithError(err).Errorf("Failed to copy port forward output for %q port %d", id, port)
|
||||||
}
|
}
|
||||||
logrus.Infof("Finish copy port forward output for %q port %d: %v", id, port)
|
logrus.Infof("Finish copy port forward output for %q port %d", id, port)
|
||||||
|
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
Loading…
Reference in New Issue
Block a user