Skip to content

Commit

Permalink
Added new types to the cluster browser (vscode-kubernetes-tools#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendandburns authored and itowlson committed Oct 11, 2018
1 parent 095b2bc commit 67844cc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 33 deletions.
32 changes: 12 additions & 20 deletions src/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Host } from './host';
import * as kuberesources from './kuberesources';
import { failed } from './errorable';
import * as helmexec from './helm.exec';
import { Pod } from './kuberesources.objectmodel';
import { K8S_RESOURCE_SCHEME, KUBECTL_RESOURCE_AUTHORITY, kubefsUri } from './kuberesources.virtualfs';
import { affectsUs } from './components/config/config';

Expand Down Expand Up @@ -138,7 +139,7 @@ class KubernetesContextNode implements KubernetesObject {
new KubernetesNamespaceFolder(),
new KubernetesNodeFolder(),
new KubernetesWorkloadFolder(),
new KubernetesServiceFolder(),
new KubernetesSelectsPodsFolder(kuberesources.allKinds.service),
new KubernetesResourceFolder(kuberesources.allKinds.ingress),
new KubernetesStorageFolder(),
new KubernetesConfigFolder(),
Expand Down Expand Up @@ -191,10 +192,12 @@ class KubernetesWorkloadFolder extends KubernetesFolder {

getChildren(kubectl: Kubectl, host: Host): vscode.ProviderResult<KubernetesObject[]> {
return [
new KubernetesDeploymentFolder(),
new KubernetesSelectsPodsFolder(kuberesources.allKinds.deployment),
new KubernetesSelectsPodsFolder(kuberesources.allKinds.statefulSet),
new KubernetesSelectsPodsFolder(kuberesources.allKinds.daemonSet),
new KubernetesResourceFolder(kuberesources.allKinds.job),
new KubernetesResourceFolder(kuberesources.allKinds.cronjob),
new KubernetesResourceFolder(kuberesources.allKinds.pod)
new KubernetesResourceFolder(kuberesources.allKinds.pod),
];
}
}
Expand Down Expand Up @@ -265,7 +268,7 @@ class KubernetesResource implements KubernetesObject, ResourceNode {
return kubefsUri(this.namespace, this.resourceId, outputFormat);
}

getChildren(kubectl: Kubectl, host: Host): vscode.ProviderResult<KubernetesObject[]> {
async getChildren(kubectl: Kubectl, host: Host): Promise<KubernetesObject[]> {
return [];
}

Expand Down Expand Up @@ -349,25 +352,14 @@ class KubernetesNamespaceResource extends KubernetesResource {
}
}

class KubernetesServiceFolder extends KubernetesResourceFolder {
constructor() {
super(kuberesources.allKinds.service);
}

async getChildren(kubectl: Kubectl, host: Host): Promise<KubernetesObject[]> {
const services = await kubectlUtils.getServices(kubectl);
return services.map((svc) => new KubernetesSelectorResource(this.kind, svc.name, svc, svc.selector));
}
}

class KubernetesDeploymentFolder extends KubernetesResourceFolder {
constructor() {
super(kuberesources.allKinds.deployment);
class KubernetesSelectsPodsFolder extends KubernetesResourceFolder {
constructor(readonly kind: kuberesources.ResourceKind) {
super(kind);
}

async getChildren(kubectl: Kubectl, host: Host): Promise<KubernetesObject[]> {
const deployments = await kubectlUtils.getDeployments(kubectl);
return deployments.map((dp) => new KubernetesSelectorResource(this.kind, dp.name, dp, dp.selector));
const objects = await kubectlUtils.getResourceWithSelector(this.kind.abbreviation, kubectl);
return objects.map((obj) => new KubernetesSelectorResource(this.kind, obj.name, obj, obj.selector));
}
}

Expand Down
14 changes: 3 additions & 11 deletions src/kubectlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface NamespaceInfo extends KubernetesObject {
readonly active: boolean;
}

export interface PodSelector extends KubernetesObject {
export interface HasSelector extends KubernetesObject {
readonly selector: object;
}

Expand Down Expand Up @@ -145,15 +145,7 @@ export async function getNamespaces(kubectl: Kubectl): Promise<NamespaceInfo[]>
});
}

export async function getServices(kubectl: Kubectl): Promise<PodSelector[]> {
return getPodSelector('services', kubectl);
}

export async function getDeployments(kubectl: Kubectl): Promise<PodSelector[]> {
return getPodSelector('deployments', kubectl);
}

export async function getPodSelector(resource: string, kubectl: Kubectl): Promise<PodSelector[]> {
export async function getResourceWithSelector(resource: string, kubectl: Kubectl): Promise<HasSelector[]> {
const currentNS = await currentNamespace(kubectl);

const shellResult = await kubectl.asJson<KubernetesCollection<any>>(`get ${resource} -o json --namespace=${currentNS}`);
Expand Down Expand Up @@ -201,7 +193,7 @@ export async function getPods(kubectl: Kubectl, selector: any, namespace: string
name: item.name,
namespace: item.namespace || ns,
nodeName: item.node,
status: item.status
status: item.status,
};
});
}
Expand Down
6 changes: 4 additions & 2 deletions src/kuberesources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ export const allKinds = {
namespace: new ResourceKind("Namespace", "Namespaces", "Namespace", "namespace"),
node: new ResourceKind("Node", "Nodes", "Node", "node"),
deployment: new ResourceKind("Deployment", "Deployments", "Deployment", "deployment"),
daemonSet: new ResourceKind("DaemonSet", "DaemonSets", "DaemonSet", "daemonset"),
replicaSet: new ResourceKind("ReplicaSet", "ReplicaSets", "ReplicaSet", "rs"),
replicationController: new ResourceKind("Replication Controller", "Replication Controllers", "ReplicationController", "rc"),
job: new ResourceKind("Job", "Jobs", "Job", "job"),
cronjob: new ResourceKind("Cron Job", "Cron Jobs", "CronJob", "cronjob"),
cronjob: new ResourceKind("CronJob", "CronJobs", "CronJob", "cronjob"),
pod: new ResourceKind("Pod", "Pods", "Pod", "pod"),
service: new ResourceKind("Service", "Services", "Service", "service"),
configMap: new ResourceKind("ConfigMap", "ConfigMaps", "ConfigMap", "configmap"),
configMap: new ResourceKind("ConfigMap", "Config Maps", "ConfigMap", "configmap"),
secret: new ResourceKind("Secret", "Secrets", "Secret", "secret"),
ingress: new ResourceKind("Ingress", "Ingress", "Ingress", "ingress"),
persistentVolume: new ResourceKind("Persistent Volume", "Persistent Volumes", "PersistentVolume", "pv"),
persistentVolumeClaim: new ResourceKind("Persistent Volume Claim", "Persistent Volume Claims", "PersistentVolumeClaim", "pvc"),
storageClass: new ResourceKind("Storage Class", "Storage Classes", "StorageClass", "sc"),
statefulSet: new ResourceKind("StatefulSet", "StatefulSets", "StatefulSet", "statefulset"),
};

export const commonKinds = [
Expand Down

0 comments on commit 67844cc

Please sign in to comment.