From c1173346c178292bb49c045b58fcc0f986657ceb Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Thu, 13 Mar 2014 21:12:14 -0700 Subject: [PATCH] fix(metadata): Ignore non-2XX HTTP responses from metadata service --- cloudinit/metadata_service.go | 6 +++++- coreos-cloudinit.go | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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)