fix(metadata): Ignore non-2XX HTTP responses from metadata service

This commit is contained in:
Brian Waldon 2014-03-13 21:12:14 -07:00
parent e3741a0fa3
commit c1173346c1
2 changed files with 10 additions and 1 deletions

View File

@ -19,8 +19,12 @@ func (ms *metadataService) UserData() ([]byte, error) {
if err != nil { if err != nil {
return []byte{}, err return []byte{}, err
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp/100 != 2 {
return []byte{}, nil
}
respBytes, err := ioutil.ReadAll(resp.Body) respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -61,6 +61,11 @@ func main() {
os.Exit(1) os.Exit(1)
} }
if userdata == "" {
log.Printf("No user data to handle, exiting.")
os.Exit(0)
}
parsed, err := cloudinit.ParseUserData(userdata) parsed, err := cloudinit.ParseUserData(userdata)
if err != nil { if err != nil {
log.Fatalf("Failed parsing user-data: %v", err) log.Fatalf("Failed parsing user-data: %v", err)