1
0
mirror of https://github.com/rancher/os.git synced 2025-06-27 15:26:50 +00:00

Add dhcp timeout parameter

This commit is contained in:
Jason-ZW 2018-10-22 10:11:12 +08:00 committed by niusmallnan
parent a088811de9
commit ef663b4e70
7 changed files with 31 additions and 7 deletions

View File

@ -284,12 +284,18 @@ func getDatasources(datasources []string) []datasource.Datasource {
} }
func enableDoLinkLocal() { func enableDoLinkLocal() {
cfg := rancherConfig.LoadConfig()
dhcpTimeout := cfg.Rancher.Defaults.Network.DHCPTimeout
if cfg.Rancher.Network.DHCPTimeout > 0 {
dhcpTimeout = cfg.Rancher.Network.DHCPTimeout
}
_, err := netconf.ApplyNetworkConfigs(&netconf.NetworkConfig{ _, err := netconf.ApplyNetworkConfigs(&netconf.NetworkConfig{
Interfaces: map[string]netconf.InterfaceConfig{ Interfaces: map[string]netconf.InterfaceConfig{
"eth0": { "eth0": {
IPV4LL: true, IPV4LL: true,
}, },
}, },
DHCPTimeout: dhcpTimeout,
}, false, false) }, false, false)
if err != nil { if err != nil {
log.Errorf("Failed to apply link local on eth0: %v", err) log.Errorf("Failed to apply link local on eth0: %v", err)

View File

@ -42,6 +42,9 @@ func ApplyNetworkConfig(cfg *config.CloudConfig) {
} }
userSetHostname := cfg.Hostname != "" userSetHostname := cfg.Hostname != ""
if cfg.Rancher.Network.DHCPTimeout <= 0 {
cfg.Rancher.Network.DHCPTimeout = cfg.Rancher.Defaults.Network.DHCPTimeout
}
dhcpSetDNS, err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network, userSetHostname, userSetDNS) dhcpSetDNS, err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network, userSetHostname, userSetDNS)
if err != nil { if err != nil {
log.Errorf("Failed to apply network configs(by netconf): %v", err) log.Errorf("Failed to apply network configs(by netconf): %v", err)

View File

@ -81,6 +81,7 @@ var schema = `{
"properties": { "properties": {
"pre_cmds": {"$ref": "#/definitions/list_of_strings"}, "pre_cmds": {"$ref": "#/definitions/list_of_strings"},
"dhcp_timeout": {"type": "integer"},
"dns": {"type": "object"}, "dns": {"type": "object"},
"interfaces": {"type": "object"}, "interfaces": {"type": "object"},
"post_cmds": {"$ref": "#/definitions/list_of_strings"}, "post_cmds": {"$ref": "#/definitions/list_of_strings"},

View File

@ -14,6 +14,7 @@ rancher:
engine: docker-18.03.1-ce engine: docker-18.03.1-ce
{{end -}} {{end -}}
network: network:
dhcp_timeout: 10
dns: dns:
nameservers: [8.8.8.8, 8.8.4.4] nameservers: [8.8.8.8, 8.8.4.4]
system_docker_logs: /var/log/system-docker.log system_docker_logs: /var/log/system-docker.log

View File

@ -13,6 +13,13 @@ func CloudInit(cfg *config.CloudConfig) (*config.CloudConfig, error) {
stateConfig := config.LoadConfigWithPrefix(config.StateDir) stateConfig := config.LoadConfigWithPrefix(config.StateDir)
cfg.Rancher.CloudInit.Datasources = stateConfig.Rancher.CloudInit.Datasources cfg.Rancher.CloudInit.Datasources = stateConfig.Rancher.CloudInit.Datasources
if stateConfig.Rancher.Network.DHCPTimeout > 0 {
cfg.Rancher.Network.DHCPTimeout = stateConfig.Rancher.Network.DHCPTimeout
if err := config.Set("rancher.network.dhcp_timeout", stateConfig.Rancher.Network.DHCPTimeout); err != nil {
log.Error(err)
}
}
if len(stateConfig.Rancher.Network.Interfaces) > 0 { if len(stateConfig.Rancher.Network.Interfaces) > 0 {
cfg.Rancher.Network = stateConfig.Rancher.Network cfg.Rancher.Network = stateConfig.Rancher.Network
if err := config.Set("rancher.network", stateConfig.Rancher.Network); err != nil { if err := config.Set("rancher.network", stateConfig.Rancher.Network); err != nil {

View File

@ -6,6 +6,7 @@ import (
"net" "net"
"os" "os"
"os/exec" "os/exec"
"strconv"
"strings" "strings"
"sync" "sync"
"syscall" "syscall"
@ -290,6 +291,10 @@ func runDhcp(netCfg *NetworkConfig, iface string, argstr string, setHostname, se
args = append(args, "--nohook", "resolv.conf") args = append(args, "--nohook", "resolv.conf")
} }
if netCfg.DHCPTimeout > 0 {
args = append(args, "--timeout", strconv.Itoa(netCfg.DHCPTimeout))
}
// Wait for lease // Wait for lease
// TODO: this should be optional - based on kernel arg? // TODO: this should be optional - based on kernel arg?
args = append(args, "-w", "--debug") args = append(args, "-w", "--debug")

View File

@ -1,13 +1,14 @@
package netconf package netconf
type NetworkConfig struct { type NetworkConfig struct {
PreCmds []string `yaml:"pre_cmds,omitempty"` PreCmds []string `yaml:"pre_cmds,omitempty"`
DNS DNSConfig `yaml:"dns,omitempty"` DHCPTimeout int `yaml:"dhcp_timeout,omitempty"`
Interfaces map[string]InterfaceConfig `yaml:"interfaces,omitempty"` DNS DNSConfig `yaml:"dns,omitempty"`
PostCmds []string `yaml:"post_cmds,omitempty"` Interfaces map[string]InterfaceConfig `yaml:"interfaces,omitempty"`
HTTPProxy string `yaml:"http_proxy,omitempty"` PostCmds []string `yaml:"post_cmds,omitempty"`
HTTPSProxy string `yaml:"https_proxy,omitempty"` HTTPProxy string `yaml:"http_proxy,omitempty"`
NoProxy string `yaml:"no_proxy,omitempty"` HTTPSProxy string `yaml:"https_proxy,omitempty"`
NoProxy string `yaml:"no_proxy,omitempty"`
} }
type InterfaceConfig struct { type InterfaceConfig struct {