Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(imagetagging): retry for missing namedImages #2713

Merged
merged 1 commit into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ protected ImageTagger(OortService oortService, ObjectMapper objectMapper) {
}

protected Collection findImages(Collection<String> imageNames, Collection<String> consideredStageRefIds, Stage stage, Class matchedImageType) {
List<String> upstreamImageIds = new ArrayList<>();

if (imageNames == null || imageNames.isEmpty()) {
imageNames = new HashSet<>();

// attempt to find upstream images in the event that one was not explicitly provided
Collection<String> upstreamImageIds = upstreamImageIds(stage, consideredStageRefIds, getCloudProvider());
upstreamImageIds.addAll(upstreamImageIds(stage, consideredStageRefIds, getCloudProvider()));
if (upstreamImageIds.isEmpty()) {
throw new IllegalStateException("Unable to determine source image(s)");
}
Expand All @@ -93,7 +95,9 @@ protected Collection findImages(Collection<String> imageNames, Collection<String
Map matchedImage = allMatchedImages.stream()
.filter(image -> image.get("imageName").equals(targetImageName))
.findFirst()
.orElseThrow(() -> new ImageNotFound(format("No image found (imageName: %s)", targetImageName), false));
.orElseThrow(() ->
new ImageNotFound(format("No image found (imageName: %s)", targetImageName), !upstreamImageIds.isEmpty())
);

foundImages.add(objectMapper.convertValue(matchedImage, matchedImageType));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ class AmazonImageTaggerSpec extends ImageTaggerSpec<AmazonImageTagger> {
pipeline.stages << stage1 << stage2

and:
oortService.findImage("aws", "my-ami", null, null, null) >> { [] }
if (foundById) {
1 * oortService.findImage("aws", "ami-id", null, null, null) >> {
[["imageName": "ami-name"]]
}
1 * oortService.findImage("aws", "ami-name", null, null, null) >> { [] }
} else if (imageId != null) {
1 * oortService.findImage("aws", imageId, null, null, null) >> { [] }
} else {
1 * oortService.findImage("aws", imageName, null, null, null) >> { [] }
}

when:
imageTagger.getOperationContext(stage2)
Expand All @@ -64,9 +73,10 @@ class AmazonImageTaggerSpec extends ImageTaggerSpec<AmazonImageTagger> {
e.shouldRetry == shouldRetry

where:
imageId | imageName || shouldRetry
"my-ami" | null || true
null | "my-ami" || false // do not retry if an explicitly provided image does not exist (user error)
imageId | imageName || foundById || shouldRetry
"ami-id" | null || false || true
"ami-id" | null || true || true
null | "ami-name" || false || false // do not retry if an explicitly provided image does not exist (user error)
}

def "should build upsertMachineImageTags and allowLaunchDescription operations"() {
Expand Down Expand Up @@ -114,7 +124,7 @@ class AmazonImageTaggerSpec extends ImageTaggerSpec<AmazonImageTagger> {
def stage = new Stage(Execution.newOrchestration("orca"), "", [
imageNames: ["my-ami-1", "my-ami-2"],
tags : [
"tag1" : "value1"
"tag1": "value1"
]
])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ class GoogleImageTaggerSpec extends ImageTaggerSpec {
pipeline.stages << stage1 << stage2

and:
oortService.findImage("gce", "my-gce-image", null, null, null) >> { [] }
if (foundById) {
1 * oortService.findImage("gce", "gce-image-id", null, null, null) >> {
[["imageName": "my-gce-image"]]
}
1 * oortService.findImage("gce", "my-gce-image", null, null, null) >> { [] }
} else if (imageId != null) {
1 * oortService.findImage("gce", imageId, null, null, null) >> { [] }
} else {
1 * oortService.findImage("gce", imageName, null, null, null) >> { [] }
}

when:
imageTagger.getOperationContext(stage2)
Expand All @@ -63,9 +72,10 @@ class GoogleImageTaggerSpec extends ImageTaggerSpec {
e.shouldRetry == shouldRetry

where:
imageId | imageName || shouldRetry
"my-gce-image" | null || true
null | "my-gce-image" || false // do not retry if an explicitly provided image does not exist (user error)
imageId | imageName || foundById || shouldRetry
"my-gce-image" | null || false || true
"gce-image-id" | null || true || true
null | "my-gce-image" || false || false // do not retry if an explicitly provided image does not exist (user error)
}

def "should build upsertImageTags operation"() {
Expand Down