mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Add benchmark for containerized KRM function in kustomize
This commit is contained in:
67
hack/krmFunctionBenchmark/benchmark.sh
Executable file
67
hack/krmFunctionBenchmark/benchmark.sh
Executable file
@@ -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
|
||||||
8
hack/krmFunctionBenchmark/cleanup.sh
Executable file
8
hack/krmFunctionBenchmark/cleanup.sh
Executable file
@@ -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
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
resources:
|
||||||
|
- data.yaml
|
||||||
|
transformers:
|
||||||
|
- 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
|
||||||
16
hack/krmFunctionBenchmark/example_tshirt/execfn/Dockerfile
Normal file
16
hack/krmFunctionBenchmark/example_tshirt/execfn/Dockerfile
Normal file
@@ -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 .
|
||||||
8
hack/krmFunctionBenchmark/example_tshirt/execfn/build.sh
Executable file
8
hack/krmFunctionBenchmark/example_tshirt/execfn/build.sh
Executable file
@@ -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
|
||||||
20
hack/krmFunctionBenchmark/example_tshirt/execfn/data.yaml
Normal file
20
hack/krmFunctionBenchmark/example_tshirt/execfn/data.yaml
Normal file
@@ -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
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
resources:
|
||||||
|
- data.yaml
|
||||||
|
transformers:
|
||||||
|
- 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
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: my-namespace
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: another-namespace
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
resources:
|
||||||
|
- data1.yaml
|
||||||
|
- data2.yaml
|
||||||
|
transformers:
|
||||||
|
- containerfn.yaml
|
||||||
15
hack/krmFunctionBenchmark/label_namespace/execfn/Dockerfile
Normal file
15
hack/krmFunctionBenchmark/label_namespace/execfn/Dockerfile
Normal file
@@ -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
|
||||||
8
hack/krmFunctionBenchmark/label_namespace/execfn/build.sh
Executable file
8
hack/krmFunctionBenchmark/label_namespace/execfn/build.sh
Executable file
@@ -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
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: my-namespace
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: another-namespace
|
||||||
11
hack/krmFunctionBenchmark/label_namespace/execfn/execfn.yaml
Normal file
11
hack/krmFunctionBenchmark/label_namespace/execfn/execfn.yaml
Normal file
@@ -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
|
||||||
3
hack/krmFunctionBenchmark/label_namespace/execfn/fn.sh
Executable file
3
hack/krmFunctionBenchmark/label_namespace/execfn/fn.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
node ./dist/label_namespace_run.js
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
resources:
|
||||||
|
- data1.yaml
|
||||||
|
- data2.yaml
|
||||||
|
transformers:
|
||||||
|
- execfn.yaml
|
||||||
19
hack/krmFunctionBenchmark/readme.md
Normal file
19
hack/krmFunctionBenchmark/readme.md
Normal file
@@ -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.
|
||||||
Reference in New Issue
Block a user