refactor(*): rework cloudconfig for better extensibility and consistency
This change creates a few simple interfaces for coreos-specific configuration options and moves things to them wherever possible; so if an option needs to write a file, or create a unit, it is acted on exactly the same way as every other file/unit that needs to be written during the cloud configuration process.
This commit is contained in:
@@ -17,12 +17,17 @@ import (
|
||||
// never be used as a true MachineID
|
||||
const fakeMachineID = "42000000000000000000000000000042"
|
||||
|
||||
// Name for drop-in service configuration files created by cloudconfig
|
||||
const cloudConfigDropIn = "20-cloudinit.conf"
|
||||
|
||||
type Unit struct {
|
||||
Name string
|
||||
Mask bool
|
||||
Enable bool
|
||||
Runtime bool
|
||||
Content string
|
||||
Command string
|
||||
DropIn bool // drop-in configuration? if so, a cloudinit.conf will be generated
|
||||
}
|
||||
|
||||
func (u *Unit) Type() string {
|
||||
@@ -42,8 +47,8 @@ func (u *Unit) Group() (group string) {
|
||||
|
||||
type Script []byte
|
||||
|
||||
// UnitDestination builds the appropriate absolte file path for
|
||||
// the given unit. The root argument indicates the effective base
|
||||
// UnitDestination builds the appropriate absolute file path for
|
||||
// the given Unit. The root argument indicates the effective base
|
||||
// directory of the system (similar to a chroot).
|
||||
func UnitDestination(u *Unit, root string) string {
|
||||
dir := "etc"
|
||||
@@ -51,7 +56,11 @@ func UnitDestination(u *Unit, root string) string {
|
||||
dir = "run"
|
||||
}
|
||||
|
||||
return path.Join(root, dir, "systemd", u.Group(), u.Name)
|
||||
if u.DropIn {
|
||||
return path.Join(root, dir, "systemd", u.Group(), fmt.Sprintf("%s.d", u.Name), cloudConfigDropIn)
|
||||
} else {
|
||||
return path.Join(root, dir, "systemd", u.Group(), u.Name)
|
||||
}
|
||||
}
|
||||
|
||||
// PlaceUnit writes a unit file at the provided destination, creating
|
||||
|
Reference in New Issue
Block a user