From 6d324d70c4c50e91a3c0e85fb6e515c56e020642 Mon Sep 17 00:00:00 2001 From: Donny Xia Date: Wed, 1 Jul 2020 12:46:16 -0700 Subject: [PATCH 1/6] Add benchmark for containerized KRM function in kustomize --- hack/krmFunctionBenchmark/benchmark.sh | 67 +++++++++++++++++++ hack/krmFunctionBenchmark/cleanup.sh | 8 +++ .../example_tshirt/containerfn/data.yaml | 20 ++++++ .../containerfn/kustomization.yaml | 4 ++ .../example_tshirt/containerfn/transf.yaml | 8 +++ .../example_tshirt/execfn/Dockerfile | 16 +++++ .../example_tshirt/execfn/build.sh | 8 +++ .../example_tshirt/execfn/data.yaml | 20 ++++++ .../example_tshirt/execfn/kustomization.yaml | 4 ++ .../example_tshirt/execfn/transf.yaml | 8 +++ .../containerfn/containerfn.yaml | 11 +++ .../label_namespace/containerfn/data1.yaml | 4 ++ .../label_namespace/containerfn/data2.yaml | 4 ++ .../containerfn/kustomization.yaml | 5 ++ .../label_namespace/execfn/Dockerfile | 15 +++++ .../label_namespace/execfn/build.sh | 8 +++ .../label_namespace/execfn/data1.yaml | 4 ++ .../label_namespace/execfn/data2.yaml | 4 ++ .../label_namespace/execfn/execfn.yaml | 11 +++ .../label_namespace/execfn/fn.sh | 3 + .../label_namespace/execfn/kustomization.yaml | 5 ++ hack/krmFunctionBenchmark/readme.md | 19 ++++++ 22 files changed, 256 insertions(+) create mode 100755 hack/krmFunctionBenchmark/benchmark.sh create mode 100755 hack/krmFunctionBenchmark/cleanup.sh create mode 100644 hack/krmFunctionBenchmark/example_tshirt/containerfn/data.yaml create mode 100644 hack/krmFunctionBenchmark/example_tshirt/containerfn/kustomization.yaml create mode 100644 hack/krmFunctionBenchmark/example_tshirt/containerfn/transf.yaml create mode 100644 hack/krmFunctionBenchmark/example_tshirt/execfn/Dockerfile create mode 100755 hack/krmFunctionBenchmark/example_tshirt/execfn/build.sh create mode 100644 hack/krmFunctionBenchmark/example_tshirt/execfn/data.yaml create mode 100644 hack/krmFunctionBenchmark/example_tshirt/execfn/kustomization.yaml create mode 100644 hack/krmFunctionBenchmark/example_tshirt/execfn/transf.yaml create mode 100644 hack/krmFunctionBenchmark/label_namespace/containerfn/containerfn.yaml create mode 100644 hack/krmFunctionBenchmark/label_namespace/containerfn/data1.yaml create mode 100644 hack/krmFunctionBenchmark/label_namespace/containerfn/data2.yaml create mode 100644 hack/krmFunctionBenchmark/label_namespace/containerfn/kustomization.yaml create mode 100644 hack/krmFunctionBenchmark/label_namespace/execfn/Dockerfile create mode 100755 hack/krmFunctionBenchmark/label_namespace/execfn/build.sh create mode 100644 hack/krmFunctionBenchmark/label_namespace/execfn/data1.yaml create mode 100644 hack/krmFunctionBenchmark/label_namespace/execfn/data2.yaml create mode 100644 hack/krmFunctionBenchmark/label_namespace/execfn/execfn.yaml create mode 100755 hack/krmFunctionBenchmark/label_namespace/execfn/fn.sh create mode 100644 hack/krmFunctionBenchmark/label_namespace/execfn/kustomization.yaml create mode 100644 hack/krmFunctionBenchmark/readme.md diff --git a/hack/krmFunctionBenchmark/benchmark.sh b/hack/krmFunctionBenchmark/benchmark.sh new file mode 100755 index 000000000..0e59440b7 --- /dev/null +++ b/hack/krmFunctionBenchmark/benchmark.sh @@ -0,0 +1,67 @@ +#! /bin/bash + +set -e + +KUSTOMIZE_EXEC=kustomize +KUSTOMIZE_FLAGS="build --enable_alpha_plugins --enable-exec" + +function build_label_namespace_exec { + cd label_namespace/execfn + . build.sh + cd - +} + +function build_tshirt_exec { + cd example_tshirt/execfn + . build.sh + cd - +} + +function build_exec { + echo "Building exec functions..." + build_tshirt_exec + build_label_namespace_exec + echo "Done. Start running benchmark." +} + +function run_fn { + local loop=$1 + local type=$2 + local dir=$3 + echo -e "=== Running ${type} ${loop} times ===" + cd $dir + local begin_time=$(date +%s%N) + for ((i = 0; i < $loop; i++)) + do + $KUSTOMIZE_EXEC $KUSTOMIZE_FLAGS > /dev/null + echo -en "\r$i/$loop" + done + local end_time=$(date +%s%N) + local time_diff=$(($end_time - $begin_time)) + local time_diff_s=$(echo "${time_diff} / 1000 / 1000 / 1000" | bc -l) + echo -e "\n=== Time used: ===" + echo "${time_diff_s}s" + cd - +} + +function run_label_namespace_benchmark { + local loop=$1 + run_fn $loop "Label Namespace Transformer Exec Function" "label_namespace/execfn" + run_fn $loop "Label Namespace Transformer Container Function" "label_namespace/containerfn" +} + +function run_tshirt_benchmark { + local loop=$1 + run_fn $loop "T-shirt Example Exec Function" "example_tshirt/execfn" + run_fn $loop "T-shirt Example Container Function" "example_tshirt/containerfn" +} + +loops=(10 100 1000) + +build_exec + +for l in "${loops[@]}" +do + run_label_namespace_benchmark $l + run_tshirt_benchmark $l +done \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/cleanup.sh b/hack/krmFunctionBenchmark/cleanup.sh new file mode 100755 index 000000000..40d06fd31 --- /dev/null +++ b/hack/krmFunctionBenchmark/cleanup.sh @@ -0,0 +1,8 @@ +#! /bin/bash + +sudo rm -rf example_tshirt/execfn/tshirt label_namespace/execfn/dist label_namespace/execfn/node_modules + +if [ "$1" == "--image" ]; then + docker image rm label_namespace_build:latest + docker image rm tshirt_example_build:latest +fi \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/example_tshirt/containerfn/data.yaml b/hack/krmFunctionBenchmark/example_tshirt/containerfn/data.yaml new file mode 100644 index 000000000..a3ac98f20 --- /dev/null +++ b/hack/krmFunctionBenchmark/example_tshirt/containerfn/data.yaml @@ -0,0 +1,20 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx + labels: + app: nginx + annotations: + tshirt-size: small # this injects the resource reservations +spec: + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/example_tshirt/containerfn/kustomization.yaml b/hack/krmFunctionBenchmark/example_tshirt/containerfn/kustomization.yaml new file mode 100644 index 000000000..a509be0ae --- /dev/null +++ b/hack/krmFunctionBenchmark/example_tshirt/containerfn/kustomization.yaml @@ -0,0 +1,4 @@ +resources: +- data.yaml +transformers: +- transf.yaml \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/example_tshirt/containerfn/transf.yaml b/hack/krmFunctionBenchmark/example_tshirt/containerfn/transf.yaml new file mode 100644 index 000000000..a144d7b09 --- /dev/null +++ b/hack/krmFunctionBenchmark/example_tshirt/containerfn/transf.yaml @@ -0,0 +1,8 @@ +apiVersion: examples.config.kubernetes.io/v1beta1 +kind: tshirt +metadata: + name: tshirt + annotations: + config.kubernetes.io/function: |- + container: + image: gcr.io/kustomize-functions/example-tshirt:v0.2.0 \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/example_tshirt/execfn/Dockerfile b/hack/krmFunctionBenchmark/example_tshirt/execfn/Dockerfile new file mode 100644 index 000000000..1887cbfc9 --- /dev/null +++ b/hack/krmFunctionBenchmark/example_tshirt/execfn/Dockerfile @@ -0,0 +1,16 @@ +FROM alpine:latest + +ENV BUILD_HOME=/usr/local/build +RUN apk update && apk add --no-cache git go + +RUN mkdir -p $BUILD_HOME + +WORKDIR $BUILD_HOME + +RUN git clone https://github.com/kubernetes-sigs/kustomize.git . +RUN git checkout tags/kustomize/v3.6.1 +WORKDIR $BUILD_HOME/functions/examples/injection-tshirt-sizes/image/ + +ENV CGO_ENABLED=0 +RUN go mod download +RUN go build -o tshirt . \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/example_tshirt/execfn/build.sh b/hack/krmFunctionBenchmark/example_tshirt/execfn/build.sh new file mode 100755 index 000000000..0070ab8a3 --- /dev/null +++ b/hack/krmFunctionBenchmark/example_tshirt/execfn/build.sh @@ -0,0 +1,8 @@ +#! /bin/bash + +IMAGE_LABEL="tshirt_example_build:latest" +BUILD_HOME=/usr/local/build + +docker build -t $IMAGE_LABEL . + +docker run --rm -v $(pwd):/out $IMAGE_LABEL cp -r $BUILD_HOME/functions/examples/injection-tshirt-sizes/image/tshirt /out \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/example_tshirt/execfn/data.yaml b/hack/krmFunctionBenchmark/example_tshirt/execfn/data.yaml new file mode 100644 index 000000000..a3ac98f20 --- /dev/null +++ b/hack/krmFunctionBenchmark/example_tshirt/execfn/data.yaml @@ -0,0 +1,20 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx + labels: + app: nginx + annotations: + tshirt-size: small # this injects the resource reservations +spec: + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/example_tshirt/execfn/kustomization.yaml b/hack/krmFunctionBenchmark/example_tshirt/execfn/kustomization.yaml new file mode 100644 index 000000000..a509be0ae --- /dev/null +++ b/hack/krmFunctionBenchmark/example_tshirt/execfn/kustomization.yaml @@ -0,0 +1,4 @@ +resources: +- data.yaml +transformers: +- transf.yaml \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/example_tshirt/execfn/transf.yaml b/hack/krmFunctionBenchmark/example_tshirt/execfn/transf.yaml new file mode 100644 index 000000000..a619f3de5 --- /dev/null +++ b/hack/krmFunctionBenchmark/example_tshirt/execfn/transf.yaml @@ -0,0 +1,8 @@ +apiVersion: examples.config.kubernetes.io/v1beta1 +kind: tshirt +metadata: + name: tshirt + annotations: + config.kubernetes.io/function: |- + exec: + path: ./tshirt \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/label_namespace/containerfn/containerfn.yaml b/hack/krmFunctionBenchmark/label_namespace/containerfn/containerfn.yaml new file mode 100644 index 000000000..e47703d98 --- /dev/null +++ b/hack/krmFunctionBenchmark/label_namespace/containerfn/containerfn.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: label_namespace + annotations: + config.kubernetes.io/function: |- + container: + image: gcr.io/kpt-functions/label-namespace@sha256:4f030738d6d25a207641ca517916431517578bd0eb8d98a8bde04e3bb9315dcd +data: + label_name: my-ns-name + label_value: function-test \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/label_namespace/containerfn/data1.yaml b/hack/krmFunctionBenchmark/label_namespace/containerfn/data1.yaml new file mode 100644 index 000000000..97fc87977 --- /dev/null +++ b/hack/krmFunctionBenchmark/label_namespace/containerfn/data1.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: my-namespace \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/label_namespace/containerfn/data2.yaml b/hack/krmFunctionBenchmark/label_namespace/containerfn/data2.yaml new file mode 100644 index 000000000..167e67489 --- /dev/null +++ b/hack/krmFunctionBenchmark/label_namespace/containerfn/data2.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: another-namespace \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/label_namespace/containerfn/kustomization.yaml b/hack/krmFunctionBenchmark/label_namespace/containerfn/kustomization.yaml new file mode 100644 index 000000000..e06c3e97f --- /dev/null +++ b/hack/krmFunctionBenchmark/label_namespace/containerfn/kustomization.yaml @@ -0,0 +1,5 @@ +resources: +- data1.yaml +- data2.yaml +transformers: +- containerfn.yaml \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/label_namespace/execfn/Dockerfile b/hack/krmFunctionBenchmark/label_namespace/execfn/Dockerfile new file mode 100644 index 000000000..6fd6b84d5 --- /dev/null +++ b/hack/krmFunctionBenchmark/label_namespace/execfn/Dockerfile @@ -0,0 +1,15 @@ +FROM alpine:latest + +ENV BUILD_HOME=/usr/local/build +RUN apk update && apk add --no-cache git nodejs npm +RUN npm install -g typescript + +RUN mkdir -p $BUILD_HOME + +WORKDIR $BUILD_HOME + +RUN git clone https://github.com/GoogleContainerTools/kpt-functions-sdk.git . +RUN git checkout tags/release-kpt-functions-v0.14.2 +WORKDIR $BUILD_HOME/ts/hello-world/ +RUN npm install +RUN npm run build \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/label_namespace/execfn/build.sh b/hack/krmFunctionBenchmark/label_namespace/execfn/build.sh new file mode 100755 index 000000000..49768780e --- /dev/null +++ b/hack/krmFunctionBenchmark/label_namespace/execfn/build.sh @@ -0,0 +1,8 @@ +#! /bin/bash + +IMAGE_LABEL="label_namespace_build:latest" +BUILD_HOME=/usr/local/build + +docker build -t $IMAGE_LABEL . + +docker run --rm -v $(pwd):/out $IMAGE_LABEL cp -r $BUILD_HOME/ts/hello-world/dist $BUILD_HOME/ts/hello-world/node_modules /out \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/label_namespace/execfn/data1.yaml b/hack/krmFunctionBenchmark/label_namespace/execfn/data1.yaml new file mode 100644 index 000000000..97fc87977 --- /dev/null +++ b/hack/krmFunctionBenchmark/label_namespace/execfn/data1.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: my-namespace \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/label_namespace/execfn/data2.yaml b/hack/krmFunctionBenchmark/label_namespace/execfn/data2.yaml new file mode 100644 index 000000000..167e67489 --- /dev/null +++ b/hack/krmFunctionBenchmark/label_namespace/execfn/data2.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: another-namespace \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/label_namespace/execfn/execfn.yaml b/hack/krmFunctionBenchmark/label_namespace/execfn/execfn.yaml new file mode 100644 index 000000000..c07242d4b --- /dev/null +++ b/hack/krmFunctionBenchmark/label_namespace/execfn/execfn.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: label_namespace + annotations: + config.kubernetes.io/function: |- + exec: + path: ./fn.sh +data: + label_name: my-ns-name + label_value: function-test \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/label_namespace/execfn/fn.sh b/hack/krmFunctionBenchmark/label_namespace/execfn/fn.sh new file mode 100755 index 000000000..d1e1d8ddd --- /dev/null +++ b/hack/krmFunctionBenchmark/label_namespace/execfn/fn.sh @@ -0,0 +1,3 @@ +#! /bin/bash + +node ./dist/label_namespace_run.js \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/label_namespace/execfn/kustomization.yaml b/hack/krmFunctionBenchmark/label_namespace/execfn/kustomization.yaml new file mode 100644 index 000000000..6cb89b1df --- /dev/null +++ b/hack/krmFunctionBenchmark/label_namespace/execfn/kustomization.yaml @@ -0,0 +1,5 @@ +resources: +- data1.yaml +- data2.yaml +transformers: +- execfn.yaml \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/readme.md b/hack/krmFunctionBenchmark/readme.md new file mode 100644 index 000000000..98cb33286 --- /dev/null +++ b/hack/krmFunctionBenchmark/readme.md @@ -0,0 +1,19 @@ +# Benchmark for KRM functions in Kustomize + +## Pre-request + + - You have to use Kustomize version with KRM function supported. + - You need to have Docker running on your machine. + +## How to run + +```bash +./benchmark.sh +``` + +The script will build the exec version of function via container and then run 10, 100 and 1000 times of exec version and container version and then print out the time used by both versions. + +```bash +./cleanup.sh +``` +Will remove the built exec version of the function. Add flag `--image` to remove the images that used to build exec function. \ No newline at end of file From c2ccfd72ad22e9fe2ca71e8d431366b601e850a5 Mon Sep 17 00:00:00 2001 From: Donny Xia Date: Wed, 1 Jul 2020 12:55:38 -0700 Subject: [PATCH 2/6] Update readme --- hack/krmFunctionBenchmark/.gitignore | 3 +++ hack/krmFunctionBenchmark/readme.md | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 hack/krmFunctionBenchmark/.gitignore diff --git a/hack/krmFunctionBenchmark/.gitignore b/hack/krmFunctionBenchmark/.gitignore new file mode 100644 index 000000000..f797ffc24 --- /dev/null +++ b/hack/krmFunctionBenchmark/.gitignore @@ -0,0 +1,3 @@ +node_modules +dist +example_tshirt/execfn/tshirt \ No newline at end of file diff --git a/hack/krmFunctionBenchmark/readme.md b/hack/krmFunctionBenchmark/readme.md index 98cb33286..e472c6dbc 100644 --- a/hack/krmFunctionBenchmark/readme.md +++ b/hack/krmFunctionBenchmark/readme.md @@ -16,4 +16,13 @@ The script will build the exec version of function via container and then run 10 ```bash ./cleanup.sh ``` -Will remove the built exec version of the function. Add flag `--image` to remove the images that used to build exec function. \ No newline at end of file +Will remove the built exec version of the function. Add flag `--image` to remove the images that used to build exec function. + +## Functions in the benchmark + +Two functions are used: + + - `gcr.io/kustomize-functions/example-tshirt` ([link](https://github.com/kubernetes-sigs/kustomize/blob/master/functions/examples/injection-tshirt-sizes/image/main.go)) + - `gcr.io/kpt-functions/label-namespace` ([link](https://github.com/GoogleContainerTools/kpt-functions-sdk/blob/master/ts/hello-world/src/label_namespace.ts)) + + `example-tshirt` is a Go function. `label-namespace` is a JS function. Both of them are used as transformers. \ No newline at end of file From f6cac7e7e86a8ae8acdebc592148fa5b2c6d1180 Mon Sep 17 00:00:00 2001 From: Donny Xia Date: Mon, 6 Jul 2020 09:38:31 -0700 Subject: [PATCH 3/6] Add newline to the end of file --- hack/krmFunctionBenchmark/.gitignore | 2 +- hack/krmFunctionBenchmark/benchmark.sh | 2 +- hack/krmFunctionBenchmark/cleanup.sh | 2 +- hack/krmFunctionBenchmark/example_tshirt/containerfn/data.yaml | 2 +- .../example_tshirt/containerfn/kustomization.yaml | 2 +- .../krmFunctionBenchmark/example_tshirt/containerfn/transf.yaml | 2 +- hack/krmFunctionBenchmark/example_tshirt/execfn/Dockerfile | 2 +- hack/krmFunctionBenchmark/example_tshirt/execfn/build.sh | 2 +- hack/krmFunctionBenchmark/example_tshirt/execfn/data.yaml | 2 +- .../example_tshirt/execfn/kustomization.yaml | 2 +- hack/krmFunctionBenchmark/example_tshirt/execfn/transf.yaml | 2 +- .../label_namespace/containerfn/containerfn.yaml | 2 +- .../krmFunctionBenchmark/label_namespace/containerfn/data1.yaml | 2 +- .../krmFunctionBenchmark/label_namespace/containerfn/data2.yaml | 2 +- .../label_namespace/containerfn/kustomization.yaml | 2 +- hack/krmFunctionBenchmark/label_namespace/execfn/Dockerfile | 2 +- hack/krmFunctionBenchmark/label_namespace/execfn/build.sh | 2 +- hack/krmFunctionBenchmark/label_namespace/execfn/data1.yaml | 2 +- hack/krmFunctionBenchmark/label_namespace/execfn/data2.yaml | 2 +- hack/krmFunctionBenchmark/label_namespace/execfn/execfn.yaml | 2 +- hack/krmFunctionBenchmark/label_namespace/execfn/fn.sh | 2 +- .../label_namespace/execfn/kustomization.yaml | 2 +- hack/krmFunctionBenchmark/readme.md | 2 +- 23 files changed, 23 insertions(+), 23 deletions(-) diff --git a/hack/krmFunctionBenchmark/.gitignore b/hack/krmFunctionBenchmark/.gitignore index f797ffc24..392baaab0 100644 --- a/hack/krmFunctionBenchmark/.gitignore +++ b/hack/krmFunctionBenchmark/.gitignore @@ -1,3 +1,3 @@ node_modules dist -example_tshirt/execfn/tshirt \ No newline at end of file +example_tshirt/execfn/tshirt diff --git a/hack/krmFunctionBenchmark/benchmark.sh b/hack/krmFunctionBenchmark/benchmark.sh index 0e59440b7..efdaa258c 100755 --- a/hack/krmFunctionBenchmark/benchmark.sh +++ b/hack/krmFunctionBenchmark/benchmark.sh @@ -64,4 +64,4 @@ for l in "${loops[@]}" do run_label_namespace_benchmark $l run_tshirt_benchmark $l -done \ No newline at end of file +done diff --git a/hack/krmFunctionBenchmark/cleanup.sh b/hack/krmFunctionBenchmark/cleanup.sh index 40d06fd31..6319c38ca 100755 --- a/hack/krmFunctionBenchmark/cleanup.sh +++ b/hack/krmFunctionBenchmark/cleanup.sh @@ -5,4 +5,4 @@ sudo rm -rf example_tshirt/execfn/tshirt label_namespace/execfn/dist label_names if [ "$1" == "--image" ]; then docker image rm label_namespace_build:latest docker image rm tshirt_example_build:latest -fi \ No newline at end of file +fi diff --git a/hack/krmFunctionBenchmark/example_tshirt/containerfn/data.yaml b/hack/krmFunctionBenchmark/example_tshirt/containerfn/data.yaml index a3ac98f20..fcacb88f4 100644 --- a/hack/krmFunctionBenchmark/example_tshirt/containerfn/data.yaml +++ b/hack/krmFunctionBenchmark/example_tshirt/containerfn/data.yaml @@ -17,4 +17,4 @@ spec: spec: containers: - name: nginx - image: nginx \ No newline at end of file + image: nginx diff --git a/hack/krmFunctionBenchmark/example_tshirt/containerfn/kustomization.yaml b/hack/krmFunctionBenchmark/example_tshirt/containerfn/kustomization.yaml index a509be0ae..499359fd8 100644 --- a/hack/krmFunctionBenchmark/example_tshirt/containerfn/kustomization.yaml +++ b/hack/krmFunctionBenchmark/example_tshirt/containerfn/kustomization.yaml @@ -1,4 +1,4 @@ resources: - data.yaml transformers: -- transf.yaml \ No newline at end of file +- transf.yaml diff --git a/hack/krmFunctionBenchmark/example_tshirt/containerfn/transf.yaml b/hack/krmFunctionBenchmark/example_tshirt/containerfn/transf.yaml index a144d7b09..addbb66e4 100644 --- a/hack/krmFunctionBenchmark/example_tshirt/containerfn/transf.yaml +++ b/hack/krmFunctionBenchmark/example_tshirt/containerfn/transf.yaml @@ -5,4 +5,4 @@ metadata: annotations: config.kubernetes.io/function: |- container: - image: gcr.io/kustomize-functions/example-tshirt:v0.2.0 \ No newline at end of file + image: gcr.io/kustomize-functions/example-tshirt:v0.2.0 diff --git a/hack/krmFunctionBenchmark/example_tshirt/execfn/Dockerfile b/hack/krmFunctionBenchmark/example_tshirt/execfn/Dockerfile index 1887cbfc9..4ed5d92a6 100644 --- a/hack/krmFunctionBenchmark/example_tshirt/execfn/Dockerfile +++ b/hack/krmFunctionBenchmark/example_tshirt/execfn/Dockerfile @@ -13,4 +13,4 @@ WORKDIR $BUILD_HOME/functions/examples/injection-tshirt-sizes/image/ ENV CGO_ENABLED=0 RUN go mod download -RUN go build -o tshirt . \ No newline at end of file +RUN go build -o tshirt . diff --git a/hack/krmFunctionBenchmark/example_tshirt/execfn/build.sh b/hack/krmFunctionBenchmark/example_tshirt/execfn/build.sh index 0070ab8a3..d5d758411 100755 --- a/hack/krmFunctionBenchmark/example_tshirt/execfn/build.sh +++ b/hack/krmFunctionBenchmark/example_tshirt/execfn/build.sh @@ -5,4 +5,4 @@ BUILD_HOME=/usr/local/build docker build -t $IMAGE_LABEL . -docker run --rm -v $(pwd):/out $IMAGE_LABEL cp -r $BUILD_HOME/functions/examples/injection-tshirt-sizes/image/tshirt /out \ No newline at end of file +docker run --rm -v $(pwd):/out $IMAGE_LABEL cp -r $BUILD_HOME/functions/examples/injection-tshirt-sizes/image/tshirt /out diff --git a/hack/krmFunctionBenchmark/example_tshirt/execfn/data.yaml b/hack/krmFunctionBenchmark/example_tshirt/execfn/data.yaml index a3ac98f20..fcacb88f4 100644 --- a/hack/krmFunctionBenchmark/example_tshirt/execfn/data.yaml +++ b/hack/krmFunctionBenchmark/example_tshirt/execfn/data.yaml @@ -17,4 +17,4 @@ spec: spec: containers: - name: nginx - image: nginx \ No newline at end of file + image: nginx diff --git a/hack/krmFunctionBenchmark/example_tshirt/execfn/kustomization.yaml b/hack/krmFunctionBenchmark/example_tshirt/execfn/kustomization.yaml index a509be0ae..499359fd8 100644 --- a/hack/krmFunctionBenchmark/example_tshirt/execfn/kustomization.yaml +++ b/hack/krmFunctionBenchmark/example_tshirt/execfn/kustomization.yaml @@ -1,4 +1,4 @@ resources: - data.yaml transformers: -- transf.yaml \ No newline at end of file +- transf.yaml diff --git a/hack/krmFunctionBenchmark/example_tshirt/execfn/transf.yaml b/hack/krmFunctionBenchmark/example_tshirt/execfn/transf.yaml index a619f3de5..e5ab62278 100644 --- a/hack/krmFunctionBenchmark/example_tshirt/execfn/transf.yaml +++ b/hack/krmFunctionBenchmark/example_tshirt/execfn/transf.yaml @@ -5,4 +5,4 @@ metadata: annotations: config.kubernetes.io/function: |- exec: - path: ./tshirt \ No newline at end of file + path: ./tshirt diff --git a/hack/krmFunctionBenchmark/label_namespace/containerfn/containerfn.yaml b/hack/krmFunctionBenchmark/label_namespace/containerfn/containerfn.yaml index e47703d98..a3417d2b3 100644 --- a/hack/krmFunctionBenchmark/label_namespace/containerfn/containerfn.yaml +++ b/hack/krmFunctionBenchmark/label_namespace/containerfn/containerfn.yaml @@ -8,4 +8,4 @@ metadata: image: gcr.io/kpt-functions/label-namespace@sha256:4f030738d6d25a207641ca517916431517578bd0eb8d98a8bde04e3bb9315dcd data: label_name: my-ns-name - label_value: function-test \ No newline at end of file + label_value: function-test diff --git a/hack/krmFunctionBenchmark/label_namespace/containerfn/data1.yaml b/hack/krmFunctionBenchmark/label_namespace/containerfn/data1.yaml index 97fc87977..4cb279baf 100644 --- a/hack/krmFunctionBenchmark/label_namespace/containerfn/data1.yaml +++ b/hack/krmFunctionBenchmark/label_namespace/containerfn/data1.yaml @@ -1,4 +1,4 @@ apiVersion: v1 kind: Namespace metadata: - name: my-namespace \ No newline at end of file + name: my-namespace diff --git a/hack/krmFunctionBenchmark/label_namespace/containerfn/data2.yaml b/hack/krmFunctionBenchmark/label_namespace/containerfn/data2.yaml index 167e67489..c731475f2 100644 --- a/hack/krmFunctionBenchmark/label_namespace/containerfn/data2.yaml +++ b/hack/krmFunctionBenchmark/label_namespace/containerfn/data2.yaml @@ -1,4 +1,4 @@ apiVersion: v1 kind: Namespace metadata: - name: another-namespace \ No newline at end of file + name: another-namespace diff --git a/hack/krmFunctionBenchmark/label_namespace/containerfn/kustomization.yaml b/hack/krmFunctionBenchmark/label_namespace/containerfn/kustomization.yaml index e06c3e97f..e729f717f 100644 --- a/hack/krmFunctionBenchmark/label_namespace/containerfn/kustomization.yaml +++ b/hack/krmFunctionBenchmark/label_namespace/containerfn/kustomization.yaml @@ -2,4 +2,4 @@ resources: - data1.yaml - data2.yaml transformers: -- containerfn.yaml \ No newline at end of file +- containerfn.yaml diff --git a/hack/krmFunctionBenchmark/label_namespace/execfn/Dockerfile b/hack/krmFunctionBenchmark/label_namespace/execfn/Dockerfile index 6fd6b84d5..4e74861f6 100644 --- a/hack/krmFunctionBenchmark/label_namespace/execfn/Dockerfile +++ b/hack/krmFunctionBenchmark/label_namespace/execfn/Dockerfile @@ -12,4 +12,4 @@ RUN git clone https://github.com/GoogleContainerTools/kpt-functions-sdk.git . RUN git checkout tags/release-kpt-functions-v0.14.2 WORKDIR $BUILD_HOME/ts/hello-world/ RUN npm install -RUN npm run build \ No newline at end of file +RUN npm run build diff --git a/hack/krmFunctionBenchmark/label_namespace/execfn/build.sh b/hack/krmFunctionBenchmark/label_namespace/execfn/build.sh index 49768780e..abc93c02b 100755 --- a/hack/krmFunctionBenchmark/label_namespace/execfn/build.sh +++ b/hack/krmFunctionBenchmark/label_namespace/execfn/build.sh @@ -5,4 +5,4 @@ BUILD_HOME=/usr/local/build docker build -t $IMAGE_LABEL . -docker run --rm -v $(pwd):/out $IMAGE_LABEL cp -r $BUILD_HOME/ts/hello-world/dist $BUILD_HOME/ts/hello-world/node_modules /out \ No newline at end of file +docker run --rm -v $(pwd):/out $IMAGE_LABEL cp -r $BUILD_HOME/ts/hello-world/dist $BUILD_HOME/ts/hello-world/node_modules /out diff --git a/hack/krmFunctionBenchmark/label_namespace/execfn/data1.yaml b/hack/krmFunctionBenchmark/label_namespace/execfn/data1.yaml index 97fc87977..4cb279baf 100644 --- a/hack/krmFunctionBenchmark/label_namespace/execfn/data1.yaml +++ b/hack/krmFunctionBenchmark/label_namespace/execfn/data1.yaml @@ -1,4 +1,4 @@ apiVersion: v1 kind: Namespace metadata: - name: my-namespace \ No newline at end of file + name: my-namespace diff --git a/hack/krmFunctionBenchmark/label_namespace/execfn/data2.yaml b/hack/krmFunctionBenchmark/label_namespace/execfn/data2.yaml index 167e67489..c731475f2 100644 --- a/hack/krmFunctionBenchmark/label_namespace/execfn/data2.yaml +++ b/hack/krmFunctionBenchmark/label_namespace/execfn/data2.yaml @@ -1,4 +1,4 @@ apiVersion: v1 kind: Namespace metadata: - name: another-namespace \ No newline at end of file + name: another-namespace diff --git a/hack/krmFunctionBenchmark/label_namespace/execfn/execfn.yaml b/hack/krmFunctionBenchmark/label_namespace/execfn/execfn.yaml index c07242d4b..b08055823 100644 --- a/hack/krmFunctionBenchmark/label_namespace/execfn/execfn.yaml +++ b/hack/krmFunctionBenchmark/label_namespace/execfn/execfn.yaml @@ -8,4 +8,4 @@ metadata: path: ./fn.sh data: label_name: my-ns-name - label_value: function-test \ No newline at end of file + label_value: function-test diff --git a/hack/krmFunctionBenchmark/label_namespace/execfn/fn.sh b/hack/krmFunctionBenchmark/label_namespace/execfn/fn.sh index d1e1d8ddd..de2d233b3 100755 --- a/hack/krmFunctionBenchmark/label_namespace/execfn/fn.sh +++ b/hack/krmFunctionBenchmark/label_namespace/execfn/fn.sh @@ -1,3 +1,3 @@ #! /bin/bash -node ./dist/label_namespace_run.js \ No newline at end of file +node ./dist/label_namespace_run.js diff --git a/hack/krmFunctionBenchmark/label_namespace/execfn/kustomization.yaml b/hack/krmFunctionBenchmark/label_namespace/execfn/kustomization.yaml index 6cb89b1df..ecc941a74 100644 --- a/hack/krmFunctionBenchmark/label_namespace/execfn/kustomization.yaml +++ b/hack/krmFunctionBenchmark/label_namespace/execfn/kustomization.yaml @@ -2,4 +2,4 @@ resources: - data1.yaml - data2.yaml transformers: -- execfn.yaml \ No newline at end of file +- execfn.yaml diff --git a/hack/krmFunctionBenchmark/readme.md b/hack/krmFunctionBenchmark/readme.md index e472c6dbc..dee12742e 100644 --- a/hack/krmFunctionBenchmark/readme.md +++ b/hack/krmFunctionBenchmark/readme.md @@ -25,4 +25,4 @@ Two functions are used: - `gcr.io/kustomize-functions/example-tshirt` ([link](https://github.com/kubernetes-sigs/kustomize/blob/master/functions/examples/injection-tshirt-sizes/image/main.go)) - `gcr.io/kpt-functions/label-namespace` ([link](https://github.com/GoogleContainerTools/kpt-functions-sdk/blob/master/ts/hello-world/src/label_namespace.ts)) - `example-tshirt` is a Go function. `label-namespace` is a JS function. Both of them are used as transformers. \ No newline at end of file + `example-tshirt` is a Go function. `label-namespace` is a JS function. Both of them are used as transformers. From 42e19d610af00bf00ff1579b3bbd465a24c3eddd Mon Sep 17 00:00:00 2001 From: Donny Xia Date: Wed, 8 Jul 2020 11:08:19 -0700 Subject: [PATCH 4/6] Improve cleanup --- hack/krmFunctionBenchmark/cleanup.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hack/krmFunctionBenchmark/cleanup.sh b/hack/krmFunctionBenchmark/cleanup.sh index 6319c38ca..f7dded0da 100755 --- a/hack/krmFunctionBenchmark/cleanup.sh +++ b/hack/krmFunctionBenchmark/cleanup.sh @@ -1,8 +1,12 @@ #! /bin/bash +set -e +echo "You may need to run as root to clean." -sudo rm -rf example_tshirt/execfn/tshirt label_namespace/execfn/dist label_namespace/execfn/node_modules +rm -rf example_tshirt/execfn/tshirt label_namespace/execfn/dist label_namespace/execfn/node_modules if [ "$1" == "--image" ]; then docker image rm label_namespace_build:latest docker image rm tshirt_example_build:latest fi + +echo "Done" From 6fabfe963e80a8352b322b6e034ad95cb97eb10c Mon Sep 17 00:00:00 2001 From: Donny Xia Date: Mon, 13 Jul 2020 12:05:03 -0700 Subject: [PATCH 5/6] code review --- hack/krmFunctionBenchmark/benchmark.sh | 11 +++++++++++ .../example_tshirt/execfn/build.sh | 3 ++- .../label_namespace/execfn/build.sh | 3 ++- hack/krmFunctionBenchmark/readme.md | 6 +++--- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/hack/krmFunctionBenchmark/benchmark.sh b/hack/krmFunctionBenchmark/benchmark.sh index efdaa258c..a2c5e8cc5 100755 --- a/hack/krmFunctionBenchmark/benchmark.sh +++ b/hack/krmFunctionBenchmark/benchmark.sh @@ -56,6 +56,17 @@ function run_tshirt_benchmark { run_fn $loop "T-shirt Example Container Function" "example_tshirt/containerfn" } +if [ "$1" != "--doIt" ]; then + echo "Usage: $0 --doIt" + echo " " + echo "This script measures performance of kustomize containerized" + echo "functions (KRM config functions) implementation." + echo "It does so by running functions in local executable mode and" + echo "in container mode for 10, 100 and 1000 times. The time" + echo "used in these 2 modes are recorded." + exit 1 +fi + loops=(10 100 1000) build_exec diff --git a/hack/krmFunctionBenchmark/example_tshirt/execfn/build.sh b/hack/krmFunctionBenchmark/example_tshirt/execfn/build.sh index d5d758411..4795418c3 100755 --- a/hack/krmFunctionBenchmark/example_tshirt/execfn/build.sh +++ b/hack/krmFunctionBenchmark/example_tshirt/execfn/build.sh @@ -5,4 +5,5 @@ BUILD_HOME=/usr/local/build docker build -t $IMAGE_LABEL . -docker run --rm -v $(pwd):/out $IMAGE_LABEL cp -r $BUILD_HOME/functions/examples/injection-tshirt-sizes/image/tshirt /out +docker run --rm -v $(pwd):/out $IMAGE_LABEL \ + cp -r $BUILD_HOME/functions/examples/injection-tshirt-sizes/image/tshirt /out diff --git a/hack/krmFunctionBenchmark/label_namespace/execfn/build.sh b/hack/krmFunctionBenchmark/label_namespace/execfn/build.sh index abc93c02b..c7e461db5 100755 --- a/hack/krmFunctionBenchmark/label_namespace/execfn/build.sh +++ b/hack/krmFunctionBenchmark/label_namespace/execfn/build.sh @@ -5,4 +5,5 @@ BUILD_HOME=/usr/local/build docker build -t $IMAGE_LABEL . -docker run --rm -v $(pwd):/out $IMAGE_LABEL cp -r $BUILD_HOME/ts/hello-world/dist $BUILD_HOME/ts/hello-world/node_modules /out +docker run --rm -v $(pwd):/out $IMAGE_LABEL \ + cp -r $BUILD_HOME/ts/hello-world/dist $BUILD_HOME/ts/hello-world/node_modules /out diff --git a/hack/krmFunctionBenchmark/readme.md b/hack/krmFunctionBenchmark/readme.md index dee12742e..b32a09d23 100644 --- a/hack/krmFunctionBenchmark/readme.md +++ b/hack/krmFunctionBenchmark/readme.md @@ -1,9 +1,9 @@ # Benchmark for KRM functions in Kustomize -## Pre-request +## Pre-prerequisites - - You have to use Kustomize version with KRM function supported. - - You need to have Docker running on your machine. + - [kustomize v3.7.0 or higher](https://kubernetes-sigs.github.io/kustomize/installation) (support for KRM Config Functions). + - [docker](https://github.com/kubernetes-sigs/kustomize/pull/docker.com) ## How to run From e9c118fd552206368d928a435d40f178bb4967fc Mon Sep 17 00:00:00 2001 From: Jeff Regan Date: Mon, 13 Jul 2020 12:24:34 -0700 Subject: [PATCH 6/6] Update readme.md --- hack/krmFunctionBenchmark/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/krmFunctionBenchmark/readme.md b/hack/krmFunctionBenchmark/readme.md index b32a09d23..cb3e8eb5a 100644 --- a/hack/krmFunctionBenchmark/readme.md +++ b/hack/krmFunctionBenchmark/readme.md @@ -1,6 +1,6 @@ # Benchmark for KRM functions in Kustomize -## Pre-prerequisites +## Prerequisites - [kustomize v3.7.0 or higher](https://kubernetes-sigs.github.io/kustomize/installation) (support for KRM Config Functions). - [docker](https://github.com/kubernetes-sigs/kustomize/pull/docker.com)