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

Restricted the duplicates of pod name #4299

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
6 changes: 2 additions & 4 deletions src/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
}
} else if ('kind' in element && element.kind === 'Deployment') {
try {
const pods = await Oc.Instance.getKubernetesObjects('pods');
return pods.filter((pod) => pod.metadata.name.indexOf(element.metadata.name) !== -1);
return this.getPods(element);
} catch {
return [ couldNotGetItem(element.kind, this.kubeConfig.getCluster(this.kubeContext.cluster)?.server) ];
}
Expand Down Expand Up @@ -659,8 +658,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
}

public async getPods(element: KubernetesObject | OpenShiftObject) {
const pods = await Oc.Instance.getKubernetesObjects('pods');
return pods.filter((pod) => pod.metadata.name.indexOf(element.metadata.name) !== -1);
return await Oc.Instance.getKubernetesObjects('pods', undefined, element.metadata.name);
}

refresh(target?: ExplorerItem): void {
Expand Down
9 changes: 8 additions & 1 deletion src/oc/ocWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ export class Oc {
*
* @param resourceType the type of resource to get a list of
* @param namespace the namespace to list the resources of (defaults to the current namespace if none is provided)
* @param appName the name of the application
* @returns a list of all resources of the given type in the given namespace
*/
public async getKubernetesObjects(
resourceType: string,
namespace?: string,
appName?: string
): Promise<KubernetesObject[]> {
const result = await CliChannel.getInstance().executeTool(
Oc.getKubernetesObjectCommand(resourceType, namespace),
Oc.getKubernetesObjectCommand(resourceType, namespace, appName),
);
return JSON.parse(result.stdout).items;
}
Expand Down Expand Up @@ -688,11 +690,13 @@ export class Oc {
*
* @param resourceType the resource type to get
* @param namespace the namespace from which to get all the stateful sets
* @param appName the name of the application
* @returns the oc command to list all resources of the given type in the given (or current) namespace
*/
private static getKubernetesObjectCommand(
resourceType: string,
namespace?: string,
appName?: string
): CommandText {
if (!resourceType) {
throw new Error('Must pass the resource type to get');
Expand All @@ -701,6 +705,9 @@ export class Oc {
if (namespace) {
args.push(new CommandOption('--namespace', namespace));
}
if (appName) {
args.push(new CommandOption('-l', `app=${appName}`));
}
return new CommandText('oc', `get ${resourceType}`, args);
}

Expand Down
Loading