Merge pull request #101 from jonboulle/fleet
feat(*): add basic fleet configuration to cloud-config
This commit is contained in:
commit
41cbec8729
@ -32,6 +32,7 @@ type CloudConfig struct {
|
||||
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
|
||||
Coreos struct {
|
||||
Etcd EtcdEnvironment
|
||||
Fleet FleetEnvironment
|
||||
OEM OEMRelease
|
||||
Update UpdateConfig
|
||||
Units []system.Unit
|
||||
@ -133,7 +134,7 @@ func Apply(cfg CloudConfig, env *Environment) error {
|
||||
}
|
||||
}
|
||||
|
||||
for _, ccu := range []CloudConfigUnit{cfg.Coreos.Etcd, cfg.Coreos.Update} {
|
||||
for _, ccu := range []CloudConfigUnit{cfg.Coreos.Etcd, cfg.Coreos.Fleet, cfg.Coreos.Update} {
|
||||
u, err := ccu.Unit(env.Root())
|
||||
if err != nil {
|
||||
return err
|
||||
|
34
initialize/fleet.go
Normal file
34
initialize/fleet.go
Normal file
@ -0,0 +1,34 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coreos/coreos-cloudinit/system"
|
||||
)
|
||||
|
||||
type FleetEnvironment map[string]string
|
||||
|
||||
func (fe FleetEnvironment) String() (out string) {
|
||||
norm := normalizeSvcEnv(fe)
|
||||
out += "[Service]\n"
|
||||
|
||||
for key, val := range norm {
|
||||
out += fmt.Sprintf("Environment=\"FLEET_%s=%s\"\n", key, val)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Unit generates a Unit file drop-in for fleet, if any fleet options were
|
||||
// configured in cloud-config
|
||||
func (fe FleetEnvironment) Unit(root string) (*system.Unit, error) {
|
||||
if len(fe) < 1 {
|
||||
return nil, nil
|
||||
}
|
||||
return &system.Unit{
|
||||
Name: "fleet.service",
|
||||
Runtime: true,
|
||||
DropIn: true,
|
||||
Content: fe.String(),
|
||||
}, nil
|
||||
}
|
42
initialize/fleet_test.go
Normal file
42
initialize/fleet_test.go
Normal file
@ -0,0 +1,42 @@
|
||||
package initialize
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFleetEnvironment(t *testing.T) {
|
||||
cfg := make(FleetEnvironment, 0)
|
||||
cfg["public-ip"] = "12.34.56.78"
|
||||
|
||||
env := cfg.String()
|
||||
|
||||
expect := `[Service]
|
||||
Environment="FLEET_PUBLIC_IP=12.34.56.78"
|
||||
`
|
||||
|
||||
if env != expect {
|
||||
t.Errorf("Generated environment:\n%s\nExpected environment:\n%s", env, expect)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFleetUnit(t *testing.T) {
|
||||
cfg := make(FleetEnvironment, 0)
|
||||
u, err := cfg.Unit("/")
|
||||
if u != nil {
|
||||
t.Errorf("unexpectedly generated unit with empty FleetEnvironment")
|
||||
}
|
||||
|
||||
cfg["public-ip"] = "12.34.56.78"
|
||||
|
||||
u, err = cfg.Unit("/")
|
||||
if err != nil {
|
||||
t.Errorf("error generating fleet unit: %v", err)
|
||||
}
|
||||
if u == nil {
|
||||
t.Fatalf("unexpectedly got nil unit generating fleet unit!")
|
||||
}
|
||||
if !u.Runtime {
|
||||
t.Errorf("bad Runtime for generated fleet unit!")
|
||||
}
|
||||
if !u.DropIn {
|
||||
t.Errorf("bad DropIn for generated fleet unit!")
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user