Skip to content

Commit

Permalink
fix(deploy): Correctly detect images in parent executions (#3203)
Browse files Browse the repository at this point in the history
A previous refactor (#3011) reversed the order of stages returned from parent executions, which in turn caused a bug in the lookup of image id's.
If you have several image producing stages in a parent pipeline, for instance a "Find image by tag" stage followed by a bake stage, Spinnaker would now use the output of the "Find image by tag" stage instead of the bake stage. This PR changes it back to the former behaviour, so that the image closest to the current executing stage will be used.
  • Loading branch information
jervi authored and marchello2000 committed Oct 2, 2019
1 parent 3bad6ca commit ef3c8c6
Showing 1 changed file with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import static java.lang.String.format;
import static java.lang.String.join;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Collections.*;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;

import com.fasterxml.jackson.annotation.JsonBackReference;
Expand All @@ -42,7 +45,17 @@
import de.huxhorn.sulky.ulid.ULID;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -529,23 +542,25 @@ private static Stage findAncestor(Stage stage, Execution execution, Predicate<St
if (parentPipelineStage.isPresent()) {
matchingStage = findAncestor(parentPipelineStage.get(), parentPipelineExecution, predicate);
} else {
List<Stage> parentPipelineStages = new ArrayList<>(parentPipelineExecution.getStages());
parentPipelineStages.sort(
(s1, s2) -> {
if ((s1.endTime == null) && (s2.endTime == null)) {
return 0;
}

if (s1.endTime == null) {
return 1;
}

if (s2.endTime == null) {
return -1;
}

return s1.endTime.compareTo(s2.endTime);
});
List<Stage> parentPipelineStages =
parentPipelineExecution.getStages().stream()
.sorted(
(s1, s2) -> {
if ((s1.endTime == null) && (s2.endTime == null)) {
return 0;
}

if (s1.endTime == null) {
return -1;
}

if (s2.endTime == null) {
return 1;
}

return s2.endTime.compareTo(s1.endTime);
})
.collect(toList());

if (parentPipelineStages.size() > 0) {
// The list is sorted in reverse order by endTime.
Expand Down

0 comments on commit ef3c8c6

Please sign in to comment.