Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Aug 27, 2024
1 parent a878d0a commit ebd747b
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions pkg/kwokctl/runtime/compose/cluster_expose_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"net"
"strings"
"os"

"sigs.k8s.io/kwok/pkg/apis/internalversion"
"sigs.k8s.io/kwok/pkg/consts"
Expand All @@ -38,6 +37,11 @@ func (c *Cluster) ExposePort(ctx context.Context, name string, portName string,
return err
}

kwokController, err := c.GetComponent(ctx, consts.ComponentKwokController)
if err != nil {
return err
}

port, ok := slices.Find(component.Ports, func(port internalversion.Port) bool {
return port.Name == portName
})
Expand All @@ -62,16 +66,19 @@ func (c *Cluster) ExposePort(ctx context.Context, name string, portName string,
return err
}

args := []string{"run",
"--rm",
"-i",
"--pull=never",
"--network=" + c.networkName(),
"--entrypoint=/usr/bin/nc",
kwokController.Image,
c.Name() + "-" + name, format.String(port.Port),
}

go func() {
ctx0 := exec.WithIOStreams(ctx,
exec.IOStreams{
In: conn,
Out: conn,
ErrOut: os.Stderr,
})
err := c.Exec(ctx0,
c.runtime, "exec", "-i", c.Name()+"-"+consts.ComponentKwokController,
"nc", c.Name()+"-"+name, format.String(port.Port))
err = c.Exec(exec.WithReadWriter(ctx, conn),
c.runtime, args...)
if err != nil {
logger.Warn("failed tunneling port", "err", err)
}
Expand Down

0 comments on commit ebd747b

Please sign in to comment.