Skip to content

Commit b859e8d

Browse files
vrubezhnydatho7561
authored andcommitted
Error popup when expanding project in Application Explorer #3520
Fixes: #3520 Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
1 parent 55ba4ff commit b859e8d

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/explorer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,19 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
270270
} else {
271271
let serviceKinds: CustomResourceDefinitionStub[] = [];
272272
try {
273-
serviceKinds = await getServiceKindStubs();
273+
if (await Oc.Instance.canGetKubernetesObjects('csv')) {
274+
serviceKinds = await getServiceKindStubs();
275+
}
274276
} catch (_) {
275277
// operator framework is not installed on cluster; do nothing
276278
}
277279

278280
const toCollect = [
279281
Oc.Instance.getKubernetesObjects('Deployment'),
280282
Helm.getHelmReleases(),
281-
...serviceKinds.map(serviceKind => Oc.Instance.getKubernetesObjects(serviceKind.name))
283+
...serviceKinds
284+
.filter(serviceKind => Oc.Instance.canGetKubernetesObjects(serviceKind.name))
285+
.map(serviceKind => Oc.Instance.getKubernetesObjects(serviceKind.name))
282286
];
283287
if (await Oc.Instance.isOpenShiftCluster()) {
284288
toCollect.push(

src/oc/ocWrapper.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,26 @@ export class Oc {
194194
return false;
195195
}
196196

197+
/**
198+
* Returns true if the current user is authorized to get a kubernates objects on the cluster, and false otherwise.
199+
*
200+
* @param resourceType the string containing the [TYPE | TYPE/NAME | NONRESOURCEURL] of the kubernetes object
201+
* @returns true if the current user is authorized to get a kubernates objects on the cluster, and false otherwise
202+
*/
203+
public async canGetKubernetesObjects(resourceType: string): Promise<boolean> {
204+
try {
205+
const result = await CliChannel.getInstance().executeTool(
206+
new CommandText('oc', `auth can-i get ${resourceType}`),
207+
);
208+
if (result.stdout === 'yes') {
209+
return true;
210+
}
211+
} catch {
212+
//ignore
213+
}
214+
return false;
215+
}
216+
197217
/**
198218
* Deletes all deployments in the current namespace that have a label "component" with a value `componentName`.
199219
*

0 commit comments

Comments
 (0)