diff --git a/coreos-cloudinit.go b/coreos-cloudinit.go index f3700e5..948a047 100644 --- a/coreos-cloudinit.go +++ b/coreos-cloudinit.go @@ -115,7 +115,7 @@ func main() { env := initialize.NewEnvironment("/", ds.ConfigRoot(), workspace, convertNetconf, sshKeyName, subs) var ccm, ccu *initialize.CloudConfig - var script system.Script + var script *system.Script if ccm, err = initialize.ParseMetaData(string(metadataBytes)); err != nil { fmt.Printf("Failed to parse meta-data: %v\n", err) die() @@ -128,7 +128,7 @@ func main() { case *initialize.CloudConfig: ccu = t case system.Script: - script = t + script = &t } } @@ -155,7 +155,7 @@ func main() { } if script != nil { - if err = runScript(script, env); err != nil { + if err = runScript(*script, env); err != nil { fmt.Printf("Failed to run script: %v\n", err) die() } diff --git a/initialize/user_data.go b/initialize/user_data.go index 4cd4fa4..280cad6 100644 --- a/initialize/user_data.go +++ b/initialize/user_data.go @@ -9,6 +9,9 @@ import ( ) func ParseUserData(contents string) (interface{}, error) { + if len(contents) == 0 { + return nil, nil + } header := strings.SplitN(contents, "\n", 2)[0] // Explicitly trim the header so we can handle user-data from diff --git a/initialize/user_data_test.go b/initialize/user_data_test.go index 984d073..006f85f 100644 --- a/initialize/user_data_test.go +++ b/initialize/user_data_test.go @@ -47,3 +47,12 @@ func TestParseConfigCRLF(t *testing.T) { t.Error("Parsed incorrect number of SSH keys") } } + +func TestParseConfigEmpty(t *testing.T) { + i, e := ParseUserData(``) + if i != nil { + t.Error("ParseUserData of empty string returned non-nil unexpectedly") + } else if e != nil { + t.Error("ParseUserData of empty string returned error unexpectedly") + } +}