Skip to content

Commit

Permalink
chore(runJobStage): Fix logs annotation processing on manifest artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
christosarvanitis committed Aug 28, 2024
1 parent 1d85e7c commit 5f2f77e
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.util.Collections.emptyMap;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.spinnaker.orca.api.pipeline.CancellableStage;
import com.netflix.spinnaker.orca.api.pipeline.graph.StageDefinitionBuilder;
Expand All @@ -29,6 +30,8 @@
import com.netflix.spinnaker.orca.clouddriver.tasks.job.MonitorJobTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.job.RunJobTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.job.WaitOnJobCompletion;
import com.netflix.spinnaker.orca.clouddriver.tasks.providers.kubernetes.Manifest;
import com.netflix.spinnaker.orca.clouddriver.tasks.providers.kubernetes.ManifestAnnotationExtractor;
import com.netflix.spinnaker.orca.jackson.OrcaObjectMapper;
import com.netflix.spinnaker.orca.pipeline.tasks.artifacts.BindProducedArtifactsTask;
import java.util.*;
Expand Down Expand Up @@ -86,6 +89,7 @@ public void afterStages(@Nonnull StageExecution stage, @Nonnull StageGraphBuilde
if (stage.getContext().getOrDefault("noOutput", "false").toString().equals("true")) {
stage.setOutputs(emptyMap());
}
stage.getContext().putAll(getLogOutputFromManifestArtifact(stage));
}

@Override
Expand Down Expand Up @@ -155,4 +159,20 @@ private Optional<RunJobStageDecorator> getCloudProviderDecorator(StageExecution
.filter(it -> it.supports(cloudProvider))
.findFirst());
}

public Map<String, Object> getLogOutputFromManifestArtifact(StageExecution stage) {
Map<String, Object> outputs = new HashMap<>();
Map<String, Object> execution = new HashMap<>();
if (stage.getContext().containsKey("manifestArtifact")) {
List<Manifest> manifest =
objectMapper.convertValue(
stage.getContext().get("outputs.manifests"), new TypeReference<List<Manifest>>() {});
String logTemplate = ManifestAnnotationExtractor.logs(manifest.get(0));
if (logTemplate != null) {
execution.put("logs", logTemplate);
outputs.put("execution", execution);
}
}
return outputs;
}
}

0 comments on commit 5f2f77e

Please sign in to comment.