From 095470beb3c9021739a086e9b9e3c139650ead56 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Wed, 25 Sep 2024 16:23:54 +0300 Subject: [PATCH 01/11] feat: testkube kind Docker image Signed-off-by: Vladislav Sukhin --- build/kind/Dockerfile.kind | 33 +++++ build/kind/entrypoint.sh | 76 ++++++++++++ build/kind/k6.yaml | 239 +++++++++++++++++++++++++++++++++++++ 3 files changed, 348 insertions(+) create mode 100644 build/kind/Dockerfile.kind create mode 100644 build/kind/entrypoint.sh create mode 100644 build/kind/k6.yaml diff --git a/build/kind/Dockerfile.kind b/build/kind/Dockerfile.kind new file mode 100644 index 00000000000..2d518c10b55 --- /dev/null +++ b/build/kind/Dockerfile.kind @@ -0,0 +1,33 @@ +# syntax=docker/dockerfile:1 +# Step 1: Use a base image with Docker installed +FROM docker:20.10.24-dind + +# Step 2: Install necessary dependencies (curl, bash) +RUN apk add --no-cache bash curl tini jq tar + +# Step 3: Install Kind (Kubernetes in Docker) +RUN curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64 && \ + chmod +x ./kind && \ + mv ./kind /usr/local/bin/kind + +# Step 4: Install kubectl (for interacting with the Kubernetes cluster) +RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \ + chmod +x ./kubectl && \ + mv ./kubectl /usr/local/bin/kubectl + +# Step 5: Install Helm (package manager for Kubernetes) +RUN curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash + +# Step 6: Install Testkube CLI +RUN curl -sSLf https://get.testkube.io | bash + +# Step 7: Script to automatically create Kind cluster and install Testkube +COPY entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh + +# Step 8: Example K6 Test Workkflow CRD and Kind images +COPY ./images /images +COPY k6.yaml /examples/k6.yaml + +# Step 9: Set Docker entry point for DIND (Docker-in-Docker) +ENTRYPOINT ["tini", "--", "/usr/local/bin/entrypoint.sh"] diff --git a/build/kind/entrypoint.sh b/build/kind/entrypoint.sh new file mode 100644 index 00000000000..49fda5fa763 --- /dev/null +++ b/build/kind/entrypoint.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +# Turn on bash's job control +set -m + +# Logging function to make it easier to debug +log() { + echo "[INFO] $1" +} + +# Step 1: Start docker service in background +/usr/local/bin/dockerd-entrypoint.sh & + +# Step 2: Wait that the docker service is up +while ! docker info; do + log "Waiting docker for 5 seconds..." + sleep 5 +done + +# Step 3: Import pre-installed images +for file in /images/*.tar; do + log "Load docker image $file..." + docker load <$file +done + +# Step 4: Create Kind cluster using a specific Kubernetes version +log "Creating Kubernetes cluster using Kind (Kubernetes v1.31.0)..." +kind create cluster --name testkube-cluster --image kindest/node:v1.31.0 --wait 5m +if [ $? -ne 0 ]; then + log "Failed to create Kind cluster." + exit 1 +fi + +# Step 5: Verify kubectl is connected to the cluster +log "Verifying cluster is up..." +kubectl cluster-info +if [ $? -ne 0 ]; then + log "Failed to verify cluster." + exit 1 +fi + +# Step 6: Add the Testkube Helm repository +log "Adding Testkube Helm repository..." +helm repo add testkube https://kubeshop.github.io/helm-charts +helm repo update + +# Step 7: Install Testkube using Helm +log "Installing Testkube via Helm..." +helm install testkube testkube/testkube --namespace testkube --create-namespace +if [ $? -ne 0 ]; then + log "Testkube installation failed." + exit 1 +fi + +# Step 8: Wait that the Testkube is up +log "Waiting Testkube for 180 seconds..." +sleep 180 + +# Step 9: Verify Testkube is installed to the cluster +log "Verifying Testkube is up..." +kubectl get pods -n testkube +if [ $? -ne 0 ]; then + log "Failed to verify Testkube." + exit 1 +fi + +# Step 10: Create and Run Testkube k6 Test Workflow +log "Creating and running Testkube k6 Test Workflow..." +kubectl apply -f /examples/k6.yaml -n testkube +kubectl testkube run testworkflow k6-workflow-smoke -f + +log "Testkube installation successful!" +log "You can now use Testkube in your Kind Kubernetes cluster." + +# Step 11: Bring docker service back to foreground +fg %1 diff --git a/build/kind/k6.yaml b/build/kind/k6.yaml new file mode 100644 index 00000000000..ca3c637fef5 --- /dev/null +++ b/build/kind/k6.yaml @@ -0,0 +1,239 @@ +apiVersion: testworkflows.testkube.io/v1 +kind: TestWorkflow +metadata: + name: k6-workflow-smoke + labels: + core-tests: workflows +spec: + content: + git: + uri: https://github.com/kubeshop/testkube + revision: main + paths: + - test/k6/executor-tests/k6-smoke-test.js + container: + resources: + requests: + cpu: 128m + memory: 128Mi + workingDir: /data/repo/test/k6/executor-tests + steps: + - name: Run test + run: + image: grafana/k6:0.43.1 + args: + - run + - k6-smoke-test.js + - -e + - K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value + env: + - name: K6_SYSTEM_ENV + value: K6_SYSTEM_ENV_value +--- +apiVersion: testworkflows.testkube.io/v1 +kind: TestWorkflow +metadata: + name: k6-workflow-smoke-template + labels: + core-tests: workflows +spec: + container: + resources: + requests: + cpu: 128m + memory: 128Mi + workingDir: /data/repo/test/k6/executor-tests + env: + - name: K6_SYSTEM_ENV # currently only possible on this level + value: K6_SYSTEM_ENV_value + steps: + - name: Run from template + workingDir: /data/repo/test/k6/executor-tests + content: + git: + uri: https://github.com/kubeshop/testkube + revision: main + paths: + - test/k6/executor-tests/k6-smoke-test.js + template: + name: official/k6/v1 + config: + version: 0.48.0 + run: "k6 run k6-smoke-test.js -e K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value" +--- +apiVersion: testworkflows.testkube.io/v1 +kind: TestWorkflow +metadata: + name: k6-workflow-smoke-template-without-checkout-step + labels: + core-tests: workflows +spec: + content: + git: + uri: https://github.com/kubeshop/testkube + revision: main + paths: + - test/k6/executor-tests/k6-smoke-test.js + container: + resources: + requests: + cpu: 128m + memory: 128Mi + workingDir: /data/repo/test/k6/executor-tests + env: + - name: K6_SYSTEM_ENV # currently only possible on this level + value: K6_SYSTEM_ENV_value + steps: + - name: Run from template + workingDir: /data/repo/test/k6/executor-tests + template: + name: official/k6/v1 + config: + version: 0.48.0 + run: "k6 run k6-smoke-test.js -e K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value" +--- +apiVersion: testworkflows.testkube.io/v1 +kind: TestWorkflow +metadata: + name: k6-workflow-smoke-artifacts + labels: + core-tests: workflows +spec: + content: + git: + uri: https://github.com/kubeshop/testkube + revision: main + paths: + - test/k6/executor-tests/k6-smoke-test.js + container: + resources: + requests: + cpu: 128m + memory: 128Mi + workingDir: /data/repo/test/k6/executor-tests + steps: + - name: Run test + container: + image: grafana/k6:0.49.0 + steps: + - shell: mkdir /data/artifacts + - run: + args: + - run + - k6-smoke-test.js + - -e + - K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value + env: + - name: K6_SYSTEM_ENV + value: K6_SYSTEM_ENV_value + - name: K6_WEB_DASHBOARD + value: "true" + - name: K6_WEB_DASHBOARD_EXPORT + value: "/data/artifacts/k6-test-report.html" + steps: + - name: Saving artifacts + workingDir: /data/artifacts + artifacts: + paths: + - '*' +--- +apiVersion: testworkflows.testkube.io/v1 +kind: TestWorkflow +metadata: + name: distributed-k6-workflow-smoke + labels: + core-tests: workflows +spec: + config: + vus: {type: integer, default: 2} + duration: {type: string, default: '2s'} + workers: {type: integer, default: 3} + content: + git: + uri: https://github.com/kubeshop/testkube + revision: main + paths: + - test/k6/executor-tests/k6-smoke-test.js + steps: + - name: Run test + parallel: + count: 'config.workers' + transfer: + - from: /data/repo + use: + - name: distribute/evenly + container: + workingDir: /data/repo/test/k6/executor-tests + resources: + requests: + cpu: 128m + memory: 128Mi + env: + - name: K6_SYSTEM_ENV + value: K6_SYSTEM_ENV_value + paused: true # synchronize running all workers + run: + image: grafana/k6:0.49.0 + shell: | + k6 run k6-smoke-test.js \ + -e K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value \ + --vus {{ shellquote(config.vus) }} \ + --duration {{ shellquote(config.duration) }} \ + --execution-segment {{ index }}/{{ count }}:{{ index + 1 }}/{{ count }} +--- +apiVersion: testworkflows.testkube.io/v1 +kind: TestWorkflow +metadata: + name: distributed-k6-workflow-smoke-artifacts + labels: + core-tests: workflows +spec: + config: + vus: {type: integer, default: 2} + duration: {type: string, default: '2s'} + workers: {type: integer, default: 3} + content: + git: + uri: https://github.com/kubeshop/testkube + revision: main + paths: + - test/k6/executor-tests/k6-smoke-test.js + steps: + - name: Run test + parallel: + count: 'config.workers' + transfer: + - from: /data/repo + use: + - name: distribute/evenly + container: + resources: + requests: + cpu: 128m + memory: 128Mi + paused: true # synchronise running all workers + run: + image: grafana/k6:0.49.0 + workingDir: /data/repo/test/k6/executor-tests + args: + - run + - k6-smoke-test.js + - -e + - K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value + - --vus + - '{{ config.vus }}' + - --duration + - '{{ config.duration }}' + - --execution-segment + - '{{ index }}/{{ count }}:{{ index + 1 }}/{{ count }}' + env: + - name: K6_SYSTEM_ENV + value: K6_SYSTEM_ENV_value + - name: K6_WEB_DASHBOARD + value: "true" + - name: K6_WEB_DASHBOARD_EXPORT + value: "/data/k6-test-report.html" + artifacts: + workingDir: /data + paths: + - '*.html' From 5450e3e4b67d8ac6cfa0420b2c8b7eb080a0e640 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Thu, 26 Sep 2024 16:07:38 +0300 Subject: [PATCH 02/11] fix: tune entrypoint Signed-off-by: Vladislav Sukhin --- build/kind/oss/Dockerfile.kind | 33 +++++++++ build/kind/oss/entrypoint.sh | 128 +++++++++++++++++++++++++++++++++ build/kind/{ => oss}/k6.yaml | 0 3 files changed, 161 insertions(+) create mode 100644 build/kind/oss/Dockerfile.kind create mode 100644 build/kind/oss/entrypoint.sh rename build/kind/{ => oss}/k6.yaml (100%) diff --git a/build/kind/oss/Dockerfile.kind b/build/kind/oss/Dockerfile.kind new file mode 100644 index 00000000000..b2137d51f6a --- /dev/null +++ b/build/kind/oss/Dockerfile.kind @@ -0,0 +1,33 @@ +# syntax=docker/dockerfile:1 +# Step 1: Use a base image with Docker installed +FROM docker:20.10.24-dind + +# Step 2: Install necessary dependencies (curl, bash, tini, jq, tar) +RUN apk add --no-cache bash curl tini jq tar + +# Step 3: Install Kind (Kubernetes in Docker) +RUN curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64 && \ + chmod +x ./kind && \ + mv ./kind /usr/local/bin/kind + +# Step 4: Install kubectl (for interacting with the Kubernetes cluster) +RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \ + chmod +x ./kubectl && \ + mv ./kubectl /usr/local/bin/kubectl + +# Step 5: Install Helm (package manager for Kubernetes) +RUN curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash + +# Step 6: Install Testkube CLI +RUN curl -sSLf https://get.testkube.io | bash + +# Step 7: Script to automatically create Kind cluster and install Testkube +COPY entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh + +# Step 8: Example K6 Test Workkflow CRD and preload Kind images +COPY ./images /images +COPY k6.yaml /examples/k6.yaml + +# Step 9: Set Docker entry point for DIND (Docker-in-Docker) +ENTRYPOINT ["tini", "--", "/usr/local/bin/entrypoint.sh"] diff --git a/build/kind/oss/entrypoint.sh b/build/kind/oss/entrypoint.sh new file mode 100644 index 00000000000..8a955a91d06 --- /dev/null +++ b/build/kind/oss/entrypoint.sh @@ -0,0 +1,128 @@ +#!/bin/bash + +# Turn on bash's job control +set -m + +# Logging function to make it easier to debug +log() { + echo "[INFO] $1" +} + +# Step 1: Start docker service in background +/usr/local/bin/dockerd-entrypoint.sh & + +# Step 2: Wait that the docker service is up +while ! docker info; do + log "Waiting docker for 5 seconds..." + sleep 5 +done + +# Step 3: Import pre-installed images +for file in /images/*.tar; do + log "Load docker image $file..." + docker load <$file +done + +# Step 4: Create Kind cluster using a specific Kubernetes version +log "Creating Kubernetes cluster using Kind (Kubernetes v1.31.0)..." +kind create cluster --name testkube-cluster --image kindest/node:v1.31.0 --wait 5m +if [ $? -ne 0 ]; then + log "Failed to create Kind cluster." + exit 1 +fi + +# Step 5: Verify kubectl is connected to the cluster +log "Verifying cluster is up..." +kubectl cluster-info +if [ $? -ne 0 ]; then + log "Failed to verify cluster." + exit 1 +fi + +# Step 6: Add the Testkube Helm repository +log "Adding Testkube Helm repository..." +helm repo add testkube https://kubeshop.github.io/helm-charts +helm repo update + +# Step 7: Install Testkube using Helm +log "Installing Testkube via Helm..." +helm install testkube testkube/testkube --namespace testkube --create-namespace +if [ $? -ne 0 ]; then + log "Testkube installation failed." + exit 1 +fi + +# Step 8: Verify Testkube is installed to the cluster +log "Verifying Testkube is up..." +counter=0 +log_pattern="testkube-api acquired lease" +while [ $counter -lt 15 ] +do + # Get all pod statuses in the Testkube namespace + pod_status=$(kubectl get pods -n testkube --no-headers) + + # Check if there are any pods in the Testkube namespace + if [ -z "$pod_status" ]; then + log "No pods found in Testkube namespace" + exit 1 + fi + + # Iterate through each pod, check status and log pattern + all_running=true + found_pattern=false + + log "Checking pods in Testkube namespace..." + while read -r line; do + pod_name=$(echo "$line" | awk '{print $1}') + status=$(echo "$line" | awk '{print $3}') + + if [ "$status" != "Running" ]; then + log "Pod $pod_name is not running. Status: $status" + all_running=false + break + else + log "Pod $pod_name is running." + fi + + if [[ $pod_name == *"testkube-api-server"* ]]; then + pod_logs=$(kubectl logs "$pod_name" -n testkube) + + # Check if logs contain the desired pattern + if echo "$pod_logs" | grep -q "$log_pattern"; then + log "Log pattern found: $log_pattern" + found_pattern=true + else + log "Log pattern not found: $log_pattern" + break + fi + fi + done <<< "$pod_status" + + if [ "$all_running" = true ] && [ "$found_pattern" = true ] ; then + log "Waiting Testkube API for 30 seconds..." + sleep 30 + break + else + log "Waiting Testkube for 30 seconds..." + sleep 30 + fi + + counter=$(( counter + 1 )) +done + +if [ $counter -eq 15 ]; then + log "Testkube validation failed." + exit 1 +fi +log "Testkube is up and running." + +# Step 9: Create and Run Testkube k6 Test Workflow +log "Creating and running Testkube k6 Test Workflow..." +kubectl apply -f /examples/k6.yaml -n testkube +kubectl testkube run testworkflow k6-workflow-smoke -f + +log "Testkube installation successful!" +log "You can now use Testkube in your Kind Kubernetes cluster." + +# Step 10: Bring docker service back to foreground +fg %1 diff --git a/build/kind/k6.yaml b/build/kind/oss/k6.yaml similarity index 100% rename from build/kind/k6.yaml rename to build/kind/oss/k6.yaml From 5f65d7513fa5c068bb7182c72ac32cb6babffc69 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Thu, 26 Sep 2024 16:08:53 +0300 Subject: [PATCH 03/11] fix: removed Signed-off-by: Vladislav Sukhin --- build/kind/Dockerfile.kind => Dockerfile.kind | 0 build/kind/entrypoint.sh => entrypoint.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename build/kind/Dockerfile.kind => Dockerfile.kind (100%) rename build/kind/entrypoint.sh => entrypoint.sh (100%) diff --git a/build/kind/Dockerfile.kind b/Dockerfile.kind similarity index 100% rename from build/kind/Dockerfile.kind rename to Dockerfile.kind diff --git a/build/kind/entrypoint.sh b/entrypoint.sh similarity index 100% rename from build/kind/entrypoint.sh rename to entrypoint.sh From 00207184fc38a5474ebeee6199aa7b3ca74180e9 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Thu, 26 Sep 2024 16:11:04 +0300 Subject: [PATCH 04/11] fix: remove files Signed-off-by: Vladislav Sukhin --- Dockerfile.kind | 33 --------------------- entrypoint.sh | 76 ------------------------------------------------- 2 files changed, 109 deletions(-) delete mode 100644 Dockerfile.kind delete mode 100644 entrypoint.sh diff --git a/Dockerfile.kind b/Dockerfile.kind deleted file mode 100644 index 2d518c10b55..00000000000 --- a/Dockerfile.kind +++ /dev/null @@ -1,33 +0,0 @@ -# syntax=docker/dockerfile:1 -# Step 1: Use a base image with Docker installed -FROM docker:20.10.24-dind - -# Step 2: Install necessary dependencies (curl, bash) -RUN apk add --no-cache bash curl tini jq tar - -# Step 3: Install Kind (Kubernetes in Docker) -RUN curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64 && \ - chmod +x ./kind && \ - mv ./kind /usr/local/bin/kind - -# Step 4: Install kubectl (for interacting with the Kubernetes cluster) -RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \ - chmod +x ./kubectl && \ - mv ./kubectl /usr/local/bin/kubectl - -# Step 5: Install Helm (package manager for Kubernetes) -RUN curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash - -# Step 6: Install Testkube CLI -RUN curl -sSLf https://get.testkube.io | bash - -# Step 7: Script to automatically create Kind cluster and install Testkube -COPY entrypoint.sh /usr/local/bin/entrypoint.sh -RUN chmod +x /usr/local/bin/entrypoint.sh - -# Step 8: Example K6 Test Workkflow CRD and Kind images -COPY ./images /images -COPY k6.yaml /examples/k6.yaml - -# Step 9: Set Docker entry point for DIND (Docker-in-Docker) -ENTRYPOINT ["tini", "--", "/usr/local/bin/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index 49fda5fa763..00000000000 --- a/entrypoint.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash - -# Turn on bash's job control -set -m - -# Logging function to make it easier to debug -log() { - echo "[INFO] $1" -} - -# Step 1: Start docker service in background -/usr/local/bin/dockerd-entrypoint.sh & - -# Step 2: Wait that the docker service is up -while ! docker info; do - log "Waiting docker for 5 seconds..." - sleep 5 -done - -# Step 3: Import pre-installed images -for file in /images/*.tar; do - log "Load docker image $file..." - docker load <$file -done - -# Step 4: Create Kind cluster using a specific Kubernetes version -log "Creating Kubernetes cluster using Kind (Kubernetes v1.31.0)..." -kind create cluster --name testkube-cluster --image kindest/node:v1.31.0 --wait 5m -if [ $? -ne 0 ]; then - log "Failed to create Kind cluster." - exit 1 -fi - -# Step 5: Verify kubectl is connected to the cluster -log "Verifying cluster is up..." -kubectl cluster-info -if [ $? -ne 0 ]; then - log "Failed to verify cluster." - exit 1 -fi - -# Step 6: Add the Testkube Helm repository -log "Adding Testkube Helm repository..." -helm repo add testkube https://kubeshop.github.io/helm-charts -helm repo update - -# Step 7: Install Testkube using Helm -log "Installing Testkube via Helm..." -helm install testkube testkube/testkube --namespace testkube --create-namespace -if [ $? -ne 0 ]; then - log "Testkube installation failed." - exit 1 -fi - -# Step 8: Wait that the Testkube is up -log "Waiting Testkube for 180 seconds..." -sleep 180 - -# Step 9: Verify Testkube is installed to the cluster -log "Verifying Testkube is up..." -kubectl get pods -n testkube -if [ $? -ne 0 ]; then - log "Failed to verify Testkube." - exit 1 -fi - -# Step 10: Create and Run Testkube k6 Test Workflow -log "Creating and running Testkube k6 Test Workflow..." -kubectl apply -f /examples/k6.yaml -n testkube -kubectl testkube run testworkflow k6-workflow-smoke -f - -log "Testkube installation successful!" -log "You can now use Testkube in your Kind Kubernetes cluster." - -# Step 11: Bring docker service back to foreground -fg %1 From f9711a61f2df56023d01ca3b0e9993615b2c735c Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Thu, 26 Sep 2024 16:13:58 +0300 Subject: [PATCH 05/11] fix: add logs Signed-off-by: Vladislav Sukhin --- build/kind/oss/entrypoint.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build/kind/oss/entrypoint.sh b/build/kind/oss/entrypoint.sh index 8a955a91d06..0f72d80e0fb 100644 --- a/build/kind/oss/entrypoint.sh +++ b/build/kind/oss/entrypoint.sh @@ -63,7 +63,7 @@ do # Check if there are any pods in the Testkube namespace if [ -z "$pod_status" ]; then - log "No pods found in Testkube namespace" + log "No pods found in Testkube namespace." exit 1 fi @@ -77,7 +77,7 @@ do status=$(echo "$line" | awk '{print $3}') if [ "$status" != "Running" ]; then - log "Pod $pod_name is not running. Status: $status" + log "Pod $pod_name is not running. Status: $status." all_running=false break else @@ -89,10 +89,10 @@ do # Check if logs contain the desired pattern if echo "$pod_logs" | grep -q "$log_pattern"; then - log "Log pattern found: $log_pattern" + log "Log pattern found: $log_pattern." found_pattern=true else - log "Log pattern not found: $log_pattern" + log "Log pattern not found: $log_pattern." break fi fi From 8f379be5125513ff4391536a630112c86b08e753 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Thu, 26 Sep 2024 17:24:10 +0300 Subject: [PATCH 06/11] feat: cloud image Signed-off-by: Vladislav Sukhin --- build/kind/cloud/Dockerfile.kind | 30 ++++ build/kind/cloud/entrypoint.sh | 151 +++++++++++++++++++ build/kind/cloud/k6.yaml | 239 +++++++++++++++++++++++++++++++ build/kind/oss/entrypoint.sh | 2 +- 4 files changed, 421 insertions(+), 1 deletion(-) create mode 100644 build/kind/cloud/Dockerfile.kind create mode 100644 build/kind/cloud/entrypoint.sh create mode 100644 build/kind/cloud/k6.yaml diff --git a/build/kind/cloud/Dockerfile.kind b/build/kind/cloud/Dockerfile.kind new file mode 100644 index 00000000000..152e4432f77 --- /dev/null +++ b/build/kind/cloud/Dockerfile.kind @@ -0,0 +1,30 @@ +# syntax=docker/dockerfile:1 +# Step 1: Use a base image with Docker installed +FROM docker:20.10.24-dind + +# Step 2: Install necessary dependencies (curl, bash, tini) +RUN apk add --no-cache bash curl tini + +# Step 3: Install Kind (Kubernetes in Docker) +RUN curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64 && \ + chmod +x ./kind && \ + mv ./kind /usr/local/bin/kind + +# Step 4: Install kubectl (for interacting with the Kubernetes cluster) +RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \ + chmod +x ./kubectl && \ + mv ./kubectl /usr/local/bin/kubectl + +# Step 5: Install Helm (package manager for Kubernetes) +RUN curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash + +# Step 6: Script to automatically create Kind cluster and install Testkube +COPY entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh + +# Step 7: Example K6 Test Workkflow CRD and preload Kind images +COPY ./images /images +COPY k6.yaml /examples/k6.yaml + +# Step 8: Set Docker entry point for DIND (Docker-in-Docker) +ENTRYPOINT ["tini", "--", "/usr/local/bin/entrypoint.sh"] diff --git a/build/kind/cloud/entrypoint.sh b/build/kind/cloud/entrypoint.sh new file mode 100644 index 00000000000..ff71aa53009 --- /dev/null +++ b/build/kind/cloud/entrypoint.sh @@ -0,0 +1,151 @@ +#!/bin/bash + +# Turn on bash's job control +set -m + +# Logging function to make it easier to debug +log() { + echo "[INFO] $1" +} + +# Check if agent key is provided +if [ -z "$AGENT_KEY" ]; then + log "Please provide AGENT_KEY env var" + exit 1 +fi + +# Check if org id is provided +if [ -z "$ORG_ID" ]; then + log "Please provide ORG_ID env var" + exit 1 +fi + +# Check if env id is provided +if [ -z "$ENV_ID" ]; then + log "Please provide ENV_ID env var" + exit 1 +fi + +# Check if cloud url is provided +if [ -z "$CLOUD_URL" ]; then + log "Please provide CLOUD_URL env var" + exit 1 +fi + +# Step 1: Start docker service in background +/usr/local/bin/dockerd-entrypoint.sh & + +# Step 2: Wait that the docker service is up +while ! docker info; do + log "Waiting docker for 5 seconds..." + sleep 5 +done + +# Step 3: Import pre-installed images +for file in /images/*.tar; do + log "Load docker image $file..." + docker load <$file +done + +# Step 4: Create Kind cluster using a specific Kubernetes version +log "Creating Kubernetes cluster using Kind (Kubernetes v1.31.0)..." +kind create cluster --name testkube-cluster --image kindest/node:v1.31.0 --wait 5m +if [ $? -ne 0 ]; then + log "Failed to create Kind cluster." + exit 1 +fi + +# Step 5: Verify kubectl is connected to the cluster +log "Verifying cluster is up..." +kubectl cluster-info +if [ $? -ne 0 ]; then + log "Failed to verify cluster." + exit 1 +fi + +# Step 6: Add the Testkube Helm repository +log "Adding Testkube Helm repository..." +helm repo add testkube https://kubeshop.github.io/helm-charts +helm repo update + +# Step 7: Install Testkube using Helm +log "Installing Testkube via Helm..." +helm install testkube testkube/testkube --namespace testkube --create-namespace --set testkube-api.cloud.key=$AGENT_KEY --set testkube-api.cloud.orgId=$ORG_ID --set testkube-api.cloud.envId=$ENV_ID --set testkube-api.minio.enabled=false --set mongodb.enabled=false --set testkube-dashboard.enabled=false --set testkube-api.cloud.url=$CLOUD_URL +if [ $? -ne 0 ]; then + log "Testkube installation failed." + exit 1 +fi + +# Step 8: Verify Testkube is installed to the cluster +log "Verifying Testkube is up..." +counter=0 +log_pattern="starting Testkube API server" +while [ $counter -lt 15 ] +do + # Get all pod statuses in the Testkube namespace + pod_status=$(kubectl get pods -n testkube --no-headers) + + # Check if there are any pods in the Testkube namespace + if [ -z "$pod_status" ]; then + log "No pods found in Testkube namespace." + exit 1 + fi + + # Iterate through each pod, check status and log pattern + all_running=true + found_pattern=false + + log "Checking pods in Testkube namespace..." + while read -r line; do + pod_name=$(echo "$line" | awk '{print $1}') + status=$(echo "$line" | awk '{print $3}') + + if [ "$status" != "Running" ]; then + log "Pod $pod_name is not running. Status: $status." + all_running=false + break + else + log "Pod $pod_name is running." + fi + + if [[ $pod_name == *"testkube-api-server"* ]]; then + pod_logs=$(kubectl logs "$pod_name" -n testkube) + + # Check if logs contain the desired pattern + if echo "$pod_logs" | grep -q "$log_pattern"; then + log "Log pattern found: $log_pattern." + found_pattern=true + else + log "Log pattern not found: $log_pattern." + break + fi + fi + done <<< "$pod_status" + + if [ "$all_running" = true ] && [ "$found_pattern" = true ] ; then + log "Waiting Testkube API for 30 seconds..." + sleep 30 + break + else + log "Waiting Testkube for 30 seconds..." + sleep 30 + fi + + counter=$(( counter + 1 )) +done + +if [ $counter -eq 15 ]; then + log "Testkube validation failed." + exit 1 +fi +log "Testkube is up and running." + +# Step 9: Create Testkube k6 Test Workflow +log "Creating and running Testkube k6 Test Workflow..." +kubectl apply -f /examples/k6.yaml -n testkube + +log "Testkube installation successful!" +log "You can now use Testkube in your Kind Kubernetes cluster." + +# Step 10: Bring docker service back to foreground +fg %1 diff --git a/build/kind/cloud/k6.yaml b/build/kind/cloud/k6.yaml new file mode 100644 index 00000000000..ca3c637fef5 --- /dev/null +++ b/build/kind/cloud/k6.yaml @@ -0,0 +1,239 @@ +apiVersion: testworkflows.testkube.io/v1 +kind: TestWorkflow +metadata: + name: k6-workflow-smoke + labels: + core-tests: workflows +spec: + content: + git: + uri: https://github.com/kubeshop/testkube + revision: main + paths: + - test/k6/executor-tests/k6-smoke-test.js + container: + resources: + requests: + cpu: 128m + memory: 128Mi + workingDir: /data/repo/test/k6/executor-tests + steps: + - name: Run test + run: + image: grafana/k6:0.43.1 + args: + - run + - k6-smoke-test.js + - -e + - K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value + env: + - name: K6_SYSTEM_ENV + value: K6_SYSTEM_ENV_value +--- +apiVersion: testworkflows.testkube.io/v1 +kind: TestWorkflow +metadata: + name: k6-workflow-smoke-template + labels: + core-tests: workflows +spec: + container: + resources: + requests: + cpu: 128m + memory: 128Mi + workingDir: /data/repo/test/k6/executor-tests + env: + - name: K6_SYSTEM_ENV # currently only possible on this level + value: K6_SYSTEM_ENV_value + steps: + - name: Run from template + workingDir: /data/repo/test/k6/executor-tests + content: + git: + uri: https://github.com/kubeshop/testkube + revision: main + paths: + - test/k6/executor-tests/k6-smoke-test.js + template: + name: official/k6/v1 + config: + version: 0.48.0 + run: "k6 run k6-smoke-test.js -e K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value" +--- +apiVersion: testworkflows.testkube.io/v1 +kind: TestWorkflow +metadata: + name: k6-workflow-smoke-template-without-checkout-step + labels: + core-tests: workflows +spec: + content: + git: + uri: https://github.com/kubeshop/testkube + revision: main + paths: + - test/k6/executor-tests/k6-smoke-test.js + container: + resources: + requests: + cpu: 128m + memory: 128Mi + workingDir: /data/repo/test/k6/executor-tests + env: + - name: K6_SYSTEM_ENV # currently only possible on this level + value: K6_SYSTEM_ENV_value + steps: + - name: Run from template + workingDir: /data/repo/test/k6/executor-tests + template: + name: official/k6/v1 + config: + version: 0.48.0 + run: "k6 run k6-smoke-test.js -e K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value" +--- +apiVersion: testworkflows.testkube.io/v1 +kind: TestWorkflow +metadata: + name: k6-workflow-smoke-artifacts + labels: + core-tests: workflows +spec: + content: + git: + uri: https://github.com/kubeshop/testkube + revision: main + paths: + - test/k6/executor-tests/k6-smoke-test.js + container: + resources: + requests: + cpu: 128m + memory: 128Mi + workingDir: /data/repo/test/k6/executor-tests + steps: + - name: Run test + container: + image: grafana/k6:0.49.0 + steps: + - shell: mkdir /data/artifacts + - run: + args: + - run + - k6-smoke-test.js + - -e + - K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value + env: + - name: K6_SYSTEM_ENV + value: K6_SYSTEM_ENV_value + - name: K6_WEB_DASHBOARD + value: "true" + - name: K6_WEB_DASHBOARD_EXPORT + value: "/data/artifacts/k6-test-report.html" + steps: + - name: Saving artifacts + workingDir: /data/artifacts + artifacts: + paths: + - '*' +--- +apiVersion: testworkflows.testkube.io/v1 +kind: TestWorkflow +metadata: + name: distributed-k6-workflow-smoke + labels: + core-tests: workflows +spec: + config: + vus: {type: integer, default: 2} + duration: {type: string, default: '2s'} + workers: {type: integer, default: 3} + content: + git: + uri: https://github.com/kubeshop/testkube + revision: main + paths: + - test/k6/executor-tests/k6-smoke-test.js + steps: + - name: Run test + parallel: + count: 'config.workers' + transfer: + - from: /data/repo + use: + - name: distribute/evenly + container: + workingDir: /data/repo/test/k6/executor-tests + resources: + requests: + cpu: 128m + memory: 128Mi + env: + - name: K6_SYSTEM_ENV + value: K6_SYSTEM_ENV_value + paused: true # synchronize running all workers + run: + image: grafana/k6:0.49.0 + shell: | + k6 run k6-smoke-test.js \ + -e K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value \ + --vus {{ shellquote(config.vus) }} \ + --duration {{ shellquote(config.duration) }} \ + --execution-segment {{ index }}/{{ count }}:{{ index + 1 }}/{{ count }} +--- +apiVersion: testworkflows.testkube.io/v1 +kind: TestWorkflow +metadata: + name: distributed-k6-workflow-smoke-artifacts + labels: + core-tests: workflows +spec: + config: + vus: {type: integer, default: 2} + duration: {type: string, default: '2s'} + workers: {type: integer, default: 3} + content: + git: + uri: https://github.com/kubeshop/testkube + revision: main + paths: + - test/k6/executor-tests/k6-smoke-test.js + steps: + - name: Run test + parallel: + count: 'config.workers' + transfer: + - from: /data/repo + use: + - name: distribute/evenly + container: + resources: + requests: + cpu: 128m + memory: 128Mi + paused: true # synchronise running all workers + run: + image: grafana/k6:0.49.0 + workingDir: /data/repo/test/k6/executor-tests + args: + - run + - k6-smoke-test.js + - -e + - K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value + - --vus + - '{{ config.vus }}' + - --duration + - '{{ config.duration }}' + - --execution-segment + - '{{ index }}/{{ count }}:{{ index + 1 }}/{{ count }}' + env: + - name: K6_SYSTEM_ENV + value: K6_SYSTEM_ENV_value + - name: K6_WEB_DASHBOARD + value: "true" + - name: K6_WEB_DASHBOARD_EXPORT + value: "/data/k6-test-report.html" + artifacts: + workingDir: /data + paths: + - '*.html' diff --git a/build/kind/oss/entrypoint.sh b/build/kind/oss/entrypoint.sh index 0f72d80e0fb..48a61366199 100644 --- a/build/kind/oss/entrypoint.sh +++ b/build/kind/oss/entrypoint.sh @@ -55,7 +55,7 @@ fi # Step 8: Verify Testkube is installed to the cluster log "Verifying Testkube is up..." counter=0 -log_pattern="testkube-api acquired lease" +log_pattern="starting Testkube API server" while [ $counter -lt 15 ] do # Get all pod statuses in the Testkube namespace From 6b7418b526eef4c5b1b1592e55b8f9a61affd936 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Thu, 26 Sep 2024 18:08:10 +0300 Subject: [PATCH 07/11] Update build/kind/oss/Dockerfile.kind Co-authored-by: Dawid Rusnak --- build/kind/oss/Dockerfile.kind | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/kind/oss/Dockerfile.kind b/build/kind/oss/Dockerfile.kind index b2137d51f6a..715d911e2d5 100644 --- a/build/kind/oss/Dockerfile.kind +++ b/build/kind/oss/Dockerfile.kind @@ -25,7 +25,7 @@ RUN curl -sSLf https://get.testkube.io | bash COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh -# Step 8: Example K6 Test Workkflow CRD and preload Kind images +# Step 8: Example K6 Test Workflow CRD and preload Kind images COPY ./images /images COPY k6.yaml /examples/k6.yaml From 5b47a819c84296f85e3b86314410a44e4ab1155d Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Mon, 30 Sep 2024 18:04:43 +0300 Subject: [PATCH 08/11] fix: remove org and env id Signed-off-by: Vladislav Sukhin --- build/kind/cloud/entrypoint.sh | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/build/kind/cloud/entrypoint.sh b/build/kind/cloud/entrypoint.sh index ff71aa53009..160a2be0751 100644 --- a/build/kind/cloud/entrypoint.sh +++ b/build/kind/cloud/entrypoint.sh @@ -14,18 +14,6 @@ if [ -z "$AGENT_KEY" ]; then exit 1 fi -# Check if org id is provided -if [ -z "$ORG_ID" ]; then - log "Please provide ORG_ID env var" - exit 1 -fi - -# Check if env id is provided -if [ -z "$ENV_ID" ]; then - log "Please provide ENV_ID env var" - exit 1 -fi - # Check if cloud url is provided if [ -z "$CLOUD_URL" ]; then log "Please provide CLOUD_URL env var" @@ -70,7 +58,7 @@ helm repo update # Step 7: Install Testkube using Helm log "Installing Testkube via Helm..." -helm install testkube testkube/testkube --namespace testkube --create-namespace --set testkube-api.cloud.key=$AGENT_KEY --set testkube-api.cloud.orgId=$ORG_ID --set testkube-api.cloud.envId=$ENV_ID --set testkube-api.minio.enabled=false --set mongodb.enabled=false --set testkube-dashboard.enabled=false --set testkube-api.cloud.url=$CLOUD_URL +helm install testkube testkube/testkube --namespace testkube --create-namespace --set testkube-api.cloud.key=$AGENT_KEY --set testkube-api.minio.enabled=false --set mongodb.enabled=false --set testkube-dashboard.enabled=false --set testkube-api.cloud.url=$CLOUD_URL if [ $? -ne 0 ]; then log "Testkube installation failed." exit 1 From c6d9499bd71e855220b6316f08cc9588cf93722b Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Mon, 30 Sep 2024 18:10:25 +0300 Subject: [PATCH 09/11] fix: move folder Signed-off-by: Vladislav Sukhin --- build/kind/{cloud => }/Dockerfile.kind | 2 +- build/kind/{cloud => }/entrypoint.sh | 0 build/kind/{cloud => }/k6.yaml | 0 build/kind/oss/Dockerfile.kind | 33 ------- build/kind/oss/entrypoint.sh | 128 ------------------------- build/kind/oss/k6.yaml => k6.yaml | 0 6 files changed, 1 insertion(+), 162 deletions(-) rename build/kind/{cloud => }/Dockerfile.kind (94%) rename build/kind/{cloud => }/entrypoint.sh (100%) rename build/kind/{cloud => }/k6.yaml (100%) delete mode 100644 build/kind/oss/Dockerfile.kind delete mode 100644 build/kind/oss/entrypoint.sh rename build/kind/oss/k6.yaml => k6.yaml (100%) diff --git a/build/kind/cloud/Dockerfile.kind b/build/kind/Dockerfile.kind similarity index 94% rename from build/kind/cloud/Dockerfile.kind rename to build/kind/Dockerfile.kind index 152e4432f77..30432dee867 100644 --- a/build/kind/cloud/Dockerfile.kind +++ b/build/kind/Dockerfile.kind @@ -22,7 +22,7 @@ RUN curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | b COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh -# Step 7: Example K6 Test Workkflow CRD and preload Kind images +# Step 7: Example K6 Test Workflow CRD and preload Kind images COPY ./images /images COPY k6.yaml /examples/k6.yaml diff --git a/build/kind/cloud/entrypoint.sh b/build/kind/entrypoint.sh similarity index 100% rename from build/kind/cloud/entrypoint.sh rename to build/kind/entrypoint.sh diff --git a/build/kind/cloud/k6.yaml b/build/kind/k6.yaml similarity index 100% rename from build/kind/cloud/k6.yaml rename to build/kind/k6.yaml diff --git a/build/kind/oss/Dockerfile.kind b/build/kind/oss/Dockerfile.kind deleted file mode 100644 index 715d911e2d5..00000000000 --- a/build/kind/oss/Dockerfile.kind +++ /dev/null @@ -1,33 +0,0 @@ -# syntax=docker/dockerfile:1 -# Step 1: Use a base image with Docker installed -FROM docker:20.10.24-dind - -# Step 2: Install necessary dependencies (curl, bash, tini, jq, tar) -RUN apk add --no-cache bash curl tini jq tar - -# Step 3: Install Kind (Kubernetes in Docker) -RUN curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64 && \ - chmod +x ./kind && \ - mv ./kind /usr/local/bin/kind - -# Step 4: Install kubectl (for interacting with the Kubernetes cluster) -RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \ - chmod +x ./kubectl && \ - mv ./kubectl /usr/local/bin/kubectl - -# Step 5: Install Helm (package manager for Kubernetes) -RUN curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash - -# Step 6: Install Testkube CLI -RUN curl -sSLf https://get.testkube.io | bash - -# Step 7: Script to automatically create Kind cluster and install Testkube -COPY entrypoint.sh /usr/local/bin/entrypoint.sh -RUN chmod +x /usr/local/bin/entrypoint.sh - -# Step 8: Example K6 Test Workflow CRD and preload Kind images -COPY ./images /images -COPY k6.yaml /examples/k6.yaml - -# Step 9: Set Docker entry point for DIND (Docker-in-Docker) -ENTRYPOINT ["tini", "--", "/usr/local/bin/entrypoint.sh"] diff --git a/build/kind/oss/entrypoint.sh b/build/kind/oss/entrypoint.sh deleted file mode 100644 index 48a61366199..00000000000 --- a/build/kind/oss/entrypoint.sh +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/bash - -# Turn on bash's job control -set -m - -# Logging function to make it easier to debug -log() { - echo "[INFO] $1" -} - -# Step 1: Start docker service in background -/usr/local/bin/dockerd-entrypoint.sh & - -# Step 2: Wait that the docker service is up -while ! docker info; do - log "Waiting docker for 5 seconds..." - sleep 5 -done - -# Step 3: Import pre-installed images -for file in /images/*.tar; do - log "Load docker image $file..." - docker load <$file -done - -# Step 4: Create Kind cluster using a specific Kubernetes version -log "Creating Kubernetes cluster using Kind (Kubernetes v1.31.0)..." -kind create cluster --name testkube-cluster --image kindest/node:v1.31.0 --wait 5m -if [ $? -ne 0 ]; then - log "Failed to create Kind cluster." - exit 1 -fi - -# Step 5: Verify kubectl is connected to the cluster -log "Verifying cluster is up..." -kubectl cluster-info -if [ $? -ne 0 ]; then - log "Failed to verify cluster." - exit 1 -fi - -# Step 6: Add the Testkube Helm repository -log "Adding Testkube Helm repository..." -helm repo add testkube https://kubeshop.github.io/helm-charts -helm repo update - -# Step 7: Install Testkube using Helm -log "Installing Testkube via Helm..." -helm install testkube testkube/testkube --namespace testkube --create-namespace -if [ $? -ne 0 ]; then - log "Testkube installation failed." - exit 1 -fi - -# Step 8: Verify Testkube is installed to the cluster -log "Verifying Testkube is up..." -counter=0 -log_pattern="starting Testkube API server" -while [ $counter -lt 15 ] -do - # Get all pod statuses in the Testkube namespace - pod_status=$(kubectl get pods -n testkube --no-headers) - - # Check if there are any pods in the Testkube namespace - if [ -z "$pod_status" ]; then - log "No pods found in Testkube namespace." - exit 1 - fi - - # Iterate through each pod, check status and log pattern - all_running=true - found_pattern=false - - log "Checking pods in Testkube namespace..." - while read -r line; do - pod_name=$(echo "$line" | awk '{print $1}') - status=$(echo "$line" | awk '{print $3}') - - if [ "$status" != "Running" ]; then - log "Pod $pod_name is not running. Status: $status." - all_running=false - break - else - log "Pod $pod_name is running." - fi - - if [[ $pod_name == *"testkube-api-server"* ]]; then - pod_logs=$(kubectl logs "$pod_name" -n testkube) - - # Check if logs contain the desired pattern - if echo "$pod_logs" | grep -q "$log_pattern"; then - log "Log pattern found: $log_pattern." - found_pattern=true - else - log "Log pattern not found: $log_pattern." - break - fi - fi - done <<< "$pod_status" - - if [ "$all_running" = true ] && [ "$found_pattern" = true ] ; then - log "Waiting Testkube API for 30 seconds..." - sleep 30 - break - else - log "Waiting Testkube for 30 seconds..." - sleep 30 - fi - - counter=$(( counter + 1 )) -done - -if [ $counter -eq 15 ]; then - log "Testkube validation failed." - exit 1 -fi -log "Testkube is up and running." - -# Step 9: Create and Run Testkube k6 Test Workflow -log "Creating and running Testkube k6 Test Workflow..." -kubectl apply -f /examples/k6.yaml -n testkube -kubectl testkube run testworkflow k6-workflow-smoke -f - -log "Testkube installation successful!" -log "You can now use Testkube in your Kind Kubernetes cluster." - -# Step 10: Bring docker service back to foreground -fg %1 diff --git a/build/kind/oss/k6.yaml b/k6.yaml similarity index 100% rename from build/kind/oss/k6.yaml rename to k6.yaml From eba8cd3a071bf0621f28947fd98a3d29bddb9a96 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Mon, 30 Sep 2024 18:11:30 +0300 Subject: [PATCH 10/11] fix: remove example Signed-off-by: Vladislav Sukhin --- k6.yaml | 239 -------------------------------------------------------- 1 file changed, 239 deletions(-) delete mode 100644 k6.yaml diff --git a/k6.yaml b/k6.yaml deleted file mode 100644 index ca3c637fef5..00000000000 --- a/k6.yaml +++ /dev/null @@ -1,239 +0,0 @@ -apiVersion: testworkflows.testkube.io/v1 -kind: TestWorkflow -metadata: - name: k6-workflow-smoke - labels: - core-tests: workflows -spec: - content: - git: - uri: https://github.com/kubeshop/testkube - revision: main - paths: - - test/k6/executor-tests/k6-smoke-test.js - container: - resources: - requests: - cpu: 128m - memory: 128Mi - workingDir: /data/repo/test/k6/executor-tests - steps: - - name: Run test - run: - image: grafana/k6:0.43.1 - args: - - run - - k6-smoke-test.js - - -e - - K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value - env: - - name: K6_SYSTEM_ENV - value: K6_SYSTEM_ENV_value ---- -apiVersion: testworkflows.testkube.io/v1 -kind: TestWorkflow -metadata: - name: k6-workflow-smoke-template - labels: - core-tests: workflows -spec: - container: - resources: - requests: - cpu: 128m - memory: 128Mi - workingDir: /data/repo/test/k6/executor-tests - env: - - name: K6_SYSTEM_ENV # currently only possible on this level - value: K6_SYSTEM_ENV_value - steps: - - name: Run from template - workingDir: /data/repo/test/k6/executor-tests - content: - git: - uri: https://github.com/kubeshop/testkube - revision: main - paths: - - test/k6/executor-tests/k6-smoke-test.js - template: - name: official/k6/v1 - config: - version: 0.48.0 - run: "k6 run k6-smoke-test.js -e K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value" ---- -apiVersion: testworkflows.testkube.io/v1 -kind: TestWorkflow -metadata: - name: k6-workflow-smoke-template-without-checkout-step - labels: - core-tests: workflows -spec: - content: - git: - uri: https://github.com/kubeshop/testkube - revision: main - paths: - - test/k6/executor-tests/k6-smoke-test.js - container: - resources: - requests: - cpu: 128m - memory: 128Mi - workingDir: /data/repo/test/k6/executor-tests - env: - - name: K6_SYSTEM_ENV # currently only possible on this level - value: K6_SYSTEM_ENV_value - steps: - - name: Run from template - workingDir: /data/repo/test/k6/executor-tests - template: - name: official/k6/v1 - config: - version: 0.48.0 - run: "k6 run k6-smoke-test.js -e K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value" ---- -apiVersion: testworkflows.testkube.io/v1 -kind: TestWorkflow -metadata: - name: k6-workflow-smoke-artifacts - labels: - core-tests: workflows -spec: - content: - git: - uri: https://github.com/kubeshop/testkube - revision: main - paths: - - test/k6/executor-tests/k6-smoke-test.js - container: - resources: - requests: - cpu: 128m - memory: 128Mi - workingDir: /data/repo/test/k6/executor-tests - steps: - - name: Run test - container: - image: grafana/k6:0.49.0 - steps: - - shell: mkdir /data/artifacts - - run: - args: - - run - - k6-smoke-test.js - - -e - - K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value - env: - - name: K6_SYSTEM_ENV - value: K6_SYSTEM_ENV_value - - name: K6_WEB_DASHBOARD - value: "true" - - name: K6_WEB_DASHBOARD_EXPORT - value: "/data/artifacts/k6-test-report.html" - steps: - - name: Saving artifacts - workingDir: /data/artifacts - artifacts: - paths: - - '*' ---- -apiVersion: testworkflows.testkube.io/v1 -kind: TestWorkflow -metadata: - name: distributed-k6-workflow-smoke - labels: - core-tests: workflows -spec: - config: - vus: {type: integer, default: 2} - duration: {type: string, default: '2s'} - workers: {type: integer, default: 3} - content: - git: - uri: https://github.com/kubeshop/testkube - revision: main - paths: - - test/k6/executor-tests/k6-smoke-test.js - steps: - - name: Run test - parallel: - count: 'config.workers' - transfer: - - from: /data/repo - use: - - name: distribute/evenly - container: - workingDir: /data/repo/test/k6/executor-tests - resources: - requests: - cpu: 128m - memory: 128Mi - env: - - name: K6_SYSTEM_ENV - value: K6_SYSTEM_ENV_value - paused: true # synchronize running all workers - run: - image: grafana/k6:0.49.0 - shell: | - k6 run k6-smoke-test.js \ - -e K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value \ - --vus {{ shellquote(config.vus) }} \ - --duration {{ shellquote(config.duration) }} \ - --execution-segment {{ index }}/{{ count }}:{{ index + 1 }}/{{ count }} ---- -apiVersion: testworkflows.testkube.io/v1 -kind: TestWorkflow -metadata: - name: distributed-k6-workflow-smoke-artifacts - labels: - core-tests: workflows -spec: - config: - vus: {type: integer, default: 2} - duration: {type: string, default: '2s'} - workers: {type: integer, default: 3} - content: - git: - uri: https://github.com/kubeshop/testkube - revision: main - paths: - - test/k6/executor-tests/k6-smoke-test.js - steps: - - name: Run test - parallel: - count: 'config.workers' - transfer: - - from: /data/repo - use: - - name: distribute/evenly - container: - resources: - requests: - cpu: 128m - memory: 128Mi - paused: true # synchronise running all workers - run: - image: grafana/k6:0.49.0 - workingDir: /data/repo/test/k6/executor-tests - args: - - run - - k6-smoke-test.js - - -e - - K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value - - --vus - - '{{ config.vus }}' - - --duration - - '{{ config.duration }}' - - --execution-segment - - '{{ index }}/{{ count }}:{{ index + 1 }}/{{ count }}' - env: - - name: K6_SYSTEM_ENV - value: K6_SYSTEM_ENV_value - - name: K6_WEB_DASHBOARD - value: "true" - - name: K6_WEB_DASHBOARD_EXPORT - value: "/data/k6-test-report.html" - artifacts: - workingDir: /data - paths: - - '*.html' From 4cd10a28f70c6b1f2dd0cbadcb15692de9e4286f Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Wed, 2 Oct 2024 15:21:04 +0300 Subject: [PATCH 11/11] fix: add docker container env Signed-off-by: Vladislav Sukhin --- build/kind/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/kind/entrypoint.sh b/build/kind/entrypoint.sh index 160a2be0751..e02303766f2 100644 --- a/build/kind/entrypoint.sh +++ b/build/kind/entrypoint.sh @@ -58,7 +58,7 @@ helm repo update # Step 7: Install Testkube using Helm log "Installing Testkube via Helm..." -helm install testkube testkube/testkube --namespace testkube --create-namespace --set testkube-api.cloud.key=$AGENT_KEY --set testkube-api.minio.enabled=false --set mongodb.enabled=false --set testkube-dashboard.enabled=false --set testkube-api.cloud.url=$CLOUD_URL +helm install testkube testkube/testkube --namespace testkube --create-namespace --set testkube-api.cloud.key=$AGENT_KEY --set testkube-api.minio.enabled=false --set mongodb.enabled=false --set testkube-dashboard.enabled=false --set testkube-api.cloud.url=$CLOUD_URL --set testkube-api.containerEnv=docker if [ $? -ne 0 ]; then log "Testkube installation failed." exit 1