Skip to content

Commit df10b3c

Browse files
Pierre Delagravemergify[bot]
Pierre Delagrave
andcommitted
fix(core): Remove useless entries from Stage.context (#3359)
Fixes spinnaker/spinnaker#5257 The `Stage` constructor was keeping `refId`, `startTimeExpiry` and `requisiteStageRefIds` from the context map argument in its internal context map. This caused issues when a parent stage's context was used to create a child stage, as these entries aren't expected to be inherited. This wasn't a problem for a long time because these values were accidentally removed by the side effect of `StartStageHandler#shouldSkip`. `shouldSkip()` uses `objectMapper.convertValue()` on a stage context expecting to have a cloned map returned. A long standing design/documentation issue with Jackson made `convertValue()` return the input parameter as is instead of converting/cloning it. This made every `Stage` passing through `StartStageHandler.handle()` having their context map indirectly 'corrected' and persisted. An upcoming upgrade to Spring Boot 2.2 comes with Jackson 2.10 where `objectMapper.convertValue()` has a new behaviour and would make `shouldSkip()` fail to silently 'correct' the stages context map. FasterXML/jackson-databind#2220 `BakeStageSpec` was validating `context['refId']` on the generated contexts but the contexts aren't Stages yet; once a context is made into a Stage and added to the graph (`graph.add`) it will have its `refId` generated based on the parent refId; which isn't under test in that spec. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 697722b commit df10b3c

File tree

2 files changed

+3
-2
lines changed
  • orca-bakery/src/test/groovy/com/netflix/spinnaker/orca/bakery/pipeline
  • orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/model

2 files changed

+3
-2
lines changed

orca-bakery/src/test/groovy/com/netflix/spinnaker/orca/bakery/pipeline/BakeStageSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class BakeStageSpec extends Specification {
218218
private
219219
static List<Map> expectedContexts(String cloudProvider, String amiSuffix, String... regions) {
220220
return regions.collect {
221-
[cloudProviderType: cloudProvider, amiSuffix: amiSuffix, type: BakeStage.PIPELINE_CONFIG_TYPE, "region": it, name: "Bake in ${it}", refId: "1"]
221+
[cloudProviderType: cloudProvider, amiSuffix: amiSuffix, type: BakeStage.PIPELINE_CONFIG_TYPE, "region": it, name: "Bake in ${it}"]
222222
}
223223
}
224224
}

orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/model/Stage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ public Stage(Execution execution, String type, String name, Map<String, Object>
104104
this.execution = execution;
105105
this.type = type;
106106
this.name = name;
107-
this.context.putAll(context);
108107

109108
this.refId = (String) context.remove("refId");
110109
this.startTimeExpiry =
@@ -114,6 +113,8 @@ public Stage(Execution execution, String type, String name, Map<String, Object>
114113
this.requisiteStageRefIds =
115114
Optional.ofNullable((Collection<String>) context.remove("requisiteStageRefIds"))
116115
.orElse(emptySet());
116+
117+
this.context.putAll(context);
117118
}
118119

119120
public Stage(Execution execution, String type, Map<String, Object> context) {

0 commit comments

Comments
 (0)