From e4b6421786e15cf2a59f544c0a69d2070bdd781e Mon Sep 17 00:00:00 2001 From: Michael Nguyen Date: Fri, 19 Jul 2019 13:55:14 -0400 Subject: [PATCH] plume: handle non-existent fcos releases.json Use an empty json instead of failing when there is no releases.json --- cmd/plume/release.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/cmd/plume/release.go b/cmd/plume/release.go index b5e8be710..cb1115ab5 100644 --- a/cmd/plume/release.go +++ b/cmd/plume/release.go @@ -26,6 +26,7 @@ import ( "strings" "time" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/spf13/cobra" "golang.org/x/net/context" "google.golang.org/api/compute/v1" @@ -492,16 +493,25 @@ func modifyReleaseMetadataIndex(spec *fcosChannelSpec, commitId string) { } path := filepath.Join("prod", "streams", specChannel, "releases.json") - - f, err := api.DownloadFile(spec.Bucket, path) - if err != nil { - plog.Fatalf("downloading release metadata index: %v", err) - } - defer f.Close() - - data, err := ioutil.ReadAll(f) + data, err := func() ([]byte, error) { + f, err := api.DownloadFile(spec.Bucket, path) + if err != nil { + if awsErr, ok := err.(awserr.Error); ok { + if awsErr.Code() == "NoSuchKey" { + return []byte("{}"), nil + } + } + return []byte{}, fmt.Errorf("downloading release metadata index: %v", err) + } + defer f.Close() + d, err := ioutil.ReadAll(f) + if err != nil { + return []byte{}, fmt.Errorf("reading release metadata index: %v", err) + } + return d, nil + }() if err != nil { - plog.Fatalf("reading release metadata index: %v", err) + plog.Fatal(err) } var m ReleaseMetadata