From 800711cf13dfdb3ff22c1ce88fbd1bf2c08fafd6 Mon Sep 17 00:00:00 2001 From: Kevin Hannon Date: Fri, 30 Aug 2024 15:01:35 -0400 Subject: [PATCH] add e2e test --- .github/workflows/e2e.yaml | 31 +++++++++++++++++++++++++ Makefile | 9 ++++++++ hack/setup-e2e.sh | 23 +++++++++++++++++++ test/e2e/test.sh | 47 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 .github/workflows/e2e.yaml create mode 100755 hack/setup-e2e.sh create mode 100755 test/e2e/test.sh diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml new file mode 100644 index 00000000..dc1a27a6 --- /dev/null +++ b/.github/workflows/e2e.yaml @@ -0,0 +1,31 @@ +name: Run tests + +on: [ push, pull_request ] + +permissions: + contents: read + +jobs: + e2e: + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: 1.22.6 + - name: Checkout code + uses: actions/checkout@v3 + - name: Update vendor modules + run: go mod vendor + - name: Build + run: make PREFIX=artifacts cmds + - name: install helm and kubelet + run: | + sudo snap install helm --classic + sudo snap install kubectl --classic + - name: Setup e2e + run: make prep-e2e + - name: run e2e-test + run: make test-e2e + - name: teardown e2e-test + run: make teardown-e2e \ No newline at end of file diff --git a/Makefile b/Makefile index d3ae9ff5..5e4d2ca8 100644 --- a/Makefile +++ b/Makefile @@ -113,6 +113,15 @@ generate-deepcopy: vendor output:object:dir=$(CURDIR)/api/$(VENDOR)/resource/$${api}; \ done +prep-e2e: + hack/setup-e2e.sh + +test-e2e: + test/e2e/test.sh + +teardown-e2e: + demo/delete-cluster.sh + # Generate an image for containerized builds # Note: This image is local only .PHONY: .build-image diff --git a/hack/setup-e2e.sh b/hack/setup-e2e.sh new file mode 100755 index 00000000..90ecee0e --- /dev/null +++ b/hack/setup-e2e.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# Copyright 2024 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +bash demo/build-driver.sh +bash demo/create-cluster.sh +helm upgrade -i \ + --create-namespace \ + --namespace dra-example-driver \ + dra-example-driver \ + deployments/helm/dra-example-driver \ No newline at end of file diff --git a/test/e2e/test.sh b/test/e2e/test.sh new file mode 100755 index 00000000..a272cac9 --- /dev/null +++ b/test/e2e/test.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +# Copyright 2024 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Very Simple Script for testing the demo + +#kubectl create -f demo/gpu-test1.yaml +#kubectl create -f demo/gpu-test2.yaml +#kubectl create -f demo/gpu-test3.yaml +#kubectl create -f demo/gpu-test4.yaml +sleep 30 + +gpu_test_1=$(kubectl get pods -n gpu-test1 | grep -c 'Running') +if [ $gpu_test_1 != 2 ]; then + echo "gpu_test_1 $gpu_test_1 failed to match against 2 expected pods" + exit 1 +fi + +gpu_test_2=$(kubectl get pods -n gpu-test2 | grep -c 'Running') +if [ $gpu_test_2 != 1 ]; then + echo "gpu_test_2 $gpu_test_2 failed to match against 1 expected pod" + exit 1 +fi + +gpu_test_3=$(kubectl get pods -n gpu-test3 | grep -c 'Running') +if [ $gpu_test_3 != 2 ]; then + echo "gpu_test_3 $gpu_test_3 failed to match against 2 expected pods" + exit 1 +fi + +gpu_test_4=$(kubectl get pods -n gpu-test4 | grep -c 'Running') +if [ $gpu_test_4 != 1 ]; then + echo "gpu_test_4 $gpu_test_4 failed to match against 1 expected pods" + exit 1 +fi \ No newline at end of file