MCPcopy Create free account
hub / github.com/RisingStack/anchor / transformContainers

Function transformContainers

src/transform/pod.js:5–98  ·  view source on GitHub ↗
(inputValues, inputChart, scope = '')

Source from the content-addressed store, hash-verified

3const fp = require('lodash/fp')
4
5function transformContainers (inputValues, inputChart, scope = '') {
6 const valuesPrefix = scope ? `.Values.${scope}` : '.Values'
7 const values = Object.assign({}, inputValues)
8 const chart = Object.assign({}, inputChart)
9
10 chart.spec.containers = chart.spec.containers.map((container, key) => {
11 const containerName = fp.camelCase(container.name) || key.toString()
12 let templateValuePathPrefix
13 let containerValues
14
15 // Simplify with one container
16 if (chart.spec.containers.length > 1) {
17 templateValuePathPrefix = `${valuesPrefix}.containers.${containerName}`
18
19 values.containers = values.containers || {}
20 values.containers[containerName] = values.containers[containerName] || {}
21 containerValues = values.containers[containerName]
22 } else {
23 templateValuePathPrefix = `${valuesPrefix}`
24 containerValues = values
25 }
26
27 // Image
28 const tmp = container.image.split(':')
29 const image = tmp[0]
30 const imageTag = tmp[1]
31
32 containerValues.image = image
33 if (imageTag) {
34 // prevent casting to Number
35 containerValues.imageTag = imageTag.toString()
36 }
37
38 container.image = `"{{ ${templateValuePathPrefix}.image }}:`
39 + `{{ ${templateValuePathPrefix}.imageTag }}"`
40
41 // Environment variables
42 if (container.env) {
43 container.env = container.env.map((env) => {
44 if (!env.value) {
45 return env
46 }
47
48 const envName = fp.camelCase(`env_${env.name}`)
49
50 containerValues[envName] = env.value
51
52 return Object.assign({}, env, {
53 value: `{{ ${templateValuePathPrefix}.${envName} | quote }}`
54 })
55 })
56 }
57
58 // Resources
59 if (container.resources) {
60 if (container.resources.limits) {
61 if (container.resources.limits.cpu) {
62 containerValues.resourcesLimitsCPU = container.resources.limits.cpu

Callers 1

transformFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected