Skip to content

Commit

Permalink
Use newly added name field in step status to find correct results
Browse files Browse the repository at this point in the history
Instead of attempting to match step status in task runs by index,
accounting for presence / order of init containers, use the
newly added name field in the step status so we can reliably
link steps to their status and logs regardless of order.

This involves updating Gopkg.lock to use github.com/tektoncd/pipeline
revision 3415c18f7728476c132f692d9a55a70b7b194c5d which introduced
the new field.
  • Loading branch information
AlanGreene authored and tekton-robot committed Apr 26, 2019
1 parent acd5391 commit 170fa38
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ export function selectedTaskRun(selectedTaskId, taskRuns) {
return taskRuns.find(run => run.id === selectedTaskId);
}

export function stepsStatus(taskSteps, taskRunStepsStatus) {
const steps = taskSteps.map((step, index) => {
const stepStatus = taskRunStepsStatus ? taskRunStepsStatus[index] : {};
export function stepsStatus(taskSteps, taskRunStepsStatus = []) {
const steps = taskSteps.map(step => {
const stepStatus =
taskRunStepsStatus.find(status => status.name === step.name) || {};

let status;
let reason;
if (stepStatus.terminated) {
Expand Down
11 changes: 9 additions & 2 deletions src/utils/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ it('stepsStatus no status', () => {
it('stepsStatus step is running', () => {
const stepName = 'testStep';
const taskSteps = [{ name: stepName, image: 'test' }];
const taskRunStepsStatus = [{ running: { startedAt: '2019' } }];
const taskRunStepsStatus = [
{
name: stepName,
running: { startedAt: '2019' }
}
];
const steps = stepsStatus(taskSteps, taskRunStepsStatus);
const returnedStep = steps[0];
expect(returnedStep.status).toEqual('running');
Expand All @@ -131,6 +136,7 @@ it('stepsStatus step is completed', () => {
const taskSteps = [{ name: stepName, image: 'test' }];
const taskRunStepsStatus = [
{
name: stepName,
terminated: {
exitCode: 0,
reason,
Expand All @@ -153,6 +159,7 @@ it('stepsStatus step is terminated with error', () => {
const taskSteps = [{ name: stepName, image: 'test' }];
const taskRunStepsStatus = [
{
name: stepName,
terminated: {
exitCode: 1,
reason,
Expand All @@ -172,7 +179,7 @@ it('stepsStatus step is terminated with error', () => {
it('stepsStatus step is waiting', () => {
const stepName = 'testStep';
const taskSteps = [{ name: stepName, image: 'test' }];
const taskRunStepsStatus = [{ waiting: {} }];
const taskRunStepsStatus = [{ name: stepName, waiting: {} }];
const steps = stepsStatus(taskSteps, taskRunStepsStatus);
const returnedStep = steps[0];
expect(returnedStep.status).toEqual('waiting');
Expand Down

0 comments on commit 170fa38

Please sign in to comment.