Skip to content

Commit

Permalink
fix: added configuration for namespaced refs
Browse files Browse the repository at this point in the history
  • Loading branch information
olensmar committed Oct 12, 2021
1 parent 8baeb3a commit f3a1f19
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/kindhandlers/common/outgoingRefMappers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {RefMapper} from '@models/resourcekindhandler';
import {NamespaceRefEnum, RefMapper} from '@models/resourcekindhandler';

const ConfigMapTarget = {
target: {
Expand All @@ -21,6 +21,13 @@ const ServiceAccountTarget = {
},
};

const PersistentVolumeClaimTarget = {
target: {
kind: 'PersistentVolumeClaim',
pathParts: ['metadata', 'name'],
},
};

export const PodOutgoingRefMappers: RefMapper[] = [
{
source: {
Expand All @@ -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: {
Expand All @@ -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,
},
Expand All @@ -97,6 +133,7 @@ export const PodOutgoingRefMappers: RefMapper[] = [
{
source: {
pathParts: ['imagePullSecrets'],
namespaceRef: NamespaceRefEnum.Implicit,
},
...SecretTarget,
},
Expand All @@ -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,
},
];
9 changes: 9 additions & 0 deletions src/models/resourcekindhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f3a1f19

Please sign in to comment.