Skip to content

Commit 37abbad

Browse files
prachirpfrankfarzan
authored andcommitted
Helm template typescript function
1 parent 6b27fd6 commit 37abbad

File tree

6 files changed

+448
-113
lines changed

6 files changed

+448
-113
lines changed

tests/e2e.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,24 @@ function testcase() {
4040
cd "${tmp}"
4141
}
4242

43+
function helm_testcase() {
44+
echo "testcase: ${1}"
45+
tmp=$(mktemp -d "/tmp/e2e.${1}.XXXXXXXX")
46+
cp -r "${REPO}"/example-configs "${tmp}"
47+
cd "${tmp}"
48+
git clone -q https://github.com/bitnami/charts.git
49+
}
50+
4351
function fail() {
4452
echo "FAIL: " "$@"
4553
exit 1
4654
}
4755

56+
function assert_contains_string() {
57+
content="$(<"$1")"
58+
grep -q "$2" "$1" || fail "String $2 not contained in: ${content}"
59+
}
60+
4861
function assert_empty_list() {
4962
content="$(<"$1")"
5063
[[ ${content} = "${EMPTY_OUTPUT}" ]] || fail "Not empty list: ${content}"
@@ -118,6 +131,40 @@ assert_dir_exists payments-dev
118131
assert_dir_exists payments-prod
119132
grep -q allowPrivilegeEscalation podsecuritypolicy_psp.yaml
120133

134+
helm_testcase "node_helm_template_command_line_args"
135+
node "${DIST}"/helm_template_run.js -i /dev/null -d name=my-chart -d chart_path=charts/bitnami/redis/ >out.yaml
136+
assert_contains_string out.yaml "my-chart"
137+
138+
helm_testcase "node_helm_template_function_config_args"
139+
cat >fc.yaml <<EOF
140+
apiVersion: v1
141+
kind: ConfigMap
142+
metadata:
143+
name: my-config
144+
annotations:
145+
config.k8s.io/function: |
146+
container:
147+
image: gcr.io/kpt-functions/helm-template
148+
config.kubernetes.io/local-config: "true"
149+
data:
150+
name: my-chart
151+
chart_path: charts/bitnami/redis
152+
EOF
153+
node "${DIST}"/helm_template_run.js -i /dev/null -f fc.yaml >out.yaml
154+
assert_contains_string out.yaml "my-chart"
155+
156+
helm_testcase "node_helm_template_undefined_args"
157+
node "${DIST}"/helm_template_run.js -i /dev/null 2>err.txt || true
158+
assert_contains_string err.txt "Error: functionConfig expected, instead undefined"
159+
160+
helm_testcase "node_helm_template_transform_funct"
161+
node "${DIST}"/read_yaml_run.js -i /dev/null -d source_dir="$(pwd)"/example-configs |
162+
node "${DIST}"/helm_template_run.js -i /dev/null -d name=my-chart -d chart_path=charts/bitnami/redis/ |
163+
node "${DIST}"/write_yaml_run.js -o /dev/null -d sink_dir="$(pwd)"/example-configs -d overwrite=true
164+
assert_dir_exists example-configs/shipping-dev
165+
assert_dir_exists example-configs/default
166+
grep -q "name: my-chart-redis-master" example-configs/default/service_my-chart-redis-master.yaml
167+
121168
############################
122169
# Docker Tests
123170
############################
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM node:10-alpine as builder
2+
3+
RUN mkdir -p /home/node/app && \
4+
chown -R node:node /home/node/app
5+
6+
USER node
7+
8+
WORKDIR /home/node/app
9+
10+
# Install dependencies and cache them.
11+
COPY --chown=node:node package*.json ./
12+
RUN npm ci
13+
14+
# Build the source.
15+
COPY --chown=node:node tsconfig.json .
16+
COPY --chown=node:node src src
17+
RUN npm run build && \
18+
npm prune --production && \
19+
rm -r src tsconfig.json
20+
21+
#############################################
22+
23+
FROM alpine/helm:3.2.1
24+
25+
WORKDIR /home/node/app
26+
27+
COPY --from=builder /home/node/app /home/node/app
28+
29+
RUN apk add bash curl git
30+
RUN apk update
31+
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
34+
ENV PATH /usr/local/bin:$PATH
35+
36+
ENTRYPOINT ["node", "/home/node/app/dist/helm_template_run.js"]

0 commit comments

Comments
 (0)