Skip to content

Commit cc2146a

Browse files
committed
Do not attempt to list cluster-scoped resources
Unprivledged accounts probably don't have access to these resources. Fixes #3726 Signed-off-by: David Thompson <[email protected]>
1 parent 545e954 commit cc2146a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/explorer.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,17 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
304304
// operator framework is not installed on cluster; do nothing
305305
}
306306

307+
const collectableServices: CustomResourceDefinitionStub[] = [];
308+
await Promise.all(serviceKinds.map(async serviceKind => {
309+
if (await Oc.Instance.canGetKubernetesObjects(serviceKind.name)) {
310+
collectableServices.push(serviceKind);
311+
}
312+
}));
313+
307314
const toCollect = [
308315
Oc.Instance.getKubernetesObjects('Deployment'),
309316
Helm.getHelmReleases(),
310-
...serviceKinds
311-
.filter(serviceKind => Oc.Instance.canGetKubernetesObjects(serviceKind.name))
317+
...collectableServices
312318
.map(serviceKind => Oc.Instance.getKubernetesObjects(serviceKind.name))
313319
];
314320
if (await Oc.Instance.isOpenShiftCluster()) {

src/oc/ocWrapper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import * as fs from 'fs/promises';
88
import * as tmp from 'tmp';
99
import { CommandOption, CommandText } from '../base/command';
1010
import { CliChannel } from '../cli';
11-
import { ClusterType, KubernetesConsole } from './types';
1211
import { Platform } from '../util/platform';
12+
import { ClusterType, KubernetesConsole } from './types';
1313

1414
/**
1515
* A wrapper around the `oc` CLI tool.
@@ -243,7 +243,7 @@ export class Oc {
243243
const result = await CliChannel.getInstance().executeTool(
244244
new CommandText('oc', `auth can-i get ${resourceType}`),
245245
);
246-
if (result.stdout === 'yes') {
246+
if (result.stdout === 'yes' && result.stderr.indexOf('not namespace scoped') < 0) {
247247
return true;
248248
}
249249
} catch {

0 commit comments

Comments
 (0)