diff --git a/cloudinit/metadata_service.go b/cloudinit/metadata_service.go index 351dcd7..8125dcb 100644 --- a/cloudinit/metadata_service.go +++ b/cloudinit/metadata_service.go @@ -19,8 +19,12 @@ func (ms *metadataService) UserData() ([]byte, error) { if err != nil { return []byte{}, err } - defer resp.Body.Close() + + if resp/100 != 2 { + return []byte{}, nil + } + respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, err diff --git a/coreos-cloudinit.go b/coreos-cloudinit.go index ba36417..102bc44 100644 --- a/coreos-cloudinit.go +++ b/coreos-cloudinit.go @@ -61,6 +61,11 @@ func main() { os.Exit(1) } + if userdata == "" { + log.Printf("No user data to handle, exiting.") + os.Exit(0) + } + parsed, err := cloudinit.ParseUserData(userdata) if err != nil { log.Fatalf("Failed parsing user-data: %v", err)