Skip to content

Commit

Permalink
#79 limit number of pipelineruns and taskruns in tree
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
  • Loading branch information
evidolob committed Jan 13, 2020
1 parent 673b5b9 commit e3a058f
Show file tree
Hide file tree
Showing 5 changed files with 340 additions and 33 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"sourceMaps": true,
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
Expand Down
30 changes: 18 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,19 +537,25 @@
"vs-tekton.tkn-path": "",
"vs-tekton.tknVersioning": "user-provided",
"vs-kubernetes.outputFormat": "yaml"
},
"vs-tekton.showChannelOutput": {
"title": "Show channel on output",
"type": "boolean",
"default": "false",
"description": "Show Tekton Pipeline output channel when new text added to output stream"
},
"vs-tekton.outputVerbosityLevel": {
"title": "Output Verbosity Level",
"type": "number",
"default": 0,
"description": "Output verbosity level (value between 0 and 9) for Tekton Pipeline Start, Push and Watch commands in output channel and integrated terminal."
},
"vs-tekton.treePaginationLimit": {
"title": "Tree items pagination limit",
"type": "number",
"default": 5,
"description": "Tree pagination limit for some tekton related nodes(pipeline runs/task runs)"
}
},
"vs-tekton.showChannelOutput": {
"title": "Show channel on output",
"type": "boolean",
"default": "false",
"description": "Show Tekton Pipeline output channel when new text added to output stream"
},
"vs-tekton.outputVerbosityLevel": {
"title": "Output Verbosity Level",
"type": "number",
"default": 0,
"description": "Output verbosity level (value between 0 and 9) for Tekton Pipeline Start, Push and Watch commands in output channel and integrated terminal."
}
}
},
Expand Down
7 changes: 7 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import fsx = require('fs-extra');
import * as k8s from 'vscode-kubernetes-tools-api';
import { ClusterTask } from './tekton/clustertask';
import { PipelineResource } from './tekton/pipelineresource';
import { TektonNode } from './tkn';

export let contextGlobalState: vscode.ExtensionContext;
let tektonExplorer: k8s.ClusterExplorerV1 | undefined = undefined;
Expand Down Expand Up @@ -59,6 +60,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
// vscode.commands.registerCommand('tekton.taskrun.cancel', (context) => execute(TaskRun.cancel, context)),
vscode.commands.registerCommand('tekton.taskrun.delete', (context) => execute(TaskRun.delete, context)),
vscode.commands.registerCommand('tekton.explorer.reportIssue', () => PipelineExplorer.reportIssue()),
vscode.commands.registerCommand('_tekton.explorer.more', expandMoreItem),
PipelineExplorer.getInstance()
];
disposables.forEach((e) => context.subscriptions.push(e));
Expand Down Expand Up @@ -131,3 +133,8 @@ function migrateFromTkn018(): void {
fsx.copyFileSync(oldCfg, newCfg);
}
}

function expandMoreItem(context: number, parent: TektonNode): void {
parent.visibleChildren += context;
PipelineExplorer.getInstance().refresh(parent);
}
101 changes: 87 additions & 14 deletions src/tkn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*-----------------------------------------------------------------------------------------------*/

import { CliCommand, CliExitData, Cli, CliImpl, createCliCommand, cliCommandToString } from './cli';
import { ProviderResult, TreeItemCollapsibleState, Terminal, Uri, QuickPickItem, workspace } from 'vscode';
import { ProviderResult, TreeItemCollapsibleState, Terminal, Uri, QuickPickItem, workspace, Command as vsCommand, TreeItem } from 'vscode';
import { WindowUtil } from './util/windowUtils';
import * as path from 'path';
import { ToolsConfig } from './tools';
Expand Down Expand Up @@ -41,6 +41,7 @@ export interface TektonNode extends QuickPickItem {
contextValue: string;
creationTime?: string;
state?: string;
visibleChildren?: number;
getChildren(): ProviderResult<TektonNode[]>;
getParent(): TektonNode;
getName(): string;
Expand Down Expand Up @@ -478,6 +479,45 @@ export class PipelineRun extends TektonNodeImpl {
}
}

export class MoreNode extends TreeItem implements TektonNode {
contextValue: string;
creationTime?: string;
state?: string;
detail?: string;
picked?: boolean;
alwaysShow?: boolean;
label: string;

constructor(private showNext: number,
private totalCount: number,
private parent: TektonNode) {
super(`more`, TreeItemCollapsibleState.None);
}

get command(): vsCommand {
return { command: '_tekton.explorer.more', title: `more ${this.showNext}`, arguments: [this.showNext, this.parent, this] };
}

get tooltip(): string {
return `${this.showNext} more from ${this.totalCount}`
}

get description(): string {
return `${this.showNext} from ${this.totalCount}`
}

getChildren(): ProviderResult<TektonNode[]> {
throw new Error("Method not implemented.");
}
getParent(): TektonNode {
return this.parent;
}
getName(): string {
return this.label;
}

}

export interface Tkn {
getPipelineNodes(): Promise<TektonNode[]>;
startPipeline(pipeline: StartPipelineObject): Promise<TektonNode[]>;
Expand Down Expand Up @@ -511,16 +551,24 @@ function compareTime(a, b): number {
return aTime < bTime ? -1 : 1;
}

function compareTimeNewestFirst(a: TektonNode, b: TektonNode): number {
const aTime = Date.parse(a.creationTime);
const bTime = Date.parse(b.creationTime);
return aTime < bTime ? 1 : -1;
}

export class TknImpl implements Tkn {

public static ROOT: TektonNode = new TektonNodeImpl(undefined, 'root', undefined, undefined);
private cache: Map<TektonNode, TektonNode[]> = new Map();
private static cli: Cli = CliImpl.getInstance();
private static instance: Tkn;
// Get page size from configuration, in case configuration is not present(dev mode) use hard coded value
defaultPageSize: number = workspace.getConfiguration('vs-tekton').has('treePaginationLimit') ? workspace.getConfiguration('vs-tekton').get('treePaginationLimit') : 5;

// eslint-disable-next-line @typescript-eslint/no-empty-function
private constructor() {
private constructor() {

}

public static get Instance(): Tkn {
Expand Down Expand Up @@ -564,12 +612,24 @@ export class TknImpl implements Tkn {
}

async getPipelineRuns(pipeline: TektonNode): Promise<TektonNode[]> {
if (!pipeline.visibleChildren) {
pipeline.visibleChildren = this.defaultPageSize;
}
let pipelineRuns: TektonNode[] = this.cache.get(pipeline);
if (!pipelineRuns) {
pipelineRuns = await this._getPipelineRuns(pipeline);
this.cache.set(pipeline, pipelineRuns);
}
return pipelineRuns;

const currentRuns = pipelineRuns.slice(0, Math.min(pipeline.visibleChildren, pipelineRuns.length))
if (pipeline.visibleChildren < pipelineRuns.length) {
let nextPage = this.defaultPageSize;
if (pipeline.visibleChildren + this.defaultPageSize > pipelineRuns.length) {
nextPage = pipelineRuns.length - pipeline.visibleChildren;
}
currentRuns.push(new MoreNode(nextPage, pipelineRuns.length, pipeline));
}
return currentRuns;
}

async _getPipelineRuns(pipeline: TektonNode): Promise<TektonNode[]> | undefined {
Expand All @@ -583,14 +643,14 @@ export class TknImpl implements Tkn {
try {
const r = JSON.parse(result.stdout);
data = r.items ? r.items : data;
// eslint-disable-next-line no-empty
// eslint-disable-next-line no-empty
} catch (ignore) {
}

return data
.filter((value) => value.spec.pipelineRef.name === pipeline.getName())
.map((value) => new PipelineRun(pipeline, value.metadata.name, this, value))
.sort(compareTime);
.sort(compareTimeNewestFirst);
}

public async getTaskRunsforTasks(task: TektonNode): Promise<TektonNode[]> {
Expand All @@ -611,22 +671,35 @@ export class TknImpl implements Tkn {
let data: PipelineTaskRunData[] = [];
try {
data = JSON.parse(result.stdout).items;
// eslint-disable-next-line no-empty
// eslint-disable-next-line no-empty
} catch (ignore) {
}
return data
.filter((value) => value.spec.taskRef.name === task.getName())
.map((value) => new TaskRun(task, value.metadata.name, this, value))
.sort(compareTime);
.sort(compareTimeNewestFirst);
}

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

let taskRuns: TektonNode[] = this.cache.get(pipelineRun);
if (!taskRuns) {
taskRuns = await this._getTaskRuns(pipelineRun);
this.cache.set(pipelineRun, taskRuns);
}
return taskRuns;

const currentRuns = taskRuns.slice(0, Math.min(pipelineRun.visibleChildren, taskRuns.length))
if (pipelineRun.visibleChildren < taskRuns.length) {
let nextPage = this.defaultPageSize;
if (pipelineRun.visibleChildren + this.defaultPageSize > taskRuns.length) {
nextPage = taskRuns.length - pipelineRun.visibleChildren;
}
currentRuns.push(new MoreNode(nextPage, taskRuns.length, pipelineRun));
}
return currentRuns;
}

async _getTaskRuns(pipelinerun: TektonNode): Promise<TektonNode[]> {
Expand All @@ -638,14 +711,14 @@ export class TknImpl implements Tkn {
let data: PipelineTaskRunData[] = [];
try {
data = JSON.parse(result.stdout).items;
// eslint-disable-next-line no-empty
// eslint-disable-next-line no-empty
} catch (ignore) {
}

return data
.filter((value) => value.metadata.labels["tekton.dev/pipelineRun"] === pipelinerun.getName())
.map((value) => new TaskRun(pipelinerun, value.metadata.name, this, value))
.sort(compareTime);
.sort(compareTimeNewestFirst);
}

async getPipelines(pipeline: TektonNode): Promise<TektonNode[]> {
Expand Down Expand Up @@ -703,7 +776,7 @@ export class TknImpl implements Tkn {
}
try {
data = JSON.parse(result.stdout).items;
// eslint-disable-next-line no-empty
// eslint-disable-next-line no-empty
} catch (ignore) {
}
let tasks: string[] = data.map((value) => value.metadata.name);
Expand All @@ -720,7 +793,7 @@ export class TknImpl implements Tkn {
try {
const result = await this.execute(Command.listClusterTasks());
data = JSON.parse(result.stdout).items;
// eslint-disable-next-line no-empty
// eslint-disable-next-line no-empty
} catch (ignore) {

}
Expand All @@ -734,7 +807,7 @@ export class TknImpl implements Tkn {
let data: TknTask[] = [];
try {
data = JSON.parse(result.stdout).items;
// eslint-disable-next-line no-empty
// eslint-disable-next-line no-empty
} catch (ignore) {

}
Expand Down
Loading

0 comments on commit e3a058f

Please sign in to comment.