Skip to content

Commit

Permalink
Fix multiple time pop-up of download and install kubectl information …
Browse files Browse the repository at this point in the history
…message (#658)

* Fix multiple time pop-up of download and install kubectl information message
  • Loading branch information
sudhirverma authored Nov 29, 2021
1 parent 93def61 commit 4501769
Show file tree
Hide file tree
Showing 10 changed files with 1,134 additions and 168 deletions.
1,279 changes: 1,115 additions & 164 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/tkn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ export class TknImpl implements Tkn {

async getRawTasks(): Promise<TknTask[]> {
let data: TknTask[] = [];
if (!ToolsConfig.getTknLocation('kubectl')) return null;
const result = await this.execute(Command.listTasks());
if (result.error) {
console.error(result + 'Std.err when processing tasks');
Expand Down Expand Up @@ -523,6 +524,7 @@ export class TknImpl implements Tkn {

async getRawClusterTasks(): Promise<TknTask[]> {
let data: TknTask[] = [];
if (!ToolsConfig.getTknLocation('kubectl')) return null;
const result = await this.execute(Command.listClusterTasks());
if (result.error) {
console.log(result + 'Std.err when processing tasks');
Expand Down
2 changes: 1 addition & 1 deletion src/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"vendor": "Google",
"name": "kubectl",
"version": "1.18.8",
"versionRange": "1.17.0 - 1.20.0",
"versionRange": "1.17.0 - 1.22.0",
"versionRangeLabel": "v1.18.0",
"dlFileName": "kubectl",
"cmdFileName": "kubectl",
Expand Down
2 changes: 2 additions & 0 deletions src/util/list-tekton-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CliCommand } from '../cli';
import { Command } from '../cli-command';
import { TknPipeline } from '../tekton';
import { tkn } from '../tkn';
import { ToolsConfig } from '../tools';

export async function getPipelineList(): Promise<TknPipeline[]> {
return await executeCommand(Command.listPipelines());
Expand All @@ -17,6 +18,7 @@ export async function getResourceList(resource: string): Promise<TknPipeline[]>
}

async function executeCommand(command: CliCommand): Promise<TknPipeline[]> {
if (!ToolsConfig.getTknLocation('kubectl')) return [];
const result = await tkn.execute(command);
let data: TknPipeline[] = [];
try {
Expand Down
2 changes: 2 additions & 0 deletions src/yaml-support/tkn-conditions-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

import { Command } from '../cli-command';
import { tkn } from '../tkn';
import { ToolsConfig } from '../tools';


export async function getTknConditionsSnippets(): Promise<string[]> {
if (!ToolsConfig.getTknLocation('kubectl')) return [];
const result = await tkn.execute(Command.listConditions());
let data = [];
if (result.error) {
Expand Down
8 changes: 5 additions & 3 deletions src/yaml-support/tkn-tasks-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ interface Param {
}

export async function getRawTasks(forceLoad?: boolean): Promise<TknTask[]> {
let allRawTasks: TknTask[];
let allRawTasks: TknTask[] = [];
if (cache.has(tasksKey) && !forceLoad){
allRawTasks = cache.get(tasksKey);
} else {
const [rawClusterTasks, rawTasks] = await Promise.all([tkn.getRawClusterTasks(), tkn.getRawTasks()]);
allRawTasks = rawClusterTasks.concat(rawTasks);
if (rawClusterTasks) {
allRawTasks = rawClusterTasks.concat(rawTasks);
}
cache.set(tasksKey, allRawTasks);
}
return allRawTasks;
Expand All @@ -75,7 +77,7 @@ export async function getTknTasksSnippets(): Promise<Snippet<TaskSnippet>[]> {

export function convertTasksToSnippet(rawTasks: TknTask[]): Snippet<TaskSnippet>[] {
const result: Snippet<TaskSnippet>[] = [];

if (!rawTasks) return result;
for (const task of rawTasks) {
result.push({
label: task.metadata.name,
Expand Down
1 change: 1 addition & 0 deletions test/tkn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ suite('tkn', () => {
sandbox.stub(telemetry, 'telemetryLogError');
sandbox.stub(ToolsConfig, 'getVersion').resolves('0.2.0');
execStubCli = sandbox.stub(CliImpl.prototype, 'execute').resolves();
sandbox.stub(ToolsConfig, 'getTknLocation').returns('kubectl');
});

teardown(() => {
Expand Down
2 changes: 2 additions & 0 deletions test/util/check-ref-resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TestItem } from '../tekton/testTektonitem';
import { TknImpl } from '../../src/tkn';
import { ContextType } from '../../src/context-type';
import { getPipelineList } from '../../src/util/list-tekton-resource';
import { ToolsConfig } from '../../src/tools';



Expand Down Expand Up @@ -65,6 +66,7 @@ suite('Reference Task/ClusterTask', () => {

setup(() => {
execStub = sandbox.stub(TknImpl.prototype, 'execute').resolves();
sandbox.stub(ToolsConfig, 'getTknLocation').returns('kubectl');
});

teardown(() => {
Expand Down
2 changes: 2 additions & 0 deletions test/yaml-support/tasks-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as sinonChai from 'sinon-chai';
import * as sinon from 'sinon';
import * as taskProvider from '../../src/yaml-support/tkn-tasks-provider';
import * as tkn from '../../src/tkn';
import { ToolsConfig } from '../../src/tools';

const expect = chai.expect;
chai.use(sinonChai);
Expand All @@ -18,6 +19,7 @@ suite('Task provider', () => {

setup(() => {
execStub = sandbox.stub(tknCli, 'execute');
sandbox.stub(ToolsConfig, 'getTknLocation').returns('kubectl');
});

teardown(() => {
Expand Down
2 changes: 2 additions & 0 deletions test/yaml-support/tkn-condition-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as sinonChai from 'sinon-chai';
import * as sinon from 'sinon';
import { tkn } from '../../src/tkn';
import { getTknConditionsSnippets } from '../../src/yaml-support/tkn-conditions-provider';
import { ToolsConfig } from '../../src/tools';

const expect = chai.expect;
chai.use(sinonChai);
Expand All @@ -18,6 +19,7 @@ suite('ConditionRef provider', () => {

setup(() => {
tknExecute = sandbox.stub(tkn, 'execute');
sandbox.stub(ToolsConfig, 'getTknLocation').returns('kubectl');
});

teardown(() => {
Expand Down

0 comments on commit 4501769

Please sign in to comment.