Skip to content

Commit

Permalink
add node-internal-dns/node-external-dns address pass-through support (k…
Browse files Browse the repository at this point in the history
…3s-io#10852)

* add --node-internal-dns and --node-external-dns

Signed-off-by: Arne Winter <[email protected]>
Co-authored-by: Brad Davidson <[email protected]>
(cherry picked from commit c4c11e5)
Signed-off-by: Brad Davidson <[email protected]>
  • Loading branch information
arnemileswinter and brandond committed Dec 11, 2024
1 parent 75b6304 commit 93565e9
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,18 @@ 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

var nodeInternalDNSs []string
for _, dnsString := range envInfo.NodeInternalDNS.Value() {
nodeInternalDNSs = append(nodeInternalDNSs, strings.Split(dnsString, ",")...)
}
nodeConfig.AgentConfig.NodeInternalDNSs = nodeInternalDNSs

nodeConfig.NoFlannel = nodeConfig.FlannelBackend == config.FlannelBackendNone
if !nodeConfig.NoFlannel {
hostLocal, err := exec.LookPath("host-local")
Expand Down
11 changes: 11 additions & 0 deletions pkg/agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,17 @@ func updateAddressAnnotations(nodeConfig *daemonconfig.Node, nodeAnnotations map
}
}

if len(agentConfig.NodeInternalDNSs) > 0 {
result[cp.InternalDNSKey] = strings.Join(agentConfig.NodeInternalDNSs, ",")
} else {
delete(result, cp.InternalDNSKey)
}
if len(agentConfig.NodeExternalDNSs) > 0 {
result[cp.ExternalDNSKey] = strings.Join(agentConfig.NodeExternalDNSs, ",")
} else {
delete(result, cp.ExternalDNSKey)
}

result = labels.Merge(nodeAnnotations, result)
return result, !equality.Semantic.DeepEqual(nodeAnnotations, result)
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/cli/cmds/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type Agent struct {
BindAddress string
NodeIP cli.StringSlice
NodeExternalIP cli.StringSlice
NodeInternalDNS cli.StringSlice
NodeExternalDNS cli.StringSlice
NodeName string
PauseImage string
Snapshotter string
Expand Down Expand Up @@ -81,6 +83,16 @@ var (
Usage: "(agent/networking) IPv4/IPv6 external IP addresses to advertise for node",
Value: &AgentConfig.NodeExternalIP,
}
NodeInternalDNSFlag = &cli.StringSliceFlag{
Name: "node-internal-dns",
Usage: "(agent/networking) internal DNS addresses to advertise for node",
Value: &AgentConfig.NodeInternalDNS,
}
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 @@ -302,6 +314,8 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
NodeIPFlag,
BindAddressFlag,
NodeExternalIPFlag,
NodeInternalDNSFlag,
NodeExternalDNSFlag,
ResolvConfFlag,
FlannelIfaceFlag,
FlannelConfFlag,
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/cmds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ var ServerFlags = []cli.Flag{
AirgapExtraRegistryFlag,
NodeIPFlag,
NodeExternalIPFlag,
NodeInternalDNSFlag,
NodeExternalDNSFlag,
ResolvConfFlag,
FlannelIfaceFlag,
FlannelConfFlag,
Expand Down
16 changes: 16 additions & 0 deletions pkg/cloudprovider/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
var (
InternalIPKey = version.Program + ".io/internal-ip"
ExternalIPKey = version.Program + ".io/external-ip"
InternalDNSKey = version.Program + ".io/internal-dns"
ExternalDNSKey = version.Program + ".io/external-dns"
HostnameKey = version.Program + ".io/hostname"
)

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

// check internal dns
if address := node.Annotations[InternalDNSKey]; address != "" {
for _, v := range strings.Split(address, ",") {
metadata.NodeAddresses = append(metadata.NodeAddresses, corev1.NodeAddress{Type: corev1.NodeInternalDNS, Address: v})
}
}

// 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})
}
}

// 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 @@ -125,6 +125,8 @@ type Agent struct {
NodeIPs []net.IP
NodeExternalIP string
NodeExternalIPs []net.IP
NodeInternalDNSs []string
NodeExternalDNSs []string
RuntimeSocket string
ImageServiceSocket string
ListenAddress string
Expand Down

0 comments on commit 93565e9

Please sign in to comment.