config: seperate the CoreOS type from CloudConfig

Renamed Coreos to CoreOS while I was at it.
This commit is contained in:
Alex Crawford 2014-12-21 12:14:23 -08:00
parent 182241c8d3
commit 057ab37364
3 changed files with 25 additions and 23 deletions

View File

@ -29,15 +29,7 @@ import (
// used for internal use) have the YAML tag '-' so that they aren't marshalled. // used for internal use) have the YAML tag '-' so that they aren't marshalled.
type CloudConfig struct { type CloudConfig struct {
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"` SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
Coreos struct { CoreOS CoreOS `yaml:"coreos"`
Etcd Etcd `yaml:"etcd"`
Flannel Flannel `yaml:"flannel"`
Fleet Fleet `yaml:"fleet"`
Locksmith Locksmith `yaml:"locksmith"`
OEM OEM `yaml:"oem"`
Update Update `yaml:"update"`
Units []Unit `yaml:"units"`
} `yaml:"coreos"`
WriteFiles []File `yaml:"write_files"` WriteFiles []File `yaml:"write_files"`
Hostname string `yaml:"hostname"` Hostname string `yaml:"hostname"`
Users []User `yaml:"users"` Users []User `yaml:"users"`
@ -46,6 +38,16 @@ type CloudConfig struct {
NetworkConfig string `yaml:"-"` NetworkConfig string `yaml:"-"`
} }
type CoreOS struct {
Etcd Etcd `yaml:"etcd"`
Flannel Flannel `yaml:"flannel"`
Fleet Fleet `yaml:"fleet"`
Locksmith Locksmith `yaml:"locksmith"`
OEM OEM `yaml:"oem"`
Update Update `yaml:"update"`
Units []Unit `yaml:"units"`
}
func IsCloudConfig(userdata string) bool { func IsCloudConfig(userdata string) bool {
header := strings.SplitN(userdata, "\n", 2)[0] header := strings.SplitN(userdata, "\n", 2)[0]

View File

@ -114,7 +114,7 @@ hostname:
if cfg.Hostname != "foo" { if cfg.Hostname != "foo" {
t.Fatalf("hostname not correctly set when invalid keys are present") t.Fatalf("hostname not correctly set when invalid keys are present")
} }
if cfg.Coreos.Etcd.Discovery != "https://discovery.etcd.io/827c73219eeb2fa5530027c37bf18877" { if cfg.CoreOS.Etcd.Discovery != "https://discovery.etcd.io/827c73219eeb2fa5530027c37bf18877" {
t.Fatalf("etcd section not correctly set when invalid keys are present") t.Fatalf("etcd section not correctly set when invalid keys are present")
} }
if len(cfg.WriteFiles) < 1 || cfg.WriteFiles[0].Content != "fun" || cfg.WriteFiles[0].Path != "/var/party" { if len(cfg.WriteFiles) < 1 || cfg.WriteFiles[0].Content != "fun" || cfg.WriteFiles[0].Path != "/var/party" {
@ -220,10 +220,10 @@ hostname: trontastic
} }
} }
if len(cfg.Coreos.Units) != 1 { if len(cfg.CoreOS.Units) != 1 {
t.Error("Failed to parse correct number of units") t.Error("Failed to parse correct number of units")
} else { } else {
u := cfg.Coreos.Units[0] u := cfg.CoreOS.Units[0]
expect := `[Match] expect := `[Match]
Name=eth47 Name=eth47
@ -241,14 +241,14 @@ Address=10.209.171.177/19
} }
} }
if cfg.Coreos.OEM.ID != "rackspace" { if cfg.CoreOS.OEM.ID != "rackspace" {
t.Errorf("Failed parsing coreos.oem. Expected ID 'rackspace', got %q.", cfg.Coreos.OEM.ID) t.Errorf("Failed parsing coreos.oem. Expected ID 'rackspace', got %q.", cfg.CoreOS.OEM.ID)
} }
if cfg.Hostname != "trontastic" { if cfg.Hostname != "trontastic" {
t.Errorf("Failed to parse hostname") t.Errorf("Failed to parse hostname")
} }
if cfg.Coreos.Update.RebootStrategy != "reboot" { if cfg.CoreOS.Update.RebootStrategy != "reboot" {
t.Errorf("Failed to parse locksmith strategy") t.Errorf("Failed to parse locksmith strategy")
} }

View File

@ -110,10 +110,10 @@ func Apply(cfg config.CloudConfig, env *Environment) error {
} }
for _, ccf := range []CloudConfigFile{ for _, ccf := range []CloudConfigFile{
system.OEM{OEM: cfg.Coreos.OEM}, system.OEM{OEM: cfg.CoreOS.OEM},
system.Update{Update: cfg.Coreos.Update, ReadConfig: system.DefaultReadConfig}, system.Update{Update: cfg.CoreOS.Update, ReadConfig: system.DefaultReadConfig},
system.EtcHosts{EtcHosts: cfg.ManageEtcHosts}, system.EtcHosts{EtcHosts: cfg.ManageEtcHosts},
system.Flannel{Flannel: cfg.Coreos.Flannel}, system.Flannel{Flannel: cfg.CoreOS.Flannel},
} { } {
f, err := ccf.File() f, err := ccf.File()
if err != nil { if err != nil {
@ -125,15 +125,15 @@ func Apply(cfg config.CloudConfig, env *Environment) error {
} }
var units []system.Unit var units []system.Unit
for _, u := range cfg.Coreos.Units { for _, u := range cfg.CoreOS.Units {
units = append(units, system.Unit{Unit: u}) units = append(units, system.Unit{Unit: u})
} }
for _, ccu := range []CloudConfigUnit{ for _, ccu := range []CloudConfigUnit{
system.Etcd{Etcd: cfg.Coreos.Etcd}, system.Etcd{Etcd: cfg.CoreOS.Etcd},
system.Fleet{Fleet: cfg.Coreos.Fleet}, system.Fleet{Fleet: cfg.CoreOS.Fleet},
system.Locksmith{Locksmith: cfg.Coreos.Locksmith}, system.Locksmith{Locksmith: cfg.CoreOS.Locksmith},
system.Update{Update: cfg.Coreos.Update, ReadConfig: system.DefaultReadConfig}, system.Update{Update: cfg.CoreOS.Update, ReadConfig: system.DefaultReadConfig},
} { } {
units = append(units, ccu.Units()...) units = append(units, ccu.Units()...)
} }