From 7b962ce3683b8dd09f23cad8282e334714da82a6 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 6 Nov 2023 16:08:28 -0800 Subject: [PATCH 1/3] Adding missing commits of artifacts --- .../orca/pipeline/util/ArtifactUtils.java | 28 +------------------ .../pipeline/util/ArtifactUtilsSpec.groovy | 2 +- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtils.java b/orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtils.java index f57085a5d2..e98b228192 100644 --- a/orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtils.java +++ b/orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtils.java @@ -28,7 +28,6 @@ import com.netflix.spinnaker.kork.annotations.NonnullByDefault; import com.netflix.spinnaker.kork.artifacts.model.Artifact; import com.netflix.spinnaker.kork.artifacts.model.ExpectedArtifact; -import com.netflix.spinnaker.kork.web.exceptions.InvalidRequestException; import com.netflix.spinnaker.orca.api.pipeline.models.PipelineExecution; import com.netflix.spinnaker.orca.api.pipeline.models.StageExecution; import com.netflix.spinnaker.orca.pipeline.model.StageContext; @@ -49,7 +48,6 @@ import javax.annotation.CheckReturnValue; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -141,31 +139,7 @@ private List getAllArtifacts( contextParameterProcessor.process( boundArtifactMap, contextParameterProcessor.buildExecutionContext(stage), true); - Artifact evaluatedArtifact = - objectMapper.convertValue(evaluatedBoundArtifactMap, Artifact.class); - return getBoundInlineArtifact(evaluatedArtifact, stage.getExecution()) - .orElse(evaluatedArtifact); - } - - private Optional getBoundInlineArtifact( - @Nullable Artifact artifact, PipelineExecution execution) { - if (ObjectUtils.anyNull( - artifact, execution.getTrigger(), execution.getTrigger().getArtifacts())) { - return Optional.empty(); - } - try { - ExpectedArtifact expectedArtifact = - ExpectedArtifact.builder().matchArtifact(artifact).build(); - return ArtifactResolver.getInstance(execution.getTrigger().getArtifacts(), true) - .resolveExpectedArtifacts(List.of(expectedArtifact)) - .getResolvedExpectedArtifacts() - .stream() - .findFirst() - .flatMap(this::getBoundArtifact); - } catch (InvalidRequestException e) { - log.debug("Could not match inline artifact with trigger bound artifacts", e); - return Optional.empty(); - } + return objectMapper.convertValue(evaluatedBoundArtifactMap, Artifact.class); } public @Nullable Artifact getBoundArtifactForId(StageExecution stage, @Nullable String id) { diff --git a/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtilsSpec.groovy b/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtilsSpec.groovy index 934c0e68b7..c043c7a645 100644 --- a/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtilsSpec.groovy +++ b/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtilsSpec.groovy @@ -590,7 +590,7 @@ class ArtifactUtilsSpec extends Specification { expectedArtifacts: [expectedArtifact], ] - def artifactUtils = makeArtifactUtilsWithMock(executionRepositoryMock) + def artifactUtils = makeArtifactUtilsWithStub(executionRepositoryMock) when: artifactUtils.resolveArtifacts(pipeline) From 211badeb3efc20b0816095c9254fbc25b7329abb Mon Sep 17 00:00:00 2001 From: Nemesis Osorio Date: Mon, 20 May 2024 15:22:35 -0600 Subject: [PATCH 2/3] fix(actifacts): using makeArtifactUtilsWithMock function --- .../spinnaker/orca/pipeline/util/ArtifactUtilsSpec.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtilsSpec.groovy b/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtilsSpec.groovy index c043c7a645..934c0e68b7 100644 --- a/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtilsSpec.groovy +++ b/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtilsSpec.groovy @@ -590,7 +590,7 @@ class ArtifactUtilsSpec extends Specification { expectedArtifacts: [expectedArtifact], ] - def artifactUtils = makeArtifactUtilsWithStub(executionRepositoryMock) + def artifactUtils = makeArtifactUtilsWithMock(executionRepositoryMock) when: artifactUtils.resolveArtifacts(pipeline) From 6fde57d068cd1a9d5475de480fe0eef31b1374e4 Mon Sep 17 00:00:00 2001 From: Nemesis Osorio Date: Tue, 21 May 2024 13:31:37 -0600 Subject: [PATCH 3/3] feature(actifacts): added feature flag for trigger and expected artifacts --- .../spinnaker/orca/pipeline/util/ArtifactUtils.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtils.java b/orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtils.java index e98b228192..0f16dec85e 100644 --- a/orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtils.java +++ b/orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/util/ArtifactUtils.java @@ -52,6 +52,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import rx.schedulers.Schedulers; @@ -65,6 +66,11 @@ public class ArtifactUtils { private final ExecutionRepository executionRepository; private final ContextParameterProcessor contextParameterProcessor; + // This workaround allows customers to keep their existing pipelines unchanged in OES-1.30. + // Do not migrate this flag to newer versions. + @Value("${trigger.expected-artifacts-legacy-behavior:true}") + private boolean filterExpectedArtifactsForTriggers; + @Autowired public ArtifactUtils( ObjectMapper objectMapper, @@ -212,7 +218,8 @@ public void resolveArtifacts(Map pipeline) { .map(it -> objectMapper.convertValue(it, ExpectedArtifact.class)) .filter( artifact -> - expectedArtifactIds.contains(artifact.getId()) + filterExpectedArtifactsForTriggers + || expectedArtifactIds.contains(artifact.getId()) || artifact.isUseDefaultArtifact() || artifact.isUsePriorArtifact()) .collect(toImmutableList());