Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add node-internal-dns/node-external-dns address pass-through support #10852

Merged
merged 9 commits into from
Sep 6, 2024
12 changes: 12 additions & 0 deletions pkg/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
if len(envInfo.NodeExternalIP) != 0 {
logrus.Warn("VPN provider overrides node-external-ip parameter")
}
if len(envInfo.NodeExternalDNS) != 0 {
logrus.Warn("VPN provider overrides node-external-dns parameter")
brandond marked this conversation as resolved.
Show resolved Hide resolved
}
nodeIPs = vpnIPs
flannelIface, err = net.InterfaceByName(vpnInfo.VPNInterface)
if err != nil {
Expand Down Expand Up @@ -630,6 +633,15 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
nodeConfig.AgentConfig.NodeExternalIP = nodeConfig.AgentConfig.NodeExternalIPs[0].String()
}

var nodeExternalDNSs []string
for _, dnsString := range envInfo.NodeExternalDNS.Value() {
nodeExternalDNSs = append(nodeExternalDNSs, strings.Split(dnsString, ",")...)
}
nodeConfig.AgentConfig.NodeExternalDNSs = nodeExternalDNSs
if len(nodeConfig.AgentConfig.NodeExternalDNSs) > 0 {
nodeConfig.AgentConfig.NodeExternalDNS = nodeConfig.AgentConfig.NodeExternalDNSs[0]
}
brandond marked this conversation as resolved.
Show resolved Hide resolved

nodeConfig.NoFlannel = nodeConfig.FlannelBackend == config.FlannelBackendNone
if !nodeConfig.NoFlannel {
hostLocal, err := exec.LookPath("host-local")
Expand Down
1 change: 1 addition & 0 deletions pkg/agent/flannel/flannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var (
FlannelBaseAnnotation = "flannel.alpha.coreos.com"
FlannelExternalIPv4Annotation = FlannelBaseAnnotation + "/public-ip-overwrite"
FlannelExternalIPv6Annotation = FlannelBaseAnnotation + "/public-ipv6-overwrite"
FlannelExternalDNSAnnotation = FlannelBaseAnnotation + "/public-dns-overwrite"
brandond marked this conversation as resolved.
Show resolved Hide resolved
)

func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kubeConfigFile string, flannelIPv6Masq bool, netMode int) error {
Expand Down
9 changes: 9 additions & 0 deletions pkg/agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,15 @@ func updateAddressAnnotations(nodeConfig *daemonconfig.Node, nodeAnnotations map
}
}

if agentConfig.NodeExternalDNS != "" {
brandond marked this conversation as resolved.
Show resolved Hide resolved
result[cp.ExternalDNSKey] = strings.Join(agentConfig.NodeExternalDNSs, ",")
if nodeConfig.FlannelExternalIP {
for _, dns := range agentConfig.NodeExternalDNSs {
result[flannel.FlannelExternalDNSAnnotation] = dns
brandond marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

result = labels.Merge(nodeAnnotations, result)
return result, !equality.Semantic.DeepEqual(nodeAnnotations, result)
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/cli/cmds/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Agent struct {
BindAddress string
NodeIP cli.StringSlice
NodeExternalIP cli.StringSlice
NodeExternalDNS cli.StringSlice
NodeName string
PauseImage string
Snapshotter string
Expand Down Expand Up @@ -80,6 +81,11 @@ var (
Usage: "(agent/networking) IPv4/IPv6 external IP addresses to advertise for node",
Value: &AgentConfig.NodeExternalIP,
}
NodeExternalDNSFlag = &cli.StringSliceFlag{
Name: "node-external-dns",
Usage: "(agent/networking) external DNS addresses to advertise for node",
Value: &AgentConfig.NodeExternalDNS,
}
NodeNameFlag = &cli.StringFlag{
Name: "node-name",
Usage: "(agent/node) Node name",
Expand Down Expand Up @@ -295,6 +301,7 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
NodeIPFlag,
BindAddressFlag,
NodeExternalIPFlag,
NodeExternalDNSFlag,
ResolvConfFlag,
FlannelIfaceFlag,
FlannelConfFlag,
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/cmds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ var ServerFlags = []cli.Flag{
AirgapExtraRegistryFlag,
NodeIPFlag,
NodeExternalIPFlag,
NodeExternalDNSFlag,
ResolvConfFlag,
FlannelIfaceFlag,
FlannelConfFlag,
Expand Down
10 changes: 10 additions & 0 deletions pkg/cloudprovider/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
var (
InternalIPKey = version.Program + ".io/internal-ip"
ExternalIPKey = version.Program + ".io/external-ip"
ExternalDNSKey = version.Program + ".io/external-dns"
brandond marked this conversation as resolved.
Show resolved Hide resolved
HostnameKey = version.Program + ".io/hostname"
)

Expand Down Expand Up @@ -79,6 +80,15 @@ func (k *k3s) InstanceMetadata(ctx context.Context, node *corev1.Node) (*cloudpr
metadata.NodeAddresses = append(metadata.NodeAddresses, corev1.NodeAddress{Type: corev1.NodeExternalIP, Address: address})
}

// check external dns
if address := node.Annotations[ExternalDNSKey]; address != "" {
for _, v := range strings.Split(address, ",") {
metadata.NodeAddresses = append(metadata.NodeAddresses, corev1.NodeAddress{Type: corev1.NodeExternalDNS, Address: v})
}
} else if address = node.Labels[ExternalDNSKey]; address != "" {
metadata.NodeAddresses = append(metadata.NodeAddresses, corev1.NodeAddress{Type: corev1.NodeExternalDNS, Address: address})
arnemileswinter marked this conversation as resolved.
Show resolved Hide resolved
}

// check hostname
if address := node.Annotations[HostnameKey]; address != "" {
metadata.NodeAddresses = append(metadata.NodeAddresses, corev1.NodeAddress{Type: corev1.NodeHostName, Address: address})
Expand Down
2 changes: 2 additions & 0 deletions pkg/daemons/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ type Agent struct {
NodeIPs []net.IP
NodeExternalIP string
NodeExternalIPs []net.IP
NodeExternalDNS string
NodeExternalDNSs []string
RuntimeSocket string
ImageServiceSocket string
ListenAddress string
Expand Down