Skip to content

Commit a64156e

Browse files
authored
Merge pull request #6741 from makhov/konnectivity-external-port
host:port support for konnectivity externalAddress
2 parents e959ba4 + 161855f commit a64156e

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

pkg/component/controller/konnectivityagent.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ package controller
66
import (
77
"context"
88
"fmt"
9+
"net"
910
"path/filepath"
11+
"strconv"
1012
"time"
1113

14+
"github.com/sirupsen/logrus"
15+
1216
"github.com/k0sproject/k0s/internal/pkg/dir"
1317
"github.com/k0sproject/k0s/internal/pkg/templatewriter"
1418
"github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
1519
"github.com/k0sproject/k0s/pkg/component/manager"
1620
"github.com/k0sproject/k0s/pkg/component/prober"
1721
"github.com/k0sproject/k0s/pkg/config"
1822
"github.com/k0sproject/k0s/pkg/constant"
19-
"github.com/sirupsen/logrus"
2023
)
2124

2225
type KonnectivityAgent struct {
@@ -103,11 +106,26 @@ func (k *KonnectivityAgent) writeKonnectivityAgent(clusterConfig *v1beta1.Cluste
103106
if err != nil {
104107
return err
105108
}
109+
110+
proxyServerHost := k.APIServerHost
111+
proxyServerPort := clusterConfig.Spec.Konnectivity.AgentPort
112+
113+
// We don't use k0snet.ParseHostPortWithDefault here because the API server host might be an IP
114+
// literal (IPv6). We don't want to change the current behavior and fail here. So we
115+
// just use the standard library function and change default values only if we successfully parsed host and port.
116+
host, port, _ := net.SplitHostPort(k.APIServerHost)
117+
if host != "" {
118+
proxyServerHost = host
119+
}
120+
if p, _ := strconv.Atoi(port); p != 0 {
121+
proxyServerPort = int32(p)
122+
}
123+
106124
cfg := konnectivityAgentConfig{
107125
// Since the konnectivity server runs with hostNetwork=true this is the
108126
// IP address of the master machine
109-
ProxyServerHost: k.APIServerHost,
110-
ProxyServerPort: uint16(clusterConfig.Spec.Konnectivity.AgentPort),
127+
ProxyServerHost: proxyServerHost,
128+
ProxyServerPort: uint16(proxyServerPort),
111129
Image: clusterConfig.Spec.Images.Konnectivity.URI(),
112130
ServerCount: serverCount,
113131
PullPolicy: clusterConfig.Spec.Images.DefaultPullPolicy,

0 commit comments

Comments
 (0)