Skip to content

Commit

Permalink
Use IPv6 in case is the first configured IP with dualstack
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Bonafiglia <[email protected]>
  • Loading branch information
rbrtbnfgl committed Oct 10, 2023
1 parent ced25af commit d88ff46
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N

// If the supervisor and externally-facing apiserver are not on the same port, tell the proxy where to find the apiserver.
if controlConfig.SupervisorPort != controlConfig.HTTPSPort {
_, isIPv6, _ := util.GetFirstString([]string{envInfo.NodeIP.String()})
isIPv6 := utilsnet.IsIPv6(net.ParseIP([]string{envInfo.NodeIP.String()}[0]))
if err := proxy.SetAPIServerPort(ctx, controlConfig.HTTPSPort, isIPv6); err != nil {
return nil, errors.Wrapf(err, "failed to setup access to API Server port %d on at %s", controlConfig.HTTPSPort, proxy.SupervisorURL())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func createProxyAndValidateToken(ctx context.Context, cfg *cmds.Agent) (proxy.Pr
if err := os.MkdirAll(agentDir, 0700); err != nil {
return nil, err
}
_, isIPv6, _ := util.GetFirstString([]string{cfg.NodeIP.String()})
isIPv6 := utilsnet.IsIPv6(net.ParseIP([]string{cfg.NodeIP.String()}[0]))

proxy, err := proxy.NewSupervisorProxy(ctx, !cfg.DisableLoadBalancer, agentDir, cfg.ServerURL, cfg.LBServerPort, isIPv6)
if err != nil {
Expand Down
20 changes: 12 additions & 8 deletions pkg/daemons/agent/agent_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package agent

import (
"net"
"os"
"path/filepath"
"strings"
Expand All @@ -13,8 +14,8 @@ import (
"github.com/k3s-io/k3s/pkg/util"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
"k8s.io/apimachinery/pkg/util/net"
"k8s.io/kubernetes/pkg/kubeapiserver/authorizer/modes"
utilsnet "k8s.io/utils/net"
)

const socketPrefix = "unix://"
Expand All @@ -32,8 +33,8 @@ func createRootlessConfig(argsMap map[string]string, controllers map[string]bool

func kubeProxyArgs(cfg *config.Agent) map[string]string {
bindAddress := "127.0.0.1"
_, IPv6only, _ := util.GetFirstString([]string{cfg.NodeIP})
if IPv6only {
isIPv6 := utilsnet.IsIPv6(net.ParseIP([]string{cfg.NodeIP}[0]))
if isIPv6 {
bindAddress = "::1"
}
argsMap := map[string]string{
Expand All @@ -53,8 +54,8 @@ func kubeProxyArgs(cfg *config.Agent) map[string]string {

func kubeletArgs(cfg *config.Agent) map[string]string {
bindAddress := "127.0.0.1"
_, IPv6only, _ := util.GetFirstString([]string{cfg.NodeIP})
if IPv6only {
isIPv6 := utilsnet.IsIPv6(net.ParseIP([]string{cfg.NodeIP}[0]))
if isIPv6 {
bindAddress = "::1"
}
argsMap := map[string]string{
Expand Down Expand Up @@ -122,9 +123,12 @@ func kubeletArgs(cfg *config.Agent) map[string]string {
if cfg.NodeName != "" {
argsMap["hostname-override"] = cfg.NodeName
}
defaultIP, err := net.ChooseHostInterface()
if err != nil || defaultIP.String() != cfg.NodeIP {
argsMap["node-ip"] = cfg.NodeIP
if nodeIPs := util.JoinIPs(cfg.NodeIPs); nodeIPs != "" {
dualStack, err := utilsnet.IsDualStackIPs(cfg.NodeIPs)
if err == nil && dualStack {
argsMap["feature-gates"] = util.AddFeatureGate(argsMap["feature-gates"], "CloudDualStackNodeIPs=true")
}
argsMap["node-ip"] = nodeIPs
}
kubeletRoot, runtimeRoot, controllers := cgroups.CheckCgroups()
if !controllers["cpu"] {
Expand Down
3 changes: 0 additions & 3 deletions tests/e2e/dualstack/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def provision(vm, role, role_num, node_num)
service-cidr: 10.43.0.0/16,2001:cafe:42:1::/112
bind-address: #{NETWORK4_PREFIX}.100
flannel-iface: eth1
kubelet-arg: "--node-ip=0.0.0.0" # Workaround for https://github.com/kubernetes/kubernetes/issues/111695
YAML
k3s.env = ["K3S_KUBECONFIG_MODE=0644", install_type]
end
Expand All @@ -66,7 +65,6 @@ def provision(vm, role, role_num, node_num)
cluster-cidr: 10.42.0.0/16,2001:cafe:42:0::/56
service-cidr: 10.43.0.0/16,2001:cafe:42:1::/112
flannel-iface: eth1
kubelet-arg: "--node-ip=0.0.0.0" # Workaround for https://github.com/kubernetes/kubernetes/issues/111695
YAML
k3s.env = ["K3S_KUBECONFIG_MODE=0644", install_type]
end
Expand All @@ -81,7 +79,6 @@ def provision(vm, role, role_num, node_num)
server: https://#{NETWORK4_PREFIX}.100:6443
token: vagrant
flannel-iface: eth1
kubelet-arg: "--node-ip=0.0.0.0" # Workaround for https://github.com/kubernetes/kubernetes/issues/111695
YAML
k3s.env = ["K3S_KUBECONFIG_MODE=0644", install_type]
end
Expand Down

0 comments on commit d88ff46

Please sign in to comment.