Skip to content

Commit

Permalink
Pod status indicators in tree view (vscode-kubernetes-tools#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreyas Karnik authored and itowlson committed Jul 18, 2018
1 parent 4cc73bb commit 6d31642
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ class KubernetesResourceFolder extends KubernetesFolder {
}

async getChildren(kubectl: Kubectl, host: Host): Promise<KubernetesObject[]> {
if (this.kind === kuberesources.allKinds.pod) {
const pods = await kubectlUtils.getPods(kubectl, null, null);
return pods.map((pod) => {
return new KubernetesResource(this.kind, pod.name, pod);
});
}
const childrenLines = await kubectl.asLines(`get ${this.kind.abbreviation}`);
if (failed(childrenLines)) {
host.showErrorMessage(childrenLines.error[0]);
Expand Down Expand Up @@ -240,6 +246,9 @@ class KubernetesResource implements KubernetesObject, ResourceNode {
this.kind === kuberesources.allKinds.secret ||
this.kind === kuberesources.allKinds.configMap) {
treeItem.contextValue = `vsKubernetes.resource.${this.kind.abbreviation}`;
if (this.kind === kuberesources.allKinds.pod && this.metadata && this.metadata.status) {
treeItem.iconPath = getIconForPodStatus(this.metadata.status.toLowerCase());
}
}
if (this.namespace) {
treeItem.tooltip = `Namespace: ${this.namespace}`; // TODO: show only if in non-current namespace?
Expand Down
13 changes: 8 additions & 5 deletions src/kubectlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface PodSelector extends KubernetesObject {
export interface PodInfo extends KubernetesObject {
readonly namespace: string;
readonly nodeName: string;
readonly status: string;
}

export interface ClusterConfig {
Expand Down Expand Up @@ -189,16 +190,18 @@ export async function getPods(kubectl: Kubectl, selector: any, namespace: string
labelStr = "--selector=" + labels.join(",");
}

const pods = await kubectl.asJson<KubernetesCollection<Pod>>(`get pods -o json ${nsFlag} ${labelStr}`);
const pods = await kubectl.fromLines(`get pods -o wide ${nsFlag} ${labelStr}`);
if (failed(pods)) {
vscode.window.showErrorMessage(pods.error[0]);
return [];
}
return pods.result.items.map((item) => {

return pods.result.map((item) => {
return {
name: item.metadata.name,
namespace: item.metadata.namespace,
nodeName: item.spec.nodeName
name: item.name,
namespace: item.namespace || ns,
nodeName: item.node,
status: item.status
};
});
}
Expand Down

0 comments on commit 6d31642

Please sign in to comment.