flannel: added flannel support and helper to make dropins
fleet, flannel, and etcd all generate dropins from config. To reduce code duplication, factor out a helper to do that.
This commit is contained in:
parent
d9d89a6fa0
commit
a20addd05e
@ -97,6 +97,29 @@ For more information on fleet configuration, see the [fleet documentation][fleet
|
||||
|
||||
[fleet-config]: https://github.com/coreos/fleet/blob/master/Documentation/deployment-and-configuration.md#configuration
|
||||
|
||||
#### flannel
|
||||
|
||||
The `coreos.flannel.*` parameters also work very similarly to `coreos.etcd.*` and `coreos.fleet.*`. They can be used to set enviornment variables for flanneld. Given the following cloud-config...
|
||||
|
||||
```yaml
|
||||
#cloud-config
|
||||
|
||||
coreos:
|
||||
flannel:
|
||||
etcd-prefix: /coreos.com/network2
|
||||
```
|
||||
|
||||
...will generate systemd unit drop-in like so:
|
||||
|
||||
```
|
||||
[Service]
|
||||
Environment="FLANNELD_ETCD_PREFIX=/coreos.com/network2"
|
||||
```
|
||||
|
||||
For complete list of flannel configuraion parameters, see the [flannel documentation][flannel-readme].
|
||||
|
||||
[flannel-readme]: https://github.com/coreos/flannel/blob/master/README.md
|
||||
|
||||
#### update
|
||||
|
||||
The `coreos.update.*` parameters manipulate settings related to how CoreOS instances are updated.
|
||||
|
@ -31,6 +31,7 @@ type CloudConfig struct {
|
||||
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
|
||||
Coreos struct {
|
||||
Etcd Etcd `yaml:"etcd"`
|
||||
Flannel Flannel `yaml:"flannel"`
|
||||
Fleet Fleet `yaml:"fleet"`
|
||||
OEM OEM `yaml:"oem"`
|
||||
Update Update `yaml:"update"`
|
||||
|
9
config/flannel.go
Normal file
9
config/flannel.go
Normal file
@ -0,0 +1,9 @@
|
||||
package config
|
||||
|
||||
type Flannel struct {
|
||||
EtcdEndpoint string `yaml:"etcd-endpoint" env:"FLANNELD_ETCD_ENDPOINT"`
|
||||
EtcdPrefix string `yaml:"etcd-prefix" env:"FLANNELD_ETCD_PREFIX"`
|
||||
IPMasq string `yaml:"ip-masq" env:"FLANNELD_IP_MASQ"`
|
||||
SubnetFile string `yaml:"subnet-file" env:"FLANNELD_SUBNET_FILE"`
|
||||
Iface string `yaml:"interface" env:"FLANNELD_IFACE"`
|
||||
}
|
@ -131,6 +131,7 @@ func Apply(cfg config.CloudConfig, env *Environment) error {
|
||||
for _, ccu := range []CloudConfigUnit{
|
||||
system.Etcd{Etcd: cfg.Coreos.Etcd},
|
||||
system.Fleet{Fleet: cfg.Coreos.Fleet},
|
||||
system.Flannel{Flannel: cfg.Coreos.Flannel},
|
||||
system.Update{Update: cfg.Coreos.Update, ReadConfig: system.DefaultReadConfig},
|
||||
} {
|
||||
units = append(units, ccu.Units()...)
|
||||
|
@ -19,6 +19,8 @@ package system
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/coreos/coreos-cloudinit/config"
|
||||
)
|
||||
|
||||
// dropinContents generates the contents for a drop-in unit given the config.
|
||||
@ -40,3 +42,16 @@ func dropinContents(e interface{}) string {
|
||||
}
|
||||
return "[Service]\n" + out
|
||||
}
|
||||
|
||||
func dropinFromConfig(cfg interface{}, name string) []Unit {
|
||||
content := dropinContents(cfg)
|
||||
if content == "" {
|
||||
return nil
|
||||
}
|
||||
return []Unit{{config.Unit{
|
||||
Name: name,
|
||||
Runtime: true,
|
||||
DropIn: true,
|
||||
Content: content,
|
||||
}}}
|
||||
}
|
||||
|
@ -28,14 +28,5 @@ type Etcd struct {
|
||||
|
||||
// Units creates a Unit file drop-in for etcd, using any configured options.
|
||||
func (ee Etcd) Units() []Unit {
|
||||
content := dropinContents(ee.Etcd)
|
||||
if content == "" {
|
||||
return nil
|
||||
}
|
||||
return []Unit{{config.Unit{
|
||||
Name: "etcd.service",
|
||||
Runtime: true,
|
||||
DropIn: true,
|
||||
Content: content,
|
||||
}}}
|
||||
return dropinFromConfig(ee.Etcd, "etcd.service")
|
||||
}
|
||||
|
17
system/flannel.go
Normal file
17
system/flannel.go
Normal file
@ -0,0 +1,17 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/coreos/coreos-cloudinit/config"
|
||||
)
|
||||
|
||||
// flannel is a top-level structure which embeds its underlying configuration,
|
||||
// config.Flannel, and provides the system-specific Unit().
|
||||
type Flannel struct {
|
||||
config.Flannel
|
||||
}
|
||||
|
||||
// Units generates a Unit file drop-in for flannel, if any flannel options were
|
||||
// configured in cloud-config
|
||||
func (fl Flannel) Units() []Unit {
|
||||
return dropinFromConfig(fl.Flannel, "flannel.service")
|
||||
}
|
40
system/flannel_test.go
Normal file
40
system/flannel_test.go
Normal file
@ -0,0 +1,40 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/coreos/coreos-cloudinit/config"
|
||||
)
|
||||
|
||||
func TestFlannelUnits(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
config config.Flannel
|
||||
units []Unit
|
||||
}{
|
||||
{
|
||||
config.Flannel{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
config.Flannel{
|
||||
EtcdEndpoint: "http://12.34.56.78:4001",
|
||||
EtcdPrefix: "/coreos.com/network/tenant1",
|
||||
},
|
||||
[]Unit{{config.Unit{
|
||||
Name: "flannel.service",
|
||||
Content: `[Service]
|
||||
Environment="FLANNELD_ETCD_ENDPOINT=http://12.34.56.78:4001"
|
||||
Environment="FLANNELD_ETCD_PREFIX=/coreos.com/network/tenant1"
|
||||
`,
|
||||
Runtime: true,
|
||||
DropIn: true,
|
||||
}}},
|
||||
},
|
||||
} {
|
||||
units := Flannel{tt.config}.Units()
|
||||
if !reflect.DeepEqual(units, tt.units) {
|
||||
t.Errorf("bad units (%q): want %v, got %v", tt.config, tt.units, units)
|
||||
}
|
||||
}
|
||||
}
|
@ -29,14 +29,5 @@ 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 {
|
||||
content := dropinContents(fe.Fleet)
|
||||
if content == "" {
|
||||
return nil
|
||||
}
|
||||
return []Unit{{config.Unit{
|
||||
Name: "fleet.service",
|
||||
Runtime: true,
|
||||
DropIn: true,
|
||||
Content: content,
|
||||
}}}
|
||||
return dropinFromConfig(fe.Fleet, "fleet.service")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user