From 585578757494b2e6c6bdfe9c3a2c0724e4db68ef Mon Sep 17 00:00:00 2001 From: Dennis Webb Date: Wed, 24 Jan 2018 10:56:12 -0600 Subject: [PATCH] returns latest image if more than 1 found --- pkg/testutils/integrationtestharness.go | 2 ++ upup/pkg/fi/cloudup/awsup/aws_cloud.go | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/testutils/integrationtestharness.go b/pkg/testutils/integrationtestharness.go index 42f1b9216e..9b1c097483 100644 --- a/pkg/testutils/integrationtestharness.go +++ b/pkg/testutils/integrationtestharness.go @@ -129,6 +129,7 @@ func (h *IntegrationTestHarness) SetupMockAWS() { }}) mockEC2.Images = append(mockEC2.Images, &ec2.Image{ + CreationDate: aws.String("2016-10-21T20:07:19.000Z"), ImageId: aws.String("ami-12345678"), Name: aws.String("k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21"), OwnerId: aws.String(awsup.WellKnownAccountKopeio), @@ -136,6 +137,7 @@ func (h *IntegrationTestHarness) SetupMockAWS() { }) mockEC2.Images = append(mockEC2.Images, &ec2.Image{ + CreationDate: aws.String("2017-01-09T17:08:27.000Z"), ImageId: aws.String("ami-15000000"), Name: aws.String("k8s-1.5-debian-jessie-amd64-hvm-ebs-2017-01-09"), OwnerId: aws.String(awsup.WellKnownAccountKopeio), diff --git a/upup/pkg/fi/cloudup/awsup/aws_cloud.go b/upup/pkg/fi/cloudup/awsup/aws_cloud.go index 1bafbefc54..a6e1070519 100644 --- a/upup/pkg/fi/cloudup/awsup/aws_cloud.go +++ b/upup/pkg/fi/cloudup/awsup/aws_cloud.go @@ -948,11 +948,16 @@ func resolveImage(ec2Client ec2iface.EC2API, name string) (*ec2.Image, error) { if response == nil || len(response.Images) == 0 { return nil, fmt.Errorf("could not find Image for %q", name) } - if len(response.Images) != 1 { - return nil, fmt.Errorf("found multiple Images for %q", name) - } image := response.Images[0] + for _, v := range response.Images { + itime, _ := time.Parse(time.RFC3339, *image.CreationDate) + vtime, _ := time.Parse(time.RFC3339, *v.CreationDate) + if vtime.After(itime) { + image = v + } + } + glog.V(4).Infof("Resolved image %q", aws.StringValue(image.ImageId)) return image, nil }