Skip to content

Commit dce46df

Browse files
committed
List operator-backed services in the sidebar
Closes #3494 Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent 3d3aebb commit dce46df

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

src/explorer.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ import {
2424
import * as Helm from './helm/helm';
2525
import { Oc } from './oc/ocWrapper';
2626
import { Odo } from './odo/odoWrapper';
27+
import { getServiceKindStubs } from './openshift/service';
2728
import { KubeConfigUtils, getKubeConfigFiles } from './util/kubeUtils';
2829
import { Platform } from './util/platform';
2930
import { Progress } from './util/progress';
3031
import { FileContentChangeNotifier, WatchUtil } from './util/watch';
3132
import { vsCommand } from './vscommand';
33+
import { CustomResourceDefinitionStub } from './webview/common/createServiceTypes';
3234

3335
type ExplorerItem = KubernetesObject | Helm.HelmRelease | Context | TreeItem;
3436

@@ -223,11 +225,27 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
223225
}
224226
}
225227
} else {
226-
result = [
227-
...await Oc.Instance.getKubernetesObjects('DeploymentConfig'),
228-
...await Oc.Instance.getKubernetesObjects('Deployment'),
229-
...await Helm.getHelmReleases()
228+
229+
let serviceKinds: CustomResourceDefinitionStub[] = [];
230+
try {
231+
serviceKinds = await getServiceKindStubs();
232+
} catch (_) {
233+
// operator framework is not installed on cluster; do nothing
234+
}
235+
236+
const toCollect = [
237+
Oc.Instance.getKubernetesObjects('Deployment'),
238+
Helm.getHelmReleases(),
239+
...serviceKinds.map(serviceKind => Oc.Instance.getKubernetesObjects(serviceKind.name))
230240
];
241+
if (await Oc.Instance.isOpenShiftCluster()) {
242+
toCollect.push(
243+
Oc.Instance.getKubernetesObjects('DeploymentConfig'),
244+
)
245+
}
246+
247+
result = await Promise.all(toCollect).then(listOfLists => listOfLists.flatMap(a => a as ExplorerItem[]));
248+
231249
}
232250
// don't show Open In Developer Dashboard if not openshift cluster
233251
const isOpenshiftCluster = await Oc.Instance.isOpenShiftCluster();

src/openshift/service.ts

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

6+
import { Oc } from '../oc/ocWrapper';
67
import { vsCommand } from '../vscommand';
8+
import { ClusterServiceVersion, CustomResourceDefinitionStub } from '../webview/common/createServiceTypes';
79
import CreateServiceViewLoader from '../webview/create-service/createServiceViewLoader';
810

911
/**
@@ -15,3 +17,18 @@ export class Service {
1517
await CreateServiceViewLoader.loadView();
1618
}
1719
}
20+
21+
export async function getServiceKindStubs(): Promise<CustomResourceDefinitionStub[]> {
22+
const clusterServiceVersions = (await Oc.Instance.getKubernetesObjects(
23+
'csv',
24+
)) as ClusterServiceVersion[];
25+
return clusterServiceVersions.flatMap(
26+
(clusterServiceVersion) => {
27+
const serviceKinds = clusterServiceVersion.spec.customresourcedefinitions.owned;
28+
for (const serviceKind of serviceKinds) {
29+
serviceKind.csvDescription = clusterServiceVersion.spec.description;
30+
}
31+
return serviceKinds;
32+
},
33+
);
34+
}

src/webview/create-service/createServiceViewLoader.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import { JSONSchema7 } from 'json-schema';
88
import * as _ from 'lodash';
99
import * as path from 'path';
1010
import * as vscode from 'vscode';
11+
import { OpenShiftExplorer } from '../../explorer';
1112
import { ClusterServiceVersionKind, CustomResourceDefinitionKind } from '../../k8s/olm/types';
1213
import { Oc } from '../../oc/ocWrapper';
1314
import { Odo } from '../../odo/odoWrapper';
15+
import { getServiceKindStubs } from '../../openshift/service';
1416
import { ExtensionID } from '../../util/constants';
1517
import { loadWebviewHtml } from '../common-ext/utils';
1618
import type {
17-
ClusterServiceVersion,
1819
CustomResourceDefinitionStub,
1920
SpecDescriptor
2021
} from '../common/createServiceTypes';
@@ -147,6 +148,7 @@ export default class CreateServiceViewLoader {
147148
void vscode.window.showInformationMessage(`Service ${(message.data as unknown as any).metadata.name} successfully created.` );
148149
CreateServiceViewLoader.panel.dispose();
149150
CreateServiceViewLoader.panel = undefined;
151+
OpenShiftExplorer.getInstance().refresh();
150152
} catch (err) {
151153
void CreateServiceViewLoader.panel.webview.postMessage({
152154
action: 'error',
@@ -162,21 +164,6 @@ export default class CreateServiceViewLoader {
162164
}
163165
}
164166

165-
async function getServiceKindStubs(): Promise<CustomResourceDefinitionStub[]> {
166-
const clusterServiceVersions = (await Oc.Instance.getKubernetesObjects(
167-
'csv',
168-
)) as ClusterServiceVersion[];
169-
return clusterServiceVersions.flatMap(
170-
(clusterServiceVersion) => {
171-
const serviceKinds = clusterServiceVersion.spec.customresourcedefinitions.owned;
172-
for (const serviceKind of serviceKinds) {
173-
serviceKind.csvDescription = clusterServiceVersion.spec.description;
174-
}
175-
return serviceKinds;
176-
},
177-
);
178-
}
179-
180167
/**
181168
* @see `csv.ts`
182169
*/

0 commit comments

Comments
 (0)