Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
Move default hostname and network under common key
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwget committed Jun 1, 2016
1 parent 97344cc commit e51c540
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func Main() {
search := cfg.Rancher.Network.Dns.Search
userSetDns := len(nameservers) > 0 || len(search) > 0
if !userSetDns {
nameservers = cfg.Rancher.DefaultNetwork.Dns.Nameservers
search = cfg.Rancher.DefaultNetwork.Dns.Search
nameservers = cfg.Rancher.Defaults.Network.Dns.Nameservers
search = cfg.Rancher.Defaults.Network.Dns.Search
}

if _, err := resolvconf.Build("/etc/resolv.conf", nameservers, search, nil); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ type CloudConfig struct {
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
WriteFiles []config.File `yaml:"write_files"`
Hostname string `yaml:"hostname"`
DefaultHostname string `yaml:"default_hostname"`

Rancher RancherConfig `yaml:"rancher,omitempty"`
}
Expand All @@ -105,6 +104,7 @@ type RancherConfig struct {
SystemDocker DockerConfig `yaml:"system_docker,omitempty"`
Upgrade UpgradeConfig `yaml:"upgrade,omitempty"`
Docker DockerConfig `yaml:"docker,omitempty"`
Defaults Defaults `yaml:"defaults,omitempty"`
}

type UpgradeConfig struct {
Expand Down Expand Up @@ -148,6 +148,11 @@ type CloudInit struct {
Datasources []string `yaml:"datasources,omitempty"`
}

type Defaults struct {
Hostname string `yaml:"hostname,omitempty"`
Network netconf.NetworkConfig `yaml:"network,omitempty"`
}

func (r Repositories) ToArray() []string {
result := make([]string, 0, len(r))
for _, repo := range r {
Expand Down
5 changes: 3 additions & 2 deletions hostname/hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package hostname

import (
"bufio"
"github.com/rancher/os/config"
"io/ioutil"
"os"
"strings"
"syscall"

"github.com/rancher/os/config"
)

func SetHostnameFromCloudConfig(cc *config.CloudConfig) error {
var hostname string
if cc.Hostname == "" {
hostname = cc.DefaultHostname
hostname = cc.Rancher.Defaults.Hostname
} else {
hostname = cc.Hostname
}
Expand Down
4 changes: 2 additions & 2 deletions init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ func getLaunchConfig(cfg *config.CloudConfig, dockerCfg *config.DockerConfig) (*

args := dockerlaunch.ParseConfig(&launchConfig, append(dockerCfg.Args, dockerCfg.ExtraArgs...)...)

launchConfig.DnsConfig.Nameservers = cfg.Rancher.DefaultNetwork.Dns.Nameservers
launchConfig.DnsConfig.Search = cfg.Rancher.DefaultNetwork.Dns.Search
launchConfig.DnsConfig.Nameservers = cfg.Rancher.Defaults.Network.Dns.Nameservers
launchConfig.DnsConfig.Search = cfg.Rancher.Defaults.Network.Dns.Search
launchConfig.Environment = dockerCfg.Environment
launchConfig.EmulateSystemd = true

Expand Down
9 changes: 5 additions & 4 deletions os-config.tpl.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
default_hostname: {{.HOSTNAME_DEFAULT}}
rancher:
defaults:
hostname: {{.HOSTNAME_DEFAULT}}
network:
dns:
nameservers: [8.8.8.8, 8.8.4.4]
bootstrap:
state-script:
image: {{.OS_REPO}}/os-statescript:{{.VERSION}}{{.SUFFIX}}
Expand Down Expand Up @@ -61,9 +65,6 @@ rancher:
cloud_init:
datasources:
- configdrive:/media/config-2
default_network:
dns:
nameservers: [8.8.8.8, 8.8.4.4]
repositories:
core:
url: {{.OS_SERVICES_REPO}}/{{.REPO_VERSION}}{{.SUFFIX}}
Expand Down

0 comments on commit e51c540

Please sign in to comment.