diff --git a/src/kindhandlers/common/outgoingRefMappers.ts b/src/kindhandlers/common/outgoingRefMappers.ts index 3ac508dec5..7c1c4ecb16 100644 --- a/src/kindhandlers/common/outgoingRefMappers.ts +++ b/src/kindhandlers/common/outgoingRefMappers.ts @@ -1,4 +1,4 @@ -import {RefMapper} from '@models/resourcekindhandler'; +import {NamespaceRefEnum, RefMapper} from '@models/resourcekindhandler'; const ConfigMapTarget = { target: { @@ -21,6 +21,13 @@ const ServiceAccountTarget = { }, }; +const PersistentVolumeClaimTarget = { + target: { + kind: 'PersistentVolumeClaim', + pathParts: ['metadata', 'name'], + }, +}; + export const PodOutgoingRefMappers: RefMapper[] = [ { source: { @@ -43,12 +50,29 @@ export const PodOutgoingRefMappers: RefMapper[] = [ ...ConfigMapTarget, }, { + // https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#secretvolumesource-v1-core source: { pathParts: ['volumes', 'secret', 'secretName'], hasOptionalSibling: true, }, ...SecretTarget, }, + { + // https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#azurefilepersistentvolumesource-v1-core + source: { + pathParts: ['azureFile', 'secretName'], + namespaceRef: NamespaceRefEnum.Explicit, + namespaceProperty: 'secretNamespace', + }, + ...SecretTarget, + }, + { + // https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#azurefilevolumesource-v1-core + source: { + pathParts: ['volumes', 'azureFile', 'secretName'], + }, + ...SecretTarget, + }, { // https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#secretprojection-v1-core source: { @@ -58,32 +82,44 @@ export const PodOutgoingRefMappers: RefMapper[] = [ ...SecretTarget, }, { + // secretRefs can be one of https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#objectreference-v1-core (with namespace) + // or https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#secretreference-v1-core (with namespace) + // or https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#localobjectreference-v1-core (without namespace) source: { pathParts: ['secretRef', 'name'], + namespaceRef: NamespaceRefEnum.OptionalImplicit, // secretRefs can be either }, ...SecretTarget, }, { + // https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#secretreference-v1-core (with namespace) source: { pathParts: ['controllerExpandSecretRef', 'name'], + namespaceRef: NamespaceRefEnum.Explicit, }, ...SecretTarget, }, { + // https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#secretreference-v1-core (with namespace) source: { pathParts: ['controllerPublishSecretRef', 'name'], + namespaceRef: NamespaceRefEnum.Explicit, }, ...SecretTarget, }, { + // https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#secretreference-v1-core (with namespace) source: { pathParts: ['nodePublishSecretRef', 'name'], + namespaceRef: NamespaceRefEnum.Explicit, }, ...SecretTarget, }, { + // https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#secretreference-v1-core (with namespace) source: { pathParts: ['nodeStageSecretRef', 'name'], + namespaceRef: NamespaceRefEnum.Explicit, }, ...SecretTarget, }, @@ -97,6 +133,7 @@ export const PodOutgoingRefMappers: RefMapper[] = [ { source: { pathParts: ['imagePullSecrets'], + namespaceRef: NamespaceRefEnum.Implicit, }, ...SecretTarget, }, @@ -106,4 +143,12 @@ export const PodOutgoingRefMappers: RefMapper[] = [ }, ...ServiceAccountTarget, }, + { + // https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#persistentvolumeclaimvolumesource-v1-core + source: { + pathParts: ['persistentVolumeClaim', 'claimName'], + namespaceRef: NamespaceRefEnum.Implicit, + }, + ...PersistentVolumeClaimTarget, + }, ]; diff --git a/src/models/resourcekindhandler.ts b/src/models/resourcekindhandler.ts index 119e632b3e..4762ee47bc 100644 --- a/src/models/resourcekindhandler.ts +++ b/src/models/resourcekindhandler.ts @@ -5,10 +5,19 @@ interface SymbolMatcher { isMatch?(symbols: monaco.languages.DocumentSymbol[]): boolean; } +export enum NamespaceRefEnum { + None, // ignore namespaces for this ref + Implicit, // use the namespace of the containing resource + Explicit, // target namespace property expected + OptionalImplicit, // if no namespace is provided then use the namespace of the containing resource +} + interface RefMapper { source: { pathParts: string[]; hasOptionalSibling?: boolean; + namespaceRef?: NamespaceRefEnum; + namespaceProperty?: string; // default to "namespace" }; target: { kind: string;