Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error popup when expanding project in Application Explorer #3520 #3644

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,19 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
} else {
let serviceKinds: CustomResourceDefinitionStub[] = [];
try {
serviceKinds = await getServiceKindStubs();
if (await Oc.Instance.canGetKubernetesObjects('csv')) {
serviceKinds = await getServiceKindStubs();
}
} catch (_) {
// operator framework is not installed on cluster; do nothing
}

const toCollect = [
Oc.Instance.getKubernetesObjects('Deployment'),
Helm.getHelmReleases(),
...serviceKinds.map(serviceKind => Oc.Instance.getKubernetesObjects(serviceKind.name))
...serviceKinds
.filter(serviceKind => Oc.Instance.canGetKubernetesObjects(serviceKind.name))
.map(serviceKind => Oc.Instance.getKubernetesObjects(serviceKind.name))
];
if (await Oc.Instance.isOpenShiftCluster()) {
toCollect.push(
Expand Down
20 changes: 20 additions & 0 deletions src/oc/ocWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,26 @@ export class Oc {
return false;
}

/**
* Returns true if the current user is authorized to get a kubernates objects on the cluster, and false otherwise.
*
* @param resourceType the string containing the [TYPE | TYPE/NAME | NONRESOURCEURL] of the kubernetes object
* @returns true if the current user is authorized to get a kubernates objects on the cluster, and false otherwise
*/
public async canGetKubernetesObjects(resourceType: string): Promise<boolean> {
try {
const result = await CliChannel.getInstance().executeTool(
new CommandText('oc', `auth can-i get ${resourceType}`),
);
if (result.stdout === 'yes') {
return true;
}
} catch {
//ignore
}
return false;
}

/**
* Deletes all deployments in the current namespace that have a label "component" with a value `componentName`.
*
Expand Down