Skip to content

Commit 4753b33

Browse files
committed
Fix circular dependency
Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent 3ac40a3 commit 4753b33

File tree

16 files changed

+168
-101
lines changed

16 files changed

+168
-101
lines changed

.vscode/project.code-snippets

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"copyright": {
3+
"prefix": "copyright",
4+
"scope": "typescript",
5+
"body": [
6+
"/*-----------------------------------------------------------------------------------------------",
7+
" * Copyright (c) Red Hat, Inc. All rights reserved.",
8+
" * Licensed under the MIT License. See LICENSE file in the project root for license information.",
9+
" *-----------------------------------------------------------------------------------------------*/",
10+
""
11+
],
12+
"description": "Copyright header"
13+
}
14+
}

src/cli.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { CommandText } from './base/command';
99
import { ToolsConfig } from './tools';
1010
import { ChildProcessUtil, CliExitData } from './util/childProcessUtil';
1111
import { VsCommandError } from './vscommand';
12-
import { OpenShiftTerminalManager } from './webview/openshift-terminal/openShiftTerminal';
1312

1413
export class CliChannel {
1514

@@ -65,11 +64,6 @@ export class CliChannel {
6564
return result;
6665
}
6766

68-
async executeInTerminal(command: CommandText, cwd: string = process.cwd(), name = 'OpenShift', addEnv = {} as {[key : string]: string} ): Promise<void> {
69-
const merged = Object.fromEntries([...Object.entries(addEnv), ...Object.entries(CliChannel.createTelemetryEnv()), ...Object.entries(process.env)]);
70-
await OpenShiftTerminalManager.getInstance().createTerminal(command, name, cwd, merged);
71-
}
72-
7367
async spawnTool(cmd: CommandText, opts: cp.SpawnOptions = {cwd: undefined, env: process.env}): Promise<cp.ChildProcess> {
7468
const toolLocation = await ToolsConfig.detect(cmd.command);
7569
const optWithTelemetryEnv = CliChannel.applyEnv(opts, CliChannel.createTelemetryEnv());

src/k8s/build.ts

Lines changed: 116 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,112 +9,145 @@ import { CommandOption, CommandText } from '../base/command';
99
import { CliChannel } from '../cli';
1010
import { Progress } from '../util/progress';
1111
import { VsCommandError, vsCommand } from '../vscommand';
12+
import { OpenShiftTerminalManager } from '../webview/openshift-terminal/openShiftTerminal';
1213
import * as common from './common';
1314

1415
export class Build {
15-
1616
public static command = {
17-
getAllBuilds(parent: ClusterExplorerV1.ClusterExplorerNode): CommandText {
18-
return new CommandText('get build',
19-
undefined, [
20-
new CommandOption('-o', `jsonpath="{range .items[?(.metadata.labels.buildconfig=='${(parent as any).name}')]}{.metadata.namespace}{','}{.metadata.name}{','}{.metadata.annotations.openshift\\.io/build\\.number}{\\"\\n\\"}{end}"`)
21-
]
22-
);
23-
},
24-
startBuild(buildConfig: string): CommandText {
25-
return new CommandText('oc start-build', buildConfig);
26-
},
27-
getBuilds(build: string): CommandText {
28-
return new CommandText('oc get build',
29-
undefined, [
17+
getAllBuilds(parent: ClusterExplorerV1.ClusterExplorerNode): CommandText {
18+
return new CommandText('get build', undefined, [
19+
new CommandOption(
20+
'-o',
21+
`jsonpath="{range .items[?(.metadata.labels.buildconfig=='${
22+
(parent as any).name
23+
}')]}{.metadata.namespace}{','}{.metadata.name}{','}{.metadata.annotations.openshift\\.io/build\\.number}{\\"\\n\\"}{end}"`,
24+
),
25+
]);
26+
},
27+
startBuild(buildConfig: string): CommandText {
28+
return new CommandText('oc start-build', buildConfig);
29+
},
30+
getBuilds(build: string): CommandText {
31+
return new CommandText('oc get build', undefined, [
3032
new CommandOption('-l', `buildconfig=${build}`),
31-
new CommandOption('-o', 'json', false)
32-
]
33-
);
34-
},
35-
showLog(build: string, text: string): CommandText {
36-
return new CommandText('oc logs', `${build}${text}`);
37-
},
38-
rebuildFrom(resourceId: string): CommandText {
39-
return new CommandText('oc start-build',
40-
undefined, [
41-
new CommandOption('--from-build', resourceId)
42-
]
43-
);
44-
},
45-
followLog(build: string, text: string): CommandText {
46-
return new CommandText('oc logs', `${build}${text}`, [
47-
new CommandOption('-f')
48-
]
49-
);
50-
},
51-
delete(build: string): CommandText {
52-
return new CommandText('oc delete build',build);
53-
},
54-
getBuildConfigs(): CommandText {
55-
return new CommandText('oc get buildConfig -o json');
56-
}
57-
};
33+
new CommandOption('-o', 'json', false),
34+
]);
35+
},
36+
showLog(build: string, text: string): CommandText {
37+
return new CommandText('oc logs', `${build}${text}`);
38+
},
39+
rebuildFrom(resourceId: string): CommandText {
40+
return new CommandText('oc start-build', undefined, [
41+
new CommandOption('--from-build', resourceId),
42+
]);
43+
},
44+
followLog(build: string, text: string): CommandText {
45+
return new CommandText('oc logs', `${build}${text}`, [new CommandOption('-f')]);
46+
},
47+
delete(build: string): CommandText {
48+
return new CommandText('oc delete build', build);
49+
},
50+
getBuildConfigs(): CommandText {
51+
return new CommandText('oc get buildConfig -o json');
52+
},
53+
};
5854

5955
protected static readonly cli = CliChannel.getInstance();
6056

6157
static getNodeContributor(): ClusterExplorerV1.NodeContributor {
62-
return {
63-
contributesChildren(parent: ClusterExplorerV1.ClusterExplorerNode | undefined): boolean {
64-
return !!parent && parent.nodeType === 'resource' && parent.resourceKind.manifestKind === 'BuildConfig';
65-
},
66-
async getChildren(parent: ClusterExplorerV1.ClusterExplorerNode | undefined): Promise<ClusterExplorerV1.Node[]> {
67-
return common.getChildrenNode(Build.command.getAllBuilds(parent), 'Build', 'build');
68-
}
69-
};
58+
return {
59+
contributesChildren(
60+
parent: ClusterExplorerV1.ClusterExplorerNode | undefined,
61+
): boolean {
62+
return (
63+
!!parent &&
64+
parent.nodeType === 'resource' &&
65+
parent.resourceKind.manifestKind === 'BuildConfig'
66+
);
67+
},
68+
async getChildren(
69+
parent: ClusterExplorerV1.ClusterExplorerNode | undefined,
70+
): Promise<ClusterExplorerV1.Node[]> {
71+
return common.getChildrenNode(Build.command.getAllBuilds(parent), 'Build', 'build');
72+
},
73+
};
7074
}
7175

7276
static async getBuildConfigNames(msg: string): Promise<QuickPickItem[]> {
7377
return common.getQuickPicks(Build.command.getBuildConfigs(), msg);
7478
}
7579

7680
static async getBuildNames(buildConfig: string): Promise<QuickPickItem[]> {
77-
return common.getQuickPicks(Build.command.getBuilds(buildConfig), 'You have no builds available');
81+
return common.getQuickPicks(
82+
Build.command.getBuilds(buildConfig),
83+
'You have no builds available',
84+
);
7885
}
7986

8087
static async selectBuild(context: any, text: string): Promise<string> {
8188
let build: string = null;
8289
if (context) {
8390
build = context.impl.name;
8491
} else {
85-
const buildConfig = await common.selectResourceByName(Build.getBuildConfigNames('You have no BuildConfigs available'), 'Select a BuildConfig to see the builds');
86-
if (buildConfig) {
87-
const selBuild = await window.showQuickPick(this.getBuildNames(buildConfig), {placeHolder: text, ignoreFocusOut: true});
92+
const buildConfig = await common.selectResourceByName(
93+
Build.getBuildConfigNames('You have no BuildConfigs available'),
94+
'Select a BuildConfig to see the builds',
95+
);
96+
if (buildConfig) {
97+
const selBuild = await window.showQuickPick(this.getBuildNames(buildConfig), {
98+
placeHolder: text,
99+
ignoreFocusOut: true,
100+
});
88101
build = selBuild ? selBuild.label : null;
89102
}
90103
}
91104
return build;
92105
}
93106

94107
@vsCommand('clusters.openshift.build.start')
95-
static async startBuild(context: { name: string}): Promise<string> {
108+
static async startBuild(context: { name: string }): Promise<string> {
96109
let buildName: string = context ? context.name : undefined;
97110
let result: Promise<string> = null;
98-
if (!buildName) buildName = await common.selectResourceByName(await Build.getBuildConfigNames('You have no BuildConfigs available to start a build'), 'Select a BuildConfig to start a build');
111+
if (!buildName) {
112+
buildName = await common.selectResourceByName(
113+
await Build.getBuildConfigNames(
114+
'You have no BuildConfigs available to start a build',
115+
),
116+
'Select a BuildConfig to start a build',
117+
);
118+
}
99119
if (buildName) {
100-
result = Progress.execFunctionWithProgress('Starting build', () => Build.cli.executeTool(Build.command.startBuild(buildName)))
120+
result = Progress.execFunctionWithProgress('Starting build', () =>
121+
Build.cli.executeTool(Build.command.startBuild(buildName)),
122+
)
101123
.then(() => `Build '${buildName}' successfully started`)
102-
.catch((err) => Promise.reject(new VsCommandError(`Failed to start build with error '${err}'`, 'Failed to start build')));
124+
.catch((err) =>
125+
Promise.reject(
126+
new VsCommandError(
127+
`Failed to start build with error '${err}'`,
128+
'Failed to start build',
129+
),
130+
),
131+
);
103132
}
104133
return result;
105134
}
106135

107136
@vsCommand('clusters.openshift.build.showLog', true)
108-
static async showLog(context: { impl: any}): Promise<string> {
137+
static async showLog(context: { impl: any }): Promise<string> {
109138
const build = await Build.selectBuild(context, 'Select a Build to see the logs');
110139
if (build) {
111-
void Build.cli.executeInTerminal(Build.command.showLog(build, '-build'), undefined, `Show '${build}' Build Log`);
140+
await OpenShiftTerminalManager.getInstance().executeInTerminal(
141+
Build.command.showLog(build, '-build'),
142+
undefined,
143+
`Show '${build}' Build Log`,
144+
);
112145
}
113146
return null;
114147
}
115148

116149
@vsCommand('clusters.openshift.build.rebuild')
117-
static async rebuild(context: { id?: string; impl: any}): Promise<string> {
150+
static async rebuild(context: { id?: string; impl: any }): Promise<string> {
118151
let resourceId: string;
119152
if (context) {
120153
resourceId = context.impl.name;
@@ -125,28 +158,45 @@ export class Build {
125158
}
126159
}
127160
if (resourceId) {
128-
void Build.cli.executeInTerminal(Build.command.rebuildFrom(resourceId), undefined, `Rebuild '${resourceId}' Build`);
161+
await OpenShiftTerminalManager.getInstance().executeInTerminal(
162+
Build.command.rebuildFrom(resourceId),
163+
undefined,
164+
`Rebuild '${resourceId}' Build`,
165+
);
129166
}
130167
return null;
131168
}
132169

133170
@vsCommand('clusters.openshift.build.followLog')
134-
static async followLog(context: { impl: any}): Promise<string> {
171+
static async followLog(context: { impl: any }): Promise<string> {
135172
const build = await Build.selectBuild(context, 'Select a build to follow the logs');
136173
if (build) {
137-
void Build.cli.executeInTerminal(Build.command.followLog(build, '-build'), undefined, `Follow '${build}' Build Log`);
174+
await OpenShiftTerminalManager.getInstance().executeInTerminal(
175+
Build.command.followLog(build, '-build'),
176+
undefined,
177+
`Follow '${build}' Build Log`,
178+
);
138179
}
139180
return null;
140181
}
141182

142183
@vsCommand('clusters.openshift.build.delete', true)
143-
static async delete(context: { impl: any}): Promise<string> {
184+
static async delete(context: { impl: any }): Promise<string> {
144185
let result: null | string | Promise<string> | PromiseLike<string> = null;
145186
const build = await Build.selectBuild(context, 'Select a build to delete');
146187
if (build) {
147-
result = Progress.execFunctionWithProgress('Deleting build', () => Build.cli.executeTool(Build.command.delete(build)))
188+
result = Progress.execFunctionWithProgress('Deleting build', () =>
189+
Build.cli.executeTool(Build.command.delete(build)),
190+
)
148191
.then(() => `Build '${build}' successfully deleted`)
149-
.catch((err) => Promise.reject(new VsCommandError(`Failed to delete build with error '${err}'`, 'Failed to delete build')));
192+
.catch((err) =>
193+
Promise.reject(
194+
new VsCommandError(
195+
`Failed to delete build with error '${err}'`,
196+
'Failed to delete build',
197+
),
198+
),
199+
);
150200
}
151201
return result;
152202
}

src/k8s/deploymentConfig.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { CommandOption, CommandText } from '../base/command';
99
import { CliChannel } from '../cli';
1010
import { Progress } from '../util/progress';
1111
import { VsCommandError, vsCommand } from '../vscommand';
12+
import { OpenShiftTerminalManager } from '../webview/openshift-terminal/openShiftTerminal';
1213
import * as common from './common';
1314

1415
export class DeploymentConfig {
@@ -93,7 +94,7 @@ export class DeploymentConfig {
9394
static async rcShowLog(context: { impl: any }): Promise<string> {
9495
const replica = await DeploymentConfig.selectReplica(context, 'Select a Replica to see the logs');
9596
if (replica) {
96-
await DeploymentConfig.cli.executeInTerminal(DeploymentConfig.command.showLog(replica), undefined, `Show '${replica}' Replica Log`);
97+
await OpenShiftTerminalManager.getInstance().executeInTerminal(DeploymentConfig.command.showLog(replica), undefined, `Show '${replica}' Replica Log`);
9798
}
9899
return replica;
99100
}
@@ -103,7 +104,7 @@ export class DeploymentConfig {
103104
let deployName: string = context ? context.name : null;
104105
if (!deployName) deployName = await common.selectResourceByName(DeploymentConfig.getDeploymentConfigNames('You have no DeploymentConfigs available to see logs'), 'Select a DeploymentConfig to see logs');
105106
if (deployName) {
106-
await DeploymentConfig.cli.executeInTerminal(DeploymentConfig.command.showDeploymentConfigLog(deployName), undefined, `OpenShift: Show '${deployName}' DeploymentConfig Log`);
107+
await OpenShiftTerminalManager.getInstance().executeInTerminal(DeploymentConfig.command.showDeploymentConfigLog(deployName), undefined, `OpenShift: Show '${deployName}' DeploymentConfig Log`);
107108
}
108109
return deployName;
109110
}

src/openshift/cluster.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { KubeConfigUtils } from '../util/kubeUtils';
1717
import { Platform } from '../util/platform';
1818
import { Progress } from '../util/progress';
1919
import { VsCommandError, vsCommand } from '../vscommand';
20+
import { OpenShiftTerminalManager } from '../webview/openshift-terminal/openShiftTerminal';
2021
import OpenShiftItem, { clusterRequired } from './openshiftItem';
2122
import fetch = require('make-fetch-happen');
2223

@@ -63,12 +64,12 @@ export class Cluster extends OpenShiftItem {
6364

6465
@vsCommand('openshift.about')
6566
static async about(): Promise<void> {
66-
await CliChannel.getInstance().executeInTerminal(Command.printOdoVersion(), undefined, 'Show odo Version');
67+
await OpenShiftTerminalManager.getInstance().executeInTerminal(Command.printOdoVersion(), undefined, 'Show odo Version');
6768
}
6869

6970
@vsCommand('openshift.oc.about')
7071
static async ocAbout(): Promise<void> {
71-
await CliChannel.getInstance().executeInTerminal(Command.printOcVersion(), undefined, 'Show OKD CLI Tool Version');
72+
await OpenShiftTerminalManager.getInstance().executeInTerminal(Command.printOcVersion(), undefined, 'Show OKD CLI Tool Version');
7273
}
7374

7475
@vsCommand('openshift.output')
@@ -248,7 +249,7 @@ export class Cluster extends OpenShiftItem {
248249
} else {
249250
crcBinary = crcPath;
250251
}
251-
void CliChannel.getInstance().executeInTerminal(new CommandText(`${crcBinary} stop`), undefined, 'Stop OpenShift Local');
252+
void OpenShiftTerminalManager.getInstance().executeInTerminal(new CommandText(`${crcBinary} stop`), undefined, 'Stop OpenShift Local');
252253
}
253254

254255
public static async getVersions(): Promise<Versions> {
@@ -528,7 +529,7 @@ export class Cluster extends OpenShiftItem {
528529

529530
static async loginUsingClipboardInfo(dashboardUrl: string): Promise<string | null> {
530531
const clipboard = await Cluster.readFromClipboard();
531-
if(!NameValidator.ocLoginCommandMatches(clipboard)) {
532+
if (!NameValidator.ocLoginCommandMatches(clipboard)) {
532533
const choice = await window.showErrorMessage('Cannot parse login command in clipboard. Please open cluster dashboard and select `Copy login command` from user name dropdown in the upper right corner. Copy full login command to clipboard. Switch back to VSCode window and press `Login to Sandbox` button again.',
533534
'Open Dashboard');
534535
if (choice === 'Open Dashboard') {

0 commit comments

Comments
 (0)