Skip to content

Commit bb366f5

Browse files
committed
Remove Odo.getActiveCluster() (it's unused)
Closes #3663 Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent 9556fd0 commit bb366f5

File tree

10 files changed

+7
-127
lines changed

10 files changed

+7
-127
lines changed

src/k8s/csv.ts

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
* Licensed under the MIT License. See LICENSE file in the project root for license information.
44
*-----------------------------------------------------------------------------------------------*/
55

6-
import { TreeItem, WebviewPanel, window } from 'vscode';
6+
import { TreeItem } from 'vscode';
77
import { ClusterExplorerV1 } from 'vscode-kubernetes-tools-api';
88
import { Oc } from '../oc/ocWrapper';
9-
import { Odo } from '../odo/odoWrapper';
109
import OpenShiftItem from '../openshift/openshiftItem';
1110
import { CRDDescription, ClusterServiceVersionKind } from './olm/types';
1211

@@ -53,40 +52,4 @@ export class ClusterServiceVersion extends OpenShiftItem {
5352
};
5453
}
5554

56-
static createFormMessageListener(panel: WebviewPanel) {
57-
return async (event: any) => {
58-
if (event.command === 'cancel') {
59-
if (event.changed === true) {
60-
const choice = await window.showWarningMessage('Discard all the changes in the form?', 'Yes', 'No');
61-
if (choice === 'No') {
62-
return;
63-
}
64-
}
65-
panel.dispose();
66-
}
67-
if (event.command === 'create') {
68-
// add waiting for Deployment to be created using wait --for=condition
69-
// no need to wait until it is available
70-
if (!await Odo.Instance.getActiveCluster()) {
71-
// could be expired session
72-
return;
73-
}
74-
75-
try {
76-
// make the service part of the app
77-
event.formData.metadata.labels = {
78-
app: 'app',
79-
'app.kubernetes.io/part-of': 'app'
80-
};
81-
await Oc.Instance.createKubernetesObjectFromSpec(event.formData);
82-
void window.showInformationMessage(`Service ${event.formData.metadata.name} successfully created.`);
83-
panel.dispose();
84-
} catch (err) {
85-
void window.showErrorMessage(err);
86-
await panel.webview.postMessage({action: 'error'});
87-
}
88-
}
89-
}
90-
}
91-
9255
}

src/odo/odoWrapper.ts

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
*-----------------------------------------------------------------------------------------------*/
55

66
import { KubernetesObject } from '@kubernetes/client-node';
7-
import { Uri, WorkspaceFolder, commands, workspace } from 'vscode';
7+
import { Uri, WorkspaceFolder, workspace } from 'vscode';
88
import { CommandOption, CommandText } from '../base/command';
99
import * as cliInstance from '../cli';
1010
import { ToolsConfig } from '../tools';
1111
import { ChildProcessUtil, CliExitData } from '../util/childProcessUtil';
12-
import { KubeConfigUtils } from '../util/kubeUtils';
1312
import { VsCommandError } from '../vscommand';
1413
import { Command } from './command';
1514
import { AnalyzeResponse, ComponentTypeAdapter, ComponentTypeDescription, DevfileComponentType, Registry } from './componentType';
@@ -33,47 +32,6 @@ export class Odo {
3332
// no state
3433
}
3534

36-
/**
37-
* Returns the URL of the API of the current active cluster,
38-
* or undefined if there are no active clusters.
39-
*
40-
* @return the URL of the API of the current active cluster,
41-
* or undefined if there are no active clusters
42-
*/
43-
public async getActiveCluster(): Promise<string> {
44-
const result: CliExitData = await this.execute(
45-
Command.printOdoVersion(),
46-
process.cwd(),
47-
false,
48-
);
49-
50-
const odoCluster = result.stdout
51-
.trim()
52-
.split('\n')
53-
.filter((value) => value.includes('Server:'))
54-
.map((value) => {
55-
return value.substring(value.indexOf(':') + 1).trim();
56-
});
57-
if (odoCluster.length !== 0) {
58-
void commands.executeCommand('setContext', 'isLoggedIn', true);
59-
return odoCluster[0];
60-
}
61-
62-
// odo didn't report an active cluster, try reading it from KubeConfig
63-
try {
64-
const kubeConfigCurrentCluster = new KubeConfigUtils().getCurrentCluster().server;
65-
if (kubeConfigCurrentCluster) {
66-
void commands.executeCommand('setContext', 'isLoggedIn', true);
67-
return kubeConfigCurrentCluster;
68-
}
69-
} catch (e) {
70-
// ignored
71-
}
72-
73-
// no active cluster
74-
void commands.executeCommand('setContext', 'isLoggedIn', false);
75-
}
76-
7735
public async getComponentTypes(): Promise<ComponentTypeAdapter[]> {
7836
// if kc is produced, KUBECONFIG env var is empty or pointing
7937

test/integration/odoWrapper.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ suite('./odo/odoWrapper.ts', function () {
5151
}
5252
});
5353

54-
suite('clusters', function () {
55-
test('getActiveCluster()', async function () {
56-
const activeCluster = await Odo.Instance.getActiveCluster();
57-
expect(activeCluster).to.equal(clusterUrl);
58-
});
59-
});
60-
6154
suite('components', function () {
6255
const project1 = 'my-test-project-1';
6356

test/unit/explorer.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as chai from 'chai';
77
import * as sinonChai from 'sinon-chai';
88
import { commands, Uri } from 'vscode';
99
import { OpenShiftExplorer } from '../../src/explorer';
10-
import { Odo } from '../../src/odo/odoWrapper';
1110
import sinon = require('sinon');
1211

1312
const {expect} = chai;
@@ -16,10 +15,6 @@ chai.use(sinonChai);
1615
suite('OpenShift Application Explorer', () => {
1716
const sandbox = sinon.createSandbox();
1817

19-
setup(() => {
20-
sandbox.stub(Odo.prototype, 'getActiveCluster').resolves('cluster');
21-
});
22-
2318
teardown(() => {
2419
sandbox.restore();
2520
});

test/unit/extension.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import * as sinonChai from 'sinon-chai';
1515
import * as vscode from 'vscode';
1616
import { CommandText } from '../../src/base/command';
1717
import { Oc } from '../../src/oc/ocWrapper';
18-
import { Odo } from '../../src/odo/odoWrapper';
1918
import { Project } from '../../src/oc/project';
19+
import { Odo } from '../../src/odo/odoWrapper';
2020
import { Progress } from '../../src/util/progress';
2121
import path = require('path');
2222

@@ -90,7 +90,6 @@ suite('openshift toolkit Extension', () => {
9090
return { error: undefined, stdout: '', stderr: ''};
9191
});
9292
sandbox.stub(Oc.prototype, 'getAllKubernetesObjects').resolves([]);
93-
sandbox.stub(Odo.prototype, 'getActiveCluster').resolves('cluster');
9493
sandbox.stub(Oc.prototype, 'getProjects').resolves([projectItem]);
9594
});
9695

test/unit/oc.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as sinonChai from 'sinon-chai';
99
import { window } from 'vscode';
1010
import { Oc } from '../../src/oc/ocWrapper';
1111
import { Project } from '../../src/oc/project';
12-
import { Odo } from '../../src/odo/odoWrapper';
1312
import { ToolsConfig } from '../../src/tools';
1413
import { ChildProcessUtil } from '../../src/util/childProcessUtil';
1514
import { YamlFileCommands } from '../../src/yamlFileCommands';
@@ -47,7 +46,6 @@ suite('Oc', function() {
4746
execStub = sandbox.stub(ChildProcessUtil.prototype, 'execute');
4847
getActiveProjectStub = sandbox.stub(Oc.Instance, 'getActiveProject').resolves('my-project');
4948
detectOrDownloadStub = sandbox.stub(ToolsConfig, 'detect').resolves('path');
50-
sandbox.stub(Odo.Instance, 'getActiveCluster').resolves('cluster');
5149
sandbox.stub(Oc.Instance, 'getProjects').resolves([projectItem]);
5250
sandbox.stub(Oc.Instance, 'canCreatePod').resolves(true);
5351
});

test/unit/odoWrapper.test.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ suite('./odo/odoWrapper.ts', () => {
163163

164164
test('getProjects returns empty list if an error occurs', async () => {
165165
const errorStub = sandbox.stub(window, 'showErrorMessage');
166-
sandbox.stub(odoCli, 'getActiveCluster').resolves('https://localhost:8080');
167166
execStub.rejects(errorMessage);
168167
const result = await Oc.Instance.getProjects();
169168

@@ -244,25 +243,4 @@ suite('./odo/odoWrapper.ts', () => {
244243
});
245244
});
246245

247-
suite('odo and oc current cluster detection integration', () => {
248-
const clusterUrl = 'https://localhost:8443';
249-
250-
const odoVersionOutLoggedIn = [
251-
'odo v0.0.15 (2f7ed497)',
252-
'',
253-
`Server: ${clusterUrl}`,
254-
'Kubernetes: v1.11.0+d4cacc0'
255-
];
256-
257-
test('extension uses odo version to get cluster url', async () => {
258-
sandbox.stub(Odo.prototype, 'execute').resolves({
259-
error: undefined,
260-
stdout: odoVersionOutLoggedIn.join('\n'),
261-
stderr: ''
262-
});
263-
const cluster: string = await odoCli.getActiveCluster();
264-
expect(cluster).equals(clusterUrl);
265-
});
266-
267-
});
268246
});

test/unit/openshift/component.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import * as sinon from 'sinon';
1010
import * as sinonChai from 'sinon-chai';
1111
import * as vscode from 'vscode';
1212
import { ComponentInfo, ComponentsTreeDataProvider } from '../../../src/componentsView';
13+
import { Oc } from '../../../src/oc/ocWrapper';
14+
import { Project } from '../../../src/oc/project';
1315
import { Command } from '../../../src/odo/command';
1416
import { ComponentTypeAdapter } from '../../../src/odo/componentType';
1517
import { CommandProvider } from '../../../src/odo/componentTypeDescription';
16-
import { Oc } from '../../../src/oc/ocWrapper';
1718
import { Odo } from '../../../src/odo/odoWrapper';
18-
import { Project } from '../../../src/oc/project';
1919
import { ComponentWorkspaceFolder, OdoWorkspace } from '../../../src/odo/workspace';
2020
import * as openShiftComponent from '../../../src/openshift/component';
2121
import * as Util from '../../../src/util/async';
@@ -130,7 +130,6 @@ suite('OpenShift/Component', function () {
130130
Component = pq('../../../src/openshift/component', {}).Component;
131131
termStub = sandbox.stub(OpenShiftTerminalManager.prototype, 'executeInTerminal');
132132
execStub = sandbox.stub(Odo.prototype, 'execute').resolves({ stdout: '', stderr: undefined, error: undefined });
133-
sandbox.stub(Odo.prototype, 'getActiveCluster').resolves('cluster');
134133
sandbox.stub(Oc.prototype, 'getProjects').resolves([projectItem]);
135134
sandbox.stub(Odo.prototype, 'describeComponent').resolves(componentItem1.component);
136135
sandbox.stub(OdoWorkspace.prototype, 'getComponents').resolves([componentItem1]);

test/unit/openshift/nameValidator.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import * as chai from 'chai';
77
import * as sinonChai from 'sinon-chai';
8-
import { Odo } from '../../../src/odo/odoWrapper';
98
import * as NameValidator from '../../../src/openshift/nameValidator';
109
import { wait } from '../../../src/util/async';
1110
import sinon = require('sinon');
@@ -18,7 +17,6 @@ suite('nameValidator', function () {
1817

1918
setup(function () {
2019
sandbox = sinon.createSandbox();
21-
sandbox.stub(Odo.prototype, 'getActiveCluster').resolves('cluster');
2220
});
2321

2422
teardown(function () {

test/unit/openshift/project.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import * as sinon from 'sinon';
88
import * as sinonChai from 'sinon-chai';
99
import * as vscode from 'vscode';
1010
import { CommandText } from '../../../src/base/command';
11-
import { Odo } from '../../../src/odo/odoWrapper';
12-
import { Oc} from '../../../src/oc/ocWrapper';
11+
import { Oc } from '../../../src/oc/ocWrapper';
1312
import { Project as OdoProject } from '../../../src/oc/project';
13+
import { Odo } from '../../../src/odo/odoWrapper';
1414
import { Project } from '../../../src/openshift/project';
1515

1616
const {expect} = chai;
@@ -28,7 +28,6 @@ suite('OpenShift/Project', () => {
2828
setup(() => {
2929
projectItem = { name: 'project', active: true };
3030
sandbox = sinon.createSandbox();
31-
sandbox.stub(Odo.prototype, 'getActiveCluster').resolves('cluster');
3231
sandbox.stub(Oc.prototype, 'getProjects').resolves([projectItem]);
3332
execStub = sandbox.stub(Odo.prototype, 'execute').resolves({error: undefined, stdout: '', stderr: ''});
3433
createProjectStub = sandbox.stub(Oc.prototype, 'createProject').resolves();

0 commit comments

Comments
 (0)