Skip to content

Commit bc5b5f2

Browse files
prachirpfrankfarzan
authored andcommitted
Fix helm template dockerfile and docker e2e tests
1 parent 37abbad commit bc5b5f2

File tree

2 files changed

+68
-7
lines changed

2 files changed

+68
-7
lines changed

tests/e2e.sh

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

3234
############################
3335
# Test framework
@@ -209,6 +211,47 @@ assert_dir_exists payments-dev
209211
assert_dir_exists payments-prod
210212
grep -q allowPrivilegeEscalation podsecuritypolicy_psp.yaml
211213

214+
helm_testcase "docker_helm_template_expected_args"
215+
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
216+
assert_contains_string out.yaml "expected-args"
217+
218+
helm_testcase "docker_helm_template_error_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 2>err.txt || true
220+
assert_contains_string err.txt "${HELM_ERROR_SNIPPET}"
221+
222+
helm_testcase "docker_helm_template_extra_args"
223+
cat >fc.yaml <<EOF
224+
apiVersion: v1
225+
kind: ConfigMap
226+
metadata:
227+
name: my-config
228+
annotations:
229+
config.k8s.io/function: |
230+
container:
231+
image: gcr.io/kpt-functions/helm-template
232+
config.kubernetes.io/local-config: "true"
233+
data:
234+
name: extra-args
235+
chart_path: /source/charts/bitnami/redis
236+
--values: /source/charts/bitnami/redis/values-production.yaml
237+
EOF
238+
docker run -u "$(id -u)" -v "$(pwd)":/source gcr.io/kpt-functions/helm-template:"${TAG}" -i /dev/null -f /source/fc.yaml >out.yaml
239+
assert_contains_string out.yaml "extra-args"
240+
241+
helm_testcase "docker_helm_template_sink"
242+
docker run -u "$(id -u)" -v "$(pwd)/${CHARTS_SRC}":/source gcr.io/kpt-functions/helm-template:"${TAG}" -i /dev/null -d chart_path=/source/redis -d name=sink-redis |
243+
docker run -i -u "$(id -u)" -v "$(pwd)":/sink gcr.io/kpt-functions/write-yaml:"${TAG}" -o /dev/null -d sink_dir=/sink -d overwrite=true
244+
assert_dir_exists default
245+
assert_contains_string default/secret_sink-redis.yaml "sink-redis"
246+
247+
helm_testcase "docker_helm_template_pipeline"
248+
docker run -u "$(id -u)" -v "$(pwd)/${CHARTS_SRC}":/source gcr.io/kpt-functions/helm-template:"${TAG}" -i /dev/null -d chart_path=/source/mongodb -d name=my-mongodb |
249+
docker run -i -u "$(id -u)" -v "$(pwd)/${CHARTS_SRC}":/source gcr.io/kpt-functions/helm-template:"${TAG}" -d name=my-redis -d chart_path=/source/redis |
250+
docker run -i -u "$(id -u)" -v "$(pwd)":/sink gcr.io/kpt-functions/write-yaml:"${TAG}" -o /dev/null -d sink_dir=/sink -d overwrite=true
251+
assert_dir_exists default
252+
assert_contains_string default/secret_my-mongodb.yaml "my-mongodb"
253+
assert_contains_string default/secret_my-redis.yaml "my-redis"
254+
212255
############################
213256
# kpt fn Tests
214257
############################
@@ -273,3 +316,13 @@ EOF
273316
kpt fn run .
274317
grep -qR 'color: orange' .
275318
grep -qR 'city: toronto' .
319+
320+
# TODO: Add kpt_helm_template_imperative_short and kpt_helm_template_declarative tests after fixing <https://github.com/GoogleContainerTools/kpt/issues/587>
321+
helm_testcase "kpt_helm_template_imperative"
322+
kpt fn source example-configs |
323+
docker run -i -u "$(id -u)" -v "$(pwd)/${CHARTS_SRC}":/source gcr.io/kpt-functions/helm-template:"${TAG}" -d chart_path=/source/mongodb -d name=my-mongodb |
324+
docker run -i -u "$(id -u)" -v "$(pwd)/${CHARTS_SRC}":/source gcr.io/kpt-functions/helm-template:"${TAG}" -d name=my-redis -d chart_path=/source/redis |
325+
kpt fn sink example-configs
326+
assert_dir_exists example-configs/default
327+
assert_contains_string example-configs/default/secret_my-mongodb.yaml "my-mongodb"
328+
assert_contains_string example-configs/default/secret_my-redis.yaml "my-redis"

ts/demo-functions/build/helm_template.Dockerfile

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@ RUN npm run build && \
2020

2121
#############################################
2222

23-
FROM alpine/helm:3.2.1
24-
25-
WORKDIR /home/node/app
26-
27-
COPY --from=builder /home/node/app /home/node/app
23+
FROM node:10-alpine
2824

2925
RUN apk add bash curl git
3026
RUN apk update
3127

32-
RUN curl -fsSL -o /usr/local/bin/kpt https://storage.googleapis.com/kpt-dev/latest/linux_amd64/kpt
33-
RUN chmod +x /usr/local/bin/kpt
28+
ENV HELM_LATEST_VERSION="v3.2.1"
29+
RUN curl -fsSL -o /helm-${HELM_LATEST_VERSION}-linux-amd64.tar.gz https://get.helm.sh/helm-${HELM_LATEST_VERSION}-linux-amd64.tar.gz && \
30+
tar -zxvf /helm-${HELM_LATEST_VERSION}-linux-amd64.tar.gz && \
31+
mv /linux-amd64/helm /usr/local/bin/helm && \
32+
rm -f /helm-${HELM_LATEST_VERSION}-linux-amd64.tar.gz && \
33+
rm -rf /linux-amd64
34+
35+
RUN curl -fsSL -o /usr/local/bin/kpt https://storage.googleapis.com/kpt-dev/latest/linux_amd64/kpt && \
36+
chmod +x /usr/local/bin/kpt
37+
3438
ENV PATH /usr/local/bin:$PATH
3539

40+
WORKDIR /home/node/app
41+
42+
COPY --from=builder /home/node/app /home/node/app
43+
3644
ENTRYPOINT ["node", "/home/node/app/dist/helm_template_run.js"]

0 commit comments

Comments
 (0)