unit: refactor config
- Seperate the config from Destination() - Add YAML tags for the fields
This commit is contained in:
@@ -35,7 +35,7 @@ type CloudConfig struct {
|
||||
Fleet config.Fleet
|
||||
OEM config.OEM
|
||||
Update config.Update
|
||||
Units []system.Unit
|
||||
Units []config.Unit
|
||||
}
|
||||
WriteFiles []system.File `yaml:"write_files"`
|
||||
Hostname string
|
||||
@@ -231,6 +231,11 @@ func Apply(cfg CloudConfig, env *Environment) error {
|
||||
}
|
||||
}
|
||||
|
||||
var units []system.Unit
|
||||
for _, u := range cfg.Coreos.Units {
|
||||
units = append(units, system.Unit{u})
|
||||
}
|
||||
|
||||
for _, ccu := range []CloudConfigUnit{
|
||||
system.Etcd{cfg.Coreos.Etcd},
|
||||
system.Fleet{cfg.Coreos.Fleet},
|
||||
@@ -240,7 +245,7 @@ func Apply(cfg CloudConfig, env *Environment) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg.Coreos.Units = append(cfg.Coreos.Units, u...)
|
||||
units = append(units, u...)
|
||||
}
|
||||
|
||||
wroteEnvironment := false
|
||||
@@ -291,7 +296,7 @@ func Apply(cfg CloudConfig, env *Environment) error {
|
||||
}
|
||||
|
||||
um := system.NewUnitManager(env.Root())
|
||||
return processUnits(cfg.Coreos.Units, env.Root(), um)
|
||||
return processUnits(units, env.Root(), um)
|
||||
|
||||
}
|
||||
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/coreos/coreos-cloudinit/config"
|
||||
"github.com/coreos/coreos-cloudinit/system"
|
||||
)
|
||||
|
||||
@@ -401,10 +402,10 @@ func (tum *TestUnitManager) UnmaskUnit(unit *system.Unit) error {
|
||||
func TestProcessUnits(t *testing.T) {
|
||||
tum := &TestUnitManager{}
|
||||
units := []system.Unit{
|
||||
system.Unit{
|
||||
system.Unit{config.Unit{
|
||||
Name: "foo",
|
||||
Mask: true,
|
||||
},
|
||||
}},
|
||||
}
|
||||
if err := processUnits(units, "", tum); err != nil {
|
||||
t.Fatalf("unexpected error calling processUnits: %v", err)
|
||||
@@ -415,9 +416,9 @@ func TestProcessUnits(t *testing.T) {
|
||||
|
||||
tum = &TestUnitManager{}
|
||||
units = []system.Unit{
|
||||
system.Unit{
|
||||
system.Unit{config.Unit{
|
||||
Name: "bar.network",
|
||||
},
|
||||
}},
|
||||
}
|
||||
if err := processUnits(units, "", tum); err != nil {
|
||||
t.Fatalf("unexpected error calling processUnits: %v", err)
|
||||
@@ -428,10 +429,10 @@ func TestProcessUnits(t *testing.T) {
|
||||
|
||||
tum = &TestUnitManager{}
|
||||
units = []system.Unit{
|
||||
system.Unit{
|
||||
system.Unit{config.Unit{
|
||||
Name: "baz.service",
|
||||
Content: "[Service]\nExecStart=/bin/true",
|
||||
},
|
||||
}},
|
||||
}
|
||||
if err := processUnits(units, "", tum); err != nil {
|
||||
t.Fatalf("unexpected error calling processUnits: %v", err)
|
||||
@@ -442,10 +443,10 @@ func TestProcessUnits(t *testing.T) {
|
||||
|
||||
tum = &TestUnitManager{}
|
||||
units = []system.Unit{
|
||||
system.Unit{
|
||||
system.Unit{config.Unit{
|
||||
Name: "locksmithd.service",
|
||||
Runtime: true,
|
||||
},
|
||||
}},
|
||||
}
|
||||
if err := processUnits(units, "", tum); err != nil {
|
||||
t.Fatalf("unexpected error calling processUnits: %v", err)
|
||||
@@ -456,10 +457,10 @@ func TestProcessUnits(t *testing.T) {
|
||||
|
||||
tum = &TestUnitManager{}
|
||||
units = []system.Unit{
|
||||
system.Unit{
|
||||
system.Unit{config.Unit{
|
||||
Name: "woof",
|
||||
Enable: true,
|
||||
},
|
||||
}},
|
||||
}
|
||||
if err := processUnits(units, "", tum); err != nil {
|
||||
t.Fatalf("unexpected error calling processUnits: %v", err)
|
||||
|
Reference in New Issue
Block a user