Skip to content

Commit

Permalink
#277 show condition run as child for taskrun
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
  • Loading branch information
evidolob committed May 20, 2020
1 parent 3b232f9 commit 8052a8e
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 2,537 deletions.
1 change: 1 addition & 0 deletions src/tekton.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export interface ConditionCheckStatus {
startTime?: string;
completionTime?: string;
check?: ContainerState;
conditions?: PipelineRunConditions[];
}

export interface PipelineRunConditionCheckStatus {
Expand Down
6 changes: 0 additions & 6 deletions src/tekton/tektonitem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ export abstract class TektonItem {
return taskList;
}

static async getTaskRunNames(taskRun: TektonNode): Promise<TektonNode[]> {
const taskRunList: Array<TektonNode> = await TektonItem.tkn.getTaskRunsForPipelineRun(taskRun);
if (taskRunList.length === 0) { throw Error(errorMessage.TaskRun); }
return taskRunList;
}

static async getPipelineResourceNames(pipelineResource: TektonNode): Promise<TektonNode[]> {
const pipelineResourceList: Array<TektonNode> = await TektonItem.tkn.getPipelineResources(pipelineResource);
if (pipelineResourceList.length === 0) { throw Error(errorMessage.PipelineResource); }
Expand Down
127 changes: 93 additions & 34 deletions src/tkn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as path from 'path';
import { ToolsConfig } from './tools';
import format = require('string-format');
import humanize = require('humanize-duration');
import { TknPipelineResource, TknTask, PipelineRunData } from './tekton';
import { TknPipelineResource, TknTask, PipelineRunData, TaskRun as RawTaskRun, PipelineRunConditionCheckStatus } from './tekton';
import { kubectl } from './kubectl';
import { pipelineExplorer } from './pipeline/pipelineExplorer';
import { StartObject } from './tekton/pipelinecontent';
Expand Down Expand Up @@ -74,6 +74,7 @@ export enum ContextType {
CONDITIONSNODE = 'conditionsnode',
CONDITIONS = 'conditions',
PIPELINERUNNODE = 'pipelinerunnode',
CONDITIONRUN = 'conditionrunnode',
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -394,7 +395,7 @@ export class TektonNodeImpl implements TektonNode {
pipelinerun: {
icon: 'running.gif',
tooltip: 'PipelineRun: {label}',
getChildren: () => this.tkn.getTaskRunsForPipelineRun(this)
getChildren: () => []
},
task: {
icon: 'T.svg',
Expand All @@ -406,6 +407,11 @@ export class TektonNodeImpl implements TektonNode {
tooltip: 'TaskRun: {label}',
getChildren: () => []
},
conditionrunnode: {
icon: 'running.gif',
tooltip: 'ConditionRun: {label}',
getChildren: () => []
},
clustertask: {
icon: 'CT.svg',
tooltip: 'Clustertask: {label}',
Expand Down Expand Up @@ -476,7 +482,7 @@ export class TektonNodeImpl implements TektonNode {
constructor(private parent: TektonNode,
public readonly name: string,
public readonly contextValue: ContextType,
private readonly tkn: Tkn,
protected readonly tkn: Tkn,
public readonly collapsibleState: TreeItemCollapsibleState = TreeItemCollapsibleState.Collapsed,
public readonly creationTime?: string,
public readonly state?: string) {
Expand Down Expand Up @@ -588,19 +594,86 @@ export class TaskRun extends TektonNodeImpl {
}
}

export abstract class BaseTaskRun extends TektonNodeImpl {
constructor(parent: TektonNode,
name: string,
contextType: ContextType,
tkn: Tkn,
collapsibleState: TreeItemCollapsibleState,
creationTime: string,
protected finished: string | undefined,
state: string) {
super(parent, name, contextType, tkn, collapsibleState, creationTime, state);
}

get description(): string {
let r = '';
if (this.getParent().contextValue === ContextType.TASK) {
if (this.creationTime) {
r = 'started ' + humanizer(Date.now() - Date.parse(this.creationTime)) + ' ago, finished in ' + humanizer(Date.parse(this.finished) - Date.parse(this.creationTime));
} else {
r = 'started ' + humanizer(Date.now() - Date.parse(this.creationTime)) + ' ago, running for ' + humanizer(Date.now() - Date.parse(this.creationTime));
}
} else {
if (this.finished) {
r = 'finished in ' + humanizer(Date.parse(this.finished) - Date.parse(this.creationTime));
} else {
r = 'running for ' + humanizer(Date.now() - Date.parse(this.creationTime));
}
}
return r;
}
}

export class ConditionRun extends BaseTaskRun {
constructor(parent: TektonNode, name: string, tkn: Tkn, item: PipelineRunConditionCheckStatus) {
super(parent, name, ContextType.CONDITIONRUN, tkn, TreeItemCollapsibleState.None, item.status?.startTime, item.status?.completionTime, item.status?.conditions[0]?.status)
}
}

export class TaskRunFromPipeline extends BaseTaskRun {
constructor(parent: TektonNode, name: string, tkn: Tkn, private rawTaskRun: RawTaskRun) {
super(parent,
name,
ContextType.TASKRUN,
tkn,
rawTaskRun.conditionChecks ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.None,
rawTaskRun.status.startTime,
rawTaskRun.status?.completionTime,
rawTaskRun.status ? rawTaskRun.status.conditions[0].status : '');
}

get label(): string {
return this.name;
}

getChildren(): ProviderResult<TektonNode[]> {
if (this.rawTaskRun.conditionChecks) {
const result = []
for (const conditionName in this.rawTaskRun.conditionChecks) {
const rawCondition = this.rawTaskRun.conditionChecks[conditionName];
result.push(new ConditionRun(this, rawCondition.conditionName, this.tkn, rawCondition));

}
return result.sort(compareTimeNewestFirst);
} else {
return super.getChildren();
}
}
}

export class PipelineRun extends TektonNodeImpl {
private started: string;
private finished: string;
private generateName: string;
private item: PipelineRunData;
constructor(parent: TektonNode,
name: string,
tkn: Tkn,
item: PipelineRunData, collapsibleState: TreeItemCollapsibleState) {
super(parent, name, ContextType.PIPELINERUN, tkn, collapsibleState, item.metadata.creationTimestamp, item.status ? item.status.conditions[0].status : '');
this.started = item.metadata.creationTimestamp;
this.generateName = item.metadata.generateName;
this.finished = item.status?.completionTime;
this.item = item;
}

get label(): string {
Expand All @@ -616,6 +689,20 @@ export class PipelineRun extends TektonNodeImpl {
}
return r;
}

getChildren(): ProviderResult<TektonNode[]> {
const result = [];
const tasks = this.item.status?.taskRuns;
if (!tasks) {
return result;
}
for (const task in tasks) {
const taskRun = tasks[task];
result.push(new TaskRunFromPipeline(this, taskRun.pipelineTaskName, this.tkn, taskRun));
}

return result.sort(compareTimeNewestFirst);
}
}

export class MoreNode extends TreeItem implements TektonNode {
Expand Down Expand Up @@ -664,7 +751,6 @@ export interface Tkn {
getPipelineResources(pipelineResources: TektonNode): Promise<TektonNode[]>;
getTasks(task: TektonNode): Promise<TektonNode[]>;
getRawTasks(): Promise<TknTask[]>;
getTaskRunsForPipelineRun(taskRun: TektonNode): Promise<TektonNode[]>;
getClusterTasks(clustertask: TektonNode): Promise<TektonNode[]>;
getRawClusterTasks(): Promise<TknTask[]>;
execute(command: CliCommand, cwd?: string, fail?: boolean): Promise<CliExitData>;
Expand Down Expand Up @@ -718,7 +804,7 @@ export class TknImpl implements Tkn {
}
if (result.error && getStderrString(result.error).indexOf('You must be logged in to the server (Unauthorized)') > -1) {
const tknMessage = 'Please login to the server.';
return [ new TektonNodeImpl(null, tknMessage, ContextType.TKN_DOWN, this, TreeItemCollapsibleState.None)]
return [new TektonNodeImpl(null, tknMessage, ContextType.TKN_DOWN, this, TreeItemCollapsibleState.None)]
}
if (result.error && getStderrString(result.error).indexOf('the server doesn\'t have a resource type \'pipeline\'') > -1) {
const tknDownMsg = 'Please install the OpenShift Pipelines Operator.';
Expand Down Expand Up @@ -893,33 +979,6 @@ export class TknImpl implements Tkn {
return data.map((value) => new TaskRun(taskRun, value.metadata.name, this, value)).sort(compareTimeNewestFirst);
}

async getTaskRunsForPipelineRun(pipelineRun: TektonNode): Promise<TektonNode[]> {
if (!pipelineRun.visibleChildren) {
pipelineRun.visibleChildren = this.defaultPageSize;
}

const taskRuns = await this._getTaskRunsForPipelineRun(pipelineRun);

return this.limitView(pipelineRun, taskRuns);
}

async _getTaskRunsForPipelineRun(pipelinerun: TektonNode): Promise<TektonNode[]> {
const result = await this.execute(Command.listTaskRunsForPipelineRun(pipelinerun.getName()));
if (result.error) {
console.log(result + ' Std.err when processing pipelines');
return [new TektonNodeImpl(pipelinerun, getStderrString(result.error), ContextType.TASKRUN, this, TreeItemCollapsibleState.Expanded)];
}
let data: PipelineTaskRunData[] = [];
try {
data = JSON.parse(result.stdout).items;
// eslint-disable-next-line no-empty
} catch (ignore) {
}

return data
.map((value) => new TaskRun(pipelinerun, value.metadata.name, this, value))
.sort(compareTimeNewestFirst);
}

async getPipelines(pipeline: TektonNode): Promise<TektonNode[]> {
return this._getPipelines(pipeline);
Expand Down
Loading

0 comments on commit 8052a8e

Please sign in to comment.