From f83ce074169a1c3c8f72edf3525730dbc8d95a59 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Fri, 16 May 2014 19:44:57 -0700 Subject: [PATCH 1/2] feat(units): Add generic cloudinit path unit Switch to triggering common user configs via a path unit. This is particularly useful for config drive so that a config drive can be mounted by something other than the udev triggered services, a bind mount when running in a container for example. --- units/configdrive-block.service | 4 ---- units/configdrive-virtfs.service | 4 ---- units/user-cloudinit@.path | 5 +++++ units/user-config.target | 8 +++++--- 4 files changed, 10 insertions(+), 11 deletions(-) create mode 100644 units/user-cloudinit@.path diff --git a/units/configdrive-block.service b/units/configdrive-block.service index 1d5dc94..873fd73 100644 --- a/units/configdrive-block.service +++ b/units/configdrive-block.service @@ -5,10 +5,6 @@ ConditionPathIsMountPoint=!/media/configdrive # Only mount config drive block devices automatically in virtual machines ConditionVirtualization=vm -# OpenStack defined config drive so they get to stick their name in it -Wants=user-cloudinit@media-configdrive-openstack-latest-user_data.service -Before=user-cloudinit@media-configdrive-openstack-latest-user_data.service - [Service] Type=oneshot RemainAfterExit=no diff --git a/units/configdrive-virtfs.service b/units/configdrive-virtfs.service index 1654c24..bc29612 100644 --- a/units/configdrive-virtfs.service +++ b/units/configdrive-virtfs.service @@ -4,10 +4,6 @@ Conflicts=configdrive-block.service umount.target ConditionPathIsMountPoint=!/media/configdrive ConditionVirtualization=vm -# OpenStack defined config drive so they get to stick their name in it -Wants=user-cloudinit@media-configdrive-openstack-latest-user_data.service -Before=user-cloudinit@media-configdrive-openstack-latest-user_data.service - # Support old style setup for now Wants=addon-run@media-configdrive.service addon-config@media-configdrive.service Before=addon-run@media-configdrive.service addon-config@media-configdrive.service diff --git a/units/user-cloudinit@.path b/units/user-cloudinit@.path new file mode 100644 index 0000000..8a3ba0f --- /dev/null +++ b/units/user-cloudinit@.path @@ -0,0 +1,5 @@ +[Unit] +Description=Watch for a cloud-config at %f + +[Path] +PathExists=%f diff --git a/units/user-config.target b/units/user-config.target index 018b47d..dae7d05 100644 --- a/units/user-config.target +++ b/units/user-config.target @@ -3,9 +3,11 @@ Description=Load user-provided cloud configs Requires=system-config.target After=system-config.target -# Load user_data placed by coreos-install -Requires=user-cloudinit@var-lib-coreos\x2dinstall-user_data.service -After=user-cloudinit@var-lib-coreos\x2dinstall-user_data.service +# Watch for configs at a couple common paths +Requires=user-cloudinit@media-configdrive-openstack-latest-user_data.path +After=user-cloudinit@media-configdrive-openstack-latest-user_data.path +Requires=user-cloudinit@var-lib-coreos\x2dinstall-user_data.path +After=user-cloudinit@var-lib-coreos\x2dinstall-user_data.path Requires=user-cloudinit-proc-cmdline.service After=user-cloudinit-proc-cmdline.service From ea6262f0ae371a9a1951b54a8ff670c9350bbf8f Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Fri, 16 May 2014 20:27:50 -0700 Subject: [PATCH 2/2] fix(etcd): fix runtime panic when etcd section is missing. The etcd code tries to assign ee["name"] even when the map was never defined and assigning to an uninitialized map causes a panic. --- initialize/etcd.go | 4 ++++ initialize/etcd_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/initialize/etcd.go b/initialize/etcd.go index d13b98a..ce0a367 100644 --- a/initialize/etcd.go +++ b/initialize/etcd.go @@ -31,6 +31,10 @@ func (ee EtcdEnvironment) String() (out string) { // Unit creates a Unit file drop-in for etcd, using any configured // options and adding a default MachineID if unset. func (ee EtcdEnvironment) Unit(root string) (*system.Unit, error) { + if ee == nil { + return nil, nil + } + if _, ok := ee["name"]; !ok { if machineID := system.MachineID(root); machineID != "" { ee["name"] = machineID diff --git a/initialize/etcd_test.go b/initialize/etcd_test.go index 8327969..ae1fa84 100644 --- a/initialize/etcd_test.go +++ b/initialize/etcd_test.go @@ -152,3 +152,15 @@ Environment="ETCD_NAME=node007" t.Fatalf("File has incorrect contents") } } + +func TestEtcdEnvironmentWhenNil(t *testing.T) { + // EtcdEnvironment will be a nil map if it wasn't in the yaml + var ee EtcdEnvironment + if ee != nil { + t.Fatalf("EtcdEnvironment is not nil") + } + u, err := ee.Unit("") + if u != nil || err != nil { + t.Fatalf("Unit returned a non-nil value for nil input") + } +}