Repository: k3s-io/k3s
File: pkg/agent/config/config.go (Go)

Code before:
	} else {
		listenAddress, _, _, err := util.GetDefaultAddresses(nodeIPs[0])
		if err != nil {
			return nil, errors.Wrap(err, "cannot configure IPv4/IPv6 node-ip")
		}
		nodeConfig.AgentConfig.ListenAddress = listenAddress
	}

	nodeConfig.AgentConfig.NodeIP = nodeIPs[0].String()
	nodeConfig.AgentConfig.NodeIPs = nodeIPs
	nodeConfig.AgentConfig.NodeExternalIPs = nodeExternalIPs

	// if configured, set NodeExternalIP to the first IPv4 address, for legacy clients
	// unless only IPv6 address given
	if len(nodeConfig.AgentConfig.NodeExternalIPs) > 0 {
		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]
	}

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

	nodeConfig.NoFlannel = nodeConfig.FlannelBackend == config.FlannelBackendNone
	if !nodeConfig.NoFlannel {
		hostLocal, err := exec.LookPath("host-local")
		if err != nil {
			return nil, errors.Wrapf(err, "failed to find host-local")
		}

		if envInfo.FlannelConf == "" {
			nodeConfig.FlannelConfFile = filepath.Join(envInfo.DataDir, "agent", "etc", "flannel", "net-conf.json")
		} else {
			nodeConfig.FlannelConfFile = envInfo.FlannelConf
			nodeConfig.FlannelConfOverride = true
		}
		nodeConfig.AgentConfig.CNIBinDir = filepath.Dir(hostLocal)
		nodeConfig.AgentConfig.CNIConfDir = filepath.Join(envInfo.DataDir, "agent", "etc", "cni", "net.d")

Review comment (suggestion):
you don't need to do this. The NodeInternalIP/NodeExternalIP options used to take only a single value, so we had to maintain backwards compatibility for that by passing the first list value into the old single-valued variable.

Get rid of `NodeExternalDNS` and `NodeInternalDNS` entirely.

Code after:
	} else {
		listenAddress, _, _, err := util.GetDefaultAddresses(nodeIPs[0])
		if err != nil {
			return nil, errors.Wrap(err, "cannot configure IPv4/IPv6 node-ip")
		}
		nodeConfig.AgentConfig.ListenAddress = listenAddress
	}

	nodeConfig.AgentConfig.NodeIP = nodeIPs[0].String()
	nodeConfig.AgentConfig.NodeIPs = nodeIPs
	nodeConfig.AgentConfig.NodeExternalIPs = nodeExternalIPs

	// if configured, set NodeExternalIP to the first IPv4 address, for legacy clients
	// unless only IPv6 address given
	if len(nodeConfig.AgentConfig.NodeExternalIPs) > 0 {
		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")
		if err != nil {
			return nil, errors.Wrapf(err, "failed to find host-local")
		}

		if envInfo.FlannelConf == "" {
			nodeConfig.FlannelConfFile = filepath.Join(envInfo.DataDir, "agent", "etc", "flannel", "net-conf.json")
		} else {
			nodeConfig.FlannelConfFile = envInfo.FlannelConf
			nodeConfig.FlannelConfOverride = true
		}
		nodeConfig.AgentConfig.CNIBinDir = filepath.Dir(hostLocal)
		nodeConfig.AgentConfig.CNIConfDir = filepath.Join(envInfo.DataDir, "agent", "etc", "cni", "net.d")
		nodeConfig.AgentConfig.FlannelCniConfFile = envInfo.FlannelCniConfFile

		// It does not make sense to use VPN without its flannel backend
		if envInfo.VPNAuth != "" {
			nodeConfig.FlannelBackend = vpnInfo.ProviderName
		}