diff --git a/src/explorer.ts b/src/explorer.ts index ea469cbc8..093e2dc6b 100644 --- a/src/explorer.ts +++ b/src/explorer.ts @@ -192,6 +192,7 @@ class KubernetesWorkloadFolder extends KubernetesFolder { return [ new KubernetesDeploymentFolder(), new KubernetesResourceFolder(kuberesources.allKinds.job), + new KubernetesResourceFolder(kuberesources.allKinds.cronjob), new KubernetesResourceFolder(kuberesources.allKinds.pod) ]; } diff --git a/src/kuberesources.linkprovider.ts b/src/kuberesources.linkprovider.ts index 0353789e4..521e2fc32 100644 --- a/src/kuberesources.linkprovider.ts +++ b/src/kuberesources.linkprovider.ts @@ -75,11 +75,17 @@ function key(node: yl.YamlNode): string | undefined { function parentKey(node: yl.YamlNode): string | undefined { const parent = node.parent; - if (!parent || !parent.parent || !yl.isMapping(parent.parent)) { + if (!parent) { return undefined; } - const parentPair = parent.parent.mappings.find((mi) => mi.value === parent); - return key(parentPair); + if (parent.parent && yl.isMapping(parent.parent)) { + const parentPair = parent.parent.mappings.find((mi) => mi.value === parent); + const parentKey = key(parentPair); + if (parentKey) { + return parentKey; + } + } + return parentKey(parent); } function siblings(node: yl.YamlMappingItem): yl.YamlMappingItem[] { @@ -112,6 +118,12 @@ function getLinkUri(sourceKind: string, node: yl.YamlMappingItem): vscode.Uri | if (key(node) === 'namespace' && parentKey(node) === 'metadata') { return kubefsUri(null, `ns/${node.value.raw}`, 'yaml'); } + if (key(node) === 'name' && parentKey(node) === 'ownerReferences') { + const ownerKind = k8sKindFromManifestKind(sibling(node, 'kind')); + if (ownerKind) { + return kubefsUri(null, `${ownerKind}/${node.value.raw}`, 'yaml'); + } + } // Source=type-specific navigation switch (sourceKind) { @@ -164,3 +176,8 @@ function k8sKind(document: vscode.TextDocument): string { const kindSepIndex = k8sid.indexOf('/'); return k8sid.substring(0, kindSepIndex); } + +function k8sKindFromManifestKind(manifestKind: string): string | undefined { + const resourceKind = kuberesources.findKind(manifestKind); + return resourceKind ? resourceKind.abbreviation : undefined; +} diff --git a/src/kuberesources.ts b/src/kuberesources.ts index 019a2885e..adac20863 100644 --- a/src/kuberesources.ts +++ b/src/kuberesources.ts @@ -1,7 +1,7 @@ import * as vscode from 'vscode'; export class ResourceKind implements vscode.QuickPickItem { - constructor(readonly displayName: string, readonly pluralDisplayName: string, readonly abbreviation: string) { + constructor(readonly displayName: string, readonly pluralDisplayName: string, readonly manifestKind: string, readonly abbreviation: string) { } get label() { return this.displayName; } @@ -9,20 +9,21 @@ export class ResourceKind implements vscode.QuickPickItem { } export const allKinds = { - namespace: new ResourceKind("Namespace", "Namespaces", "namespace"), - node: new ResourceKind("Node", "Nodes", "node"), - deployment: new ResourceKind("Deployment", "Deployments", "deployment"), - replicaSet: new ResourceKind("ReplicaSet", "ReplicaSets", "rs"), - replicationController: new ResourceKind("Replication Controller", "Replication Controllers", "rc"), - job: new ResourceKind("Job", "Jobs", "job"), - pod: new ResourceKind("Pod", "Pods", "pod"), - service: new ResourceKind("Service", "Services", "service"), - configMap: new ResourceKind("ConfigMap", "ConfigMaps", "configmap"), - secret: new ResourceKind("Secret", "Secrets", "secret"), - ingress: new ResourceKind("Ingress", "Ingress", "ingress"), - persistentVolume: new ResourceKind("Persistent Volume", "Persistent Volumes", "pv"), - persistentVolumeClaim: new ResourceKind("Persistent Volume Claim", "Persistent Volume Claims", "pvc"), - storageClass: new ResourceKind("Storage Class", "Storage Classes", "sc"), + namespace: new ResourceKind("Namespace", "Namespaces", "Namespace", "namespace"), + node: new ResourceKind("Node", "Nodes", "Node", "node"), + deployment: new ResourceKind("Deployment", "Deployments", "Deployment", "deployment"), + 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"), + pod: new ResourceKind("Pod", "Pods", "Pod", "pod"), + service: new ResourceKind("Service", "Services", "Service", "service"), + configMap: new ResourceKind("ConfigMap", "ConfigMaps", "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"), }; export const commonKinds = [ @@ -46,3 +47,12 @@ export const exposableKinds = [ allKinds.replicaSet, allKinds.service, ]; + +export function findKind(manifestKind: string): ResourceKind | undefined { + for (const k in allKinds) { + if (allKinds[k].manifestKind === manifestKind) { + return allKinds[k]; + } + } + return undefined; +}