forked from spinnaker/orca
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pipelines): expectedArtifacts inheritance from dynamic parent tem…
…plates (spinnaker#3023) When expected artifacts are defined in a template that is sourced dynamically, expected artifacts are not added to the execution. Expected artifacts can be defined in `TemplatedPipelineRequest`, `TemplateConfiguration` and `PipelineTemplate` objects, so a merge strategy is required. Given expected artifacts have a unique `id`, artifacts with same `id` in these object will be overridden. The artifacts with higher priority are the ones in `TemplatedPipelineRequest`, then `TemplateConfiguration` and finally `PipelineTemplate`.
- Loading branch information
1 parent
04a037b
commit 511bff2
Showing
27 changed files
with
366 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ package com.netflix.spinnaker.orca.pipelinetemplate.v1schema | |
|
||
import com.netflix.spinnaker.orca.pipelinetemplate.TemplatedPipelineRequest | ||
import com.netflix.spinnaker.orca.pipelinetemplate.generator.ExecutionGenerator | ||
|
||
import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.model.NamedHashMap | ||
import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.model.PipelineTemplate | ||
import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.model.PipelineTemplate.Configuration | ||
|
@@ -114,6 +115,79 @@ class V1SchemaExecutionGeneratorSpec extends Specification { | |
[] || ['[email protected]'] | ||
} | ||
|
||
@Unroll | ||
def "should set expected artifacts in execution json"() { | ||
given: | ||
PipelineTemplate template = getPipelineTemplate() | ||
template.configuration.setExpectedArtifacts([createExpectedArtifact('artifact-from-template')]) | ||
|
||
TemplateConfiguration configuration = new TemplateConfiguration( | ||
pipeline: new PipelineDefinition([application: 'orca', pipelineConfigId: 'pipelineConfigId']), | ||
configuration: new TemplateConfiguration.PipelineConfiguration( | ||
inherit: inherit, | ||
expectedArtifacts: [ | ||
createExpectedArtifact('artifact-from-configuration') | ||
] | ||
) | ||
) | ||
|
||
when: | ||
def request = new TemplatedPipelineRequest(id: "pipelineConfigId") | ||
if (artifactInRequest) { | ||
request.setExpectedArtifacts([createExpectedArtifact('artifact-from-request')]) | ||
} | ||
def result = subject.generate(template, configuration, request) | ||
|
||
|
||
then: | ||
result.expectedArtifacts*.id == expectedArtifactIds | ||
|
||
where: | ||
inherit | artifactInRequest || expectedArtifactIds | ||
['expectedArtifacts'] | false || ['artifact-from-template', 'artifact-from-configuration'] | ||
[] | false || ['artifact-from-configuration'] | ||
[] | true || ['artifact-from-request', 'artifact-from-configuration'] | ||
['expectedArtifacts'] | true || ['artifact-from-template', 'artifact-from-request', 'artifact-from-configuration'] | ||
} | ||
|
||
@Unroll | ||
def "should override expected artifacts in execution json"() { | ||
given: | ||
PipelineTemplate template = getPipelineTemplate() | ||
if (artifactInTemplate) { | ||
template.configuration.setExpectedArtifacts([createExpectedArtifact('artifact', 'from-template')]) | ||
} | ||
|
||
TemplateConfiguration configuration = new TemplateConfiguration( | ||
pipeline: new PipelineDefinition([application: 'orca', pipelineConfigId: 'pipelineConfigId']), | ||
configuration: new TemplateConfiguration.PipelineConfiguration( | ||
inherit: ['expectedArtifacts'] | ||
) | ||
) | ||
|
||
if (artifactInConfiguration) { | ||
configuration.getConfiguration().setExpectedArtifacts([createExpectedArtifact('artifact', 'from-configuration')]) | ||
} | ||
|
||
when: | ||
def request = new TemplatedPipelineRequest(id: "pipelineConfigId") | ||
if (artifactInRequest) { | ||
request.setExpectedArtifacts([createExpectedArtifact('artifact', 'from-request')]) | ||
} | ||
def result = subject.generate(template, configuration, request) | ||
|
||
|
||
then: | ||
result.expectedArtifacts*.displayName == expectedArtifactNames | ||
|
||
where: | ||
artifactInTemplate | artifactInConfiguration | artifactInRequest || expectedArtifactNames | ||
true | true | true || ['from-request'] | ||
true | true | false || ['from-configuration'] | ||
true | false | true || ['from-request'] | ||
false | true | true || ['from-request'] | ||
} | ||
|
||
private PipelineTemplate getPipelineTemplate() { | ||
new PipelineTemplate( | ||
id: 'simpleTemplate', | ||
|
@@ -162,4 +236,16 @@ class V1SchemaExecutionGeneratorSpec extends Specification { | |
] | ||
) | ||
} | ||
|
||
private HashMap<String, Object> createExpectedArtifact(String id, String name = null) { | ||
def effectiveName = name ?: id | ||
return [ | ||
id: id, | ||
displayName: effectiveName, | ||
defaultArtifact: [customKind: true], | ||
matchArtifact: [customKind: true, type: 'http/file', name: effectiveName], | ||
useDefaultArtifact: false, | ||
usePriorArtifact: false | ||
] | ||
} | ||
} |
Oops, something went wrong.