Skip to content

Commit a8f39b5

Browse files
prachirpfrankfarzan
authored andcommitted
Further review comments
1 parent a6ce136 commit a8f39b5

File tree

3 files changed

+20
-62
lines changed

3 files changed

+20
-62
lines changed

tests/e2e.sh

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ metadata:
2828
items: []
2929
EOF
3030
)
31-
HELM_ERROR_SNIPPET="Helm template command results in error"
3231
CHARTS_SRC="charts/bitnami"
3332

3433
############################
@@ -177,48 +176,6 @@ assert_dir_exists payments-dev
177176
assert_dir_exists payments-prod
178177
grep -q allowPrivilegeEscalation podsecuritypolicy_psp.yaml
179178

180-
helm_testcase "docker_helm_template_undefined_args"
181-
docker run -u "$(id -u)" -v "$(pwd)/${CHARTS_SRC}":/source gcr.io/kpt-functions/helm-template:"${TAG}" -i /dev/null 2>err.txt || true
182-
assert_contains_string err.txt "Error: functionConfig expected, instead undefined"
183-
184-
helm_testcase "docker_helm_template_empty_fc"
185-
cat >fc.yaml <<EOF
186-
apiVersion: v1
187-
kind: ConfigMap
188-
metadata:
189-
name: empty-config
190-
annotations:
191-
config.k8s.io/function: |
192-
container:
193-
image: gcr.io/kpt-functions/helm-template
194-
config.kubernetes.io/local-config: "true"
195-
data:
196-
EOF
197-
docker run -u "$(id -u)" -v "$(pwd)":/source gcr.io/kpt-functions/helm-template:"${TAG}" -i /dev/null -f /source/fc.yaml 2>err.txt || true
198-
assert_contains_string err.txt "Error: functionConfig expected to contain data, instead empty"
199-
200-
helm_testcase "docker_helm_template_invalid_fc"
201-
cat >fc.yaml <<EOF
202-
apiVersion: v1
203-
kind: ConfigMap
204-
metadata:
205-
name: invalid-config
206-
annotations:
207-
config.k8s.io/function: |
208-
container:
209-
image: gcr.io/kpt-functions/helm-template
210-
config.kubernetes.io/local-config: "true"
211-
data:
212-
name: invalid-fc
213-
chart_path: /path/to/helm/chart
214-
EOF
215-
docker run -u "$(id -u)" -v "$(pwd)":/source gcr.io/kpt-functions/helm-template:"${TAG}" -i /dev/null -f /source/fc.yaml >out.yaml || true
216-
assert_contains_string out.yaml "${HELM_ERROR_SNIPPET}"
217-
218-
helm_testcase "docker_helm_template_too_few_args"
219-
docker run -u "$(id -u)" -v "$(pwd)/${CHARTS_SRC}":/source gcr.io/kpt-functions/helm-template:"${TAG}" -i /dev/null -d name=too-few-args >out.yaml || true
220-
assert_contains_string out.yaml "${HELM_ERROR_SNIPPET}"
221-
222179
helm_testcase "docker_helm_template_expected_args"
223180
docker run -u "$(id -u)" -v "$(pwd)/${CHARTS_SRC}":/source gcr.io/kpt-functions/helm-template:"${TAG}" -i /dev/null -d name=expected-args -d chart_path=/source/redis >out.yaml
224181
assert_contains_string out.yaml "expected-args"

ts/demo-functions/build/helm_template.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ COPY --from=builder /home/node/app /home/node/app
4646
COPY --from=builder /usr/local/bin /usr/local/bin
4747

4848
ENV PATH /usr/local/bin:$PATH
49-
ENV HELM_PATH_CACHE /tmp
49+
ENV HELM_PATH_CACHE /var/cache
5050

5151
ENTRYPOINT ["node", "/home/node/app/dist/helm_template_run.js"]

ts/demo-functions/src/helm_template.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,28 @@ export async function helmTemplate(configs: Configs) {
5353

5454
function readArguments(configs: Configs) {
5555
const args: string[] = [];
56-
57-
// Helm template expects name then chart path then remaining flags
58-
const name = configs.getFunctionConfigValue(CHART_NAME);
59-
if (name) {
60-
args.push(name);
61-
}
62-
const chartPath = configs.getFunctionConfigValue(CHART_PATH);
63-
if (chartPath) {
64-
args.push(chartPath);
65-
}
66-
67-
// Remaining flags
56+
let nameArg;
57+
let pathArg;
6858
const data = readConfigDataOrThrow(configs);
6959
for (const key in data) {
70-
if (key !== CHART_NAME && key !== CHART_PATH) {
60+
if (key === CHART_NAME) {
61+
nameArg = data[key];
62+
} else if (key === CHART_PATH) {
63+
pathArg = data[key];
64+
} else {
7165
args.push(key);
7266
args.push(data[key]);
7367
}
7468
}
7569

70+
// Helm template expects name and chart path first so place those at the beginning
71+
if (pathArg) {
72+
args.unshift(pathArg);
73+
}
74+
if (nameArg) {
75+
args.unshift(nameArg);
76+
}
77+
7678
return args;
7779
}
7880

@@ -95,12 +97,11 @@ function readConfigDataOrThrow(configs: Configs) {
9597
}
9698

9799
helmTemplate.usage = `
98-
Render chart templates locally using helm template. If piped a Kubernetes List in
99-
addition to arguments then render the chart objects into the piped list,
100-
overwriting any chart objects that already exist in the list.
100+
Render chart templates locally using helm template. If input a list of configs in
101+
addition to arguments will overwrite any chart objects that already exist in the list.
101102
102-
Configured using a ConfigMap with keys for ${CHART_NAME}, ${CHART_PATH}, and optional helm
103-
template flags like --values:
103+
Configured using a ConfigMap with keys for ${CHART_NAME}, ${CHART_PATH}.
104+
Works with arbitrary helm template flags like --values:
104105
105106
${CHART_NAME}: Name of helm chart.
106107
${CHART_PATH}: Chart templates directory.

0 commit comments

Comments
 (0)