Merge pull request #245 from jonboulle/units
init: simplify CloudConfigUnit interface
This commit is contained in:
commit
5214ead926
@ -22,7 +22,7 @@ type CloudConfigFile interface {
|
||||
// CloudConfigUnit represents a CoreOS specific configuration option that can generate
|
||||
// associated system.Units to be created/enabled appropriately
|
||||
type CloudConfigUnit interface {
|
||||
Units() ([]system.Unit, error)
|
||||
Units() []system.Unit
|
||||
}
|
||||
|
||||
// Apply renders a CloudConfig to an Environment. This can involve things like
|
||||
@ -117,11 +117,7 @@ func Apply(cfg config.CloudConfig, env *Environment) error {
|
||||
system.Fleet{cfg.Coreos.Fleet},
|
||||
system.Update{cfg.Coreos.Update, system.DefaultReadConfig},
|
||||
} {
|
||||
u, err := ccu.Units()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
units = append(units, u...)
|
||||
units = append(units, ccu.Units()...)
|
||||
}
|
||||
|
||||
wroteEnvironment := false
|
||||
|
@ -11,15 +11,15 @@ type Etcd struct {
|
||||
}
|
||||
|
||||
// Units creates a Unit file drop-in for etcd, using any configured options.
|
||||
func (ee Etcd) Units() ([]Unit, error) {
|
||||
func (ee Etcd) Units() []Unit {
|
||||
content := dropinContents(ee.Etcd)
|
||||
if content == "" {
|
||||
return nil, nil
|
||||
return nil
|
||||
}
|
||||
return []Unit{{config.Unit{
|
||||
Name: "etcd.service",
|
||||
Runtime: true,
|
||||
DropIn: true,
|
||||
Content: content,
|
||||
}}}, nil
|
||||
}}}
|
||||
}
|
||||
|
@ -49,10 +49,7 @@ Environment="ETCD_PEER_BIND_ADDR=127.0.0.1:7002"
|
||||
}}},
|
||||
},
|
||||
} {
|
||||
units, err := Etcd{tt.config}.Units()
|
||||
if err != nil {
|
||||
t.Errorf("bad error (%q): want %q, got %q", tt.config, nil, err)
|
||||
}
|
||||
units := Etcd{tt.config}.Units()
|
||||
if !reflect.DeepEqual(tt.units, units) {
|
||||
t.Errorf("bad units (%q): want %#v, got %#v", tt.config, tt.units, units)
|
||||
}
|
||||
|
@ -12,15 +12,15 @@ type Fleet struct {
|
||||
|
||||
// Units generates a Unit file drop-in for fleet, if any fleet options were
|
||||
// configured in cloud-config
|
||||
func (fe Fleet) Units() ([]Unit, error) {
|
||||
func (fe Fleet) Units() []Unit {
|
||||
content := dropinContents(fe.Fleet)
|
||||
if content == "" {
|
||||
return nil, nil
|
||||
return nil
|
||||
}
|
||||
return []Unit{{config.Unit{
|
||||
Name: "fleet.service",
|
||||
Runtime: true,
|
||||
DropIn: true,
|
||||
Content: content,
|
||||
}}}, nil
|
||||
}}}
|
||||
}
|
||||
|
@ -30,10 +30,7 @@ Environment="FLEET_PUBLIC_IP=12.34.56.78"
|
||||
}}},
|
||||
},
|
||||
} {
|
||||
units, err := Fleet{tt.config}.Units()
|
||||
if err != nil {
|
||||
t.Errorf("bad error (%q): want %q, got %q", tt.config, nil, err)
|
||||
}
|
||||
units := Fleet{tt.config}.Units()
|
||||
if !reflect.DeepEqual(units, tt.units) {
|
||||
t.Errorf("bad units (%q): want %q, got %q", tt.config, tt.units, units)
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ func (uc Update) File() (*File, error) {
|
||||
// Units generates units for the cloud-init initializer to act on:
|
||||
// - a locksmith Unit, if "reboot-strategy" was set in cloud-config
|
||||
// - an update_engine Unit, if "group" or "server" was set in cloud-config
|
||||
func (uc Update) Units() ([]Unit, error) {
|
||||
func (uc Update) Units() []Unit {
|
||||
var units []Unit
|
||||
if uc.Config.RebootStrategy != "" {
|
||||
ls := &Unit{config.Unit{
|
||||
@ -125,7 +125,7 @@ func (uc Update) Units() ([]Unit, error) {
|
||||
units = append(units, ue)
|
||||
}
|
||||
|
||||
return units, nil
|
||||
return units
|
||||
}
|
||||
|
||||
func sortedKeys(m map[string]string) (keys []string) {
|
||||
|
@ -66,10 +66,7 @@ func TestUpdateUnits(t *testing.T) {
|
||||
}}},
|
||||
},
|
||||
} {
|
||||
units, err := Update{tt.config, testReadConfig("")}.Units()
|
||||
if !reflect.DeepEqual(tt.err, err) {
|
||||
t.Errorf("bad error (%q): want %q, got %q", tt.config, tt.err, err)
|
||||
}
|
||||
units := Update{tt.config, testReadConfig("")}.Units()
|
||||
if !reflect.DeepEqual(tt.units, units) {
|
||||
t.Errorf("bad units (%q): want %#v, got %#v", tt.config, tt.units, units)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user