Skip to content

Commit

Permalink
fix(k8s): filter out undefined environment variable values
Browse files Browse the repository at this point in the history
  • Loading branch information
solomonope authored and edvald committed Sep 7, 2020
1 parent 94a6280 commit 852b85c
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions core/src/plugins/kubernetes/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,29 +333,31 @@ export function flattenResources(resources: KubernetesResource[]) {
* Maps an array of env vars, as specified on a container module, to a list of Kubernetes `V1EnvVar`s.
*/
export function prepareEnvVars(env: ContainerEnvVars): V1EnvVar[] {
return Object.entries(env).map(([name, value]) => {
if (value === null) {
return { name, value: "null" }
} else if (typeof value === "object") {
if (!value.secretRef.key) {
throw new ConfigurationError(`kubernetes: Must specify \`key\` on secretRef for env variable ${name}`, {
return Object.entries(env)
.filter(([_, value]) => value !== undefined)
.map(([name, value]) => {
if (value === null) {
return { name, value: "null" }
} else if (typeof value === "object") {
if (!value.secretRef.key) {
throw new ConfigurationError(`kubernetes: Must specify \`key\` on secretRef for env variable ${name}`, {
name,
value,
})
}
return {
name,
value,
})
}
return {
name,
valueFrom: {
secretKeyRef: {
name: value.secretRef.name,
key: value.secretRef.key!,
valueFrom: {
secretKeyRef: {
name: value.secretRef.name,
key: value.secretRef.key!,
},
},
},
}
} else {
return { name, value: value.toString() }
}
} else {
return { name, value: value.toString() }
}
})
})
}

/**
Expand Down

0 comments on commit 852b85c

Please sign in to comment.