mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-21 20:22:41 +09:00
cmd/k8s-proxy: listen on the PORT that the operator sets
For kube-apiserver ProxyGroups with static endpoints, the operator sets PORT on the k8s-proxy container to the targetPort of the NodePort Services behind the advertised endpoints. k8s-proxy never read PORT, so tsnet listened on a random port and traffic to the static endpoints was forwarded to a port with nothing listening. Peers stayed on DERP. This fixes this by parsing PORT and setting it as tsnet.Server.Port. Thanks to @icheishvili (#18841) and @rquitales (#21716), whose changes this is based on. Updates #21714 Signed-off-by: chaosinthecrd <tom@tmlabs.co.uk>
This commit is contained in:
1 parent
36d2564bd4
commit
7ce5547382
1 file changed
+21
@@ -80,6 +80,7 @@ func run(logger *zap.SugaredLogger) error {
|
||||
configPath = os.Getenv("TS_K8S_PROXY_CONFIG")
|
||||
podUID = os.Getenv("POD_UID")
|
||||
podIP = os.Getenv("POD_IP")
|
||||
port = os.Getenv("PORT")
|
||||
)
|
||||
if configPath == "" {
|
||||
return errors.New("TS_K8S_PROXY_CONFIG unset")
|
||||
@@ -205,11 +206,18 @@ func run(logger *zap.SugaredLogger) error {
|
||||
authKey = *cfg.Parsed.AuthKey
|
||||
}
|
||||
|
||||
// PORT is the static endpoint NodePort targetPort; WireGuard must listen on it.
|
||||
tsPort, err := parsePort(port)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ts := &tsnet.Server{
|
||||
Logf: logger.Named("tsnet").Debugf,
|
||||
UserLogf: logger.Named("tsnet").Infof,
|
||||
Store: st,
|
||||
AuthKey: authKey,
|
||||
Port: tsPort,
|
||||
}
|
||||
|
||||
if cfg.Parsed.ServerURL != nil {
|
||||
@@ -448,6 +456,19 @@ func getLocalAddrPort(addr string, port uint16) string {
|
||||
return net.JoinHostPort(addr, strconv.FormatUint(uint64(port), 10))
|
||||
}
|
||||
|
||||
// parsePort parses the PORT env var. It returns 0 if PORT is unset, so tsnet
|
||||
// picks a random port.
|
||||
func parsePort(p string) (uint16, error) {
|
||||
if p == "" {
|
||||
return 0, nil
|
||||
}
|
||||
port, err := strconv.ParseUint(p, 10, 16)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to parse PORT %q: %w", p, err)
|
||||
}
|
||||
return uint16(port), nil
|
||||
}
|
||||
|
||||
func getStateStore(path *string, logger *zap.SugaredLogger) (ipn.StateStore, error) {
|
||||
p := "mem:"
|
||||
if path != nil {
|
||||
|
||||
Reference in new issue
Block a user