diff --git a/src/explorer.ts b/src/explorer.ts index 94800ad3b..823e408d5 100644 --- a/src/explorer.ts +++ b/src/explorer.ts @@ -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'; @@ -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(), @@ -191,10 +192,12 @@ class KubernetesWorkloadFolder extends KubernetesFolder { getChildren(kubectl: Kubectl, host: Host): vscode.ProviderResult { 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), ]; } } @@ -265,7 +268,7 @@ class KubernetesResource implements KubernetesObject, ResourceNode { return kubefsUri(this.namespace, this.resourceId, outputFormat); } - getChildren(kubectl: Kubectl, host: Host): vscode.ProviderResult { + async getChildren(kubectl: Kubectl, host: Host): Promise { return []; } @@ -349,25 +352,14 @@ class KubernetesNamespaceResource extends KubernetesResource { } } -class KubernetesServiceFolder extends KubernetesResourceFolder { - constructor() { - super(kuberesources.allKinds.service); - } - - async getChildren(kubectl: Kubectl, host: Host): Promise { - 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 { - 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)); } } diff --git a/src/kubectlUtils.ts b/src/kubectlUtils.ts index 9d67d69df..262bca2d3 100644 --- a/src/kubectlUtils.ts +++ b/src/kubectlUtils.ts @@ -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; } @@ -145,15 +145,7 @@ export async function getNamespaces(kubectl: Kubectl): Promise }); } -export async function getServices(kubectl: Kubectl): Promise { - return getPodSelector('services', kubectl); -} - -export async function getDeployments(kubectl: Kubectl): Promise { - return getPodSelector('deployments', kubectl); -} - -export async function getPodSelector(resource: string, kubectl: Kubectl): Promise { +export async function getResourceWithSelector(resource: string, kubectl: Kubectl): Promise { const currentNS = await currentNamespace(kubectl); const shellResult = await kubectl.asJson>(`get ${resource} -o json --namespace=${currentNS}`); @@ -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, }; }); } diff --git a/src/kuberesources.ts b/src/kuberesources.ts index adac20863..5dc455682 100644 --- a/src/kuberesources.ts +++ b/src/kuberesources.ts @@ -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 = [