From a002815953428de4c61f8a4b6af09784efb8b5cc Mon Sep 17 00:00:00 2001 From: Vibhav Bobade Date: Thu, 28 Mar 2024 04:07:40 +0530 Subject: [PATCH] update build-workflow to build helm-values for the operator --- .github/workflows/build-operator.yaml | 57 +++++++++++++++++++ .../{e2e-with-cluster.yaml => e2e.yaml} | 32 ++++++++--- ...nstall-e2e.yaml => helm-install-test.yaml} | 57 ++----------------- .github/workflows/helm-release.yml | 2 +- .../{pull_request.yaml => pull-request.yaml} | 2 +- Makefile | 7 +++ hack/e2e/001-multicluster.sh | 50 ++++++++++++++++ hack/e2e/manifests/001-multicluster.yaml | 4 ++ 8 files changed, 150 insertions(+), 61 deletions(-) create mode 100644 .github/workflows/build-operator.yaml rename .github/workflows/{e2e-with-cluster.yaml => e2e.yaml} (63%) rename .github/workflows/{helm-install-e2e.yaml => helm-install-test.yaml} (67%) rename .github/workflows/{pull_request.yaml => pull-request.yaml} (94%) create mode 100644 hack/e2e/001-multicluster.sh create mode 100644 hack/e2e/manifests/001-multicluster.yaml diff --git a/.github/workflows/build-operator.yaml b/.github/workflows/build-operator.yaml new file mode 100644 index 00000000..0f6a5c8c --- /dev/null +++ b/.github/workflows/build-operator.yaml @@ -0,0 +1,57 @@ +name: Build - Uffizzi Cluster Operator + +on: + pull_request: + branches: [ main ] + types: [opened,reopened,synchronize,closed] + +permissions: + contents: read + pull-requests: write + id-token: write + +jobs: + build-operator: + name: Build and Push `operator` Image + runs-on: ubuntu-latest + if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }} + outputs: + tags: ${{ steps.meta.outputs.tags }} + uuid: ${{ env.UUID_OPERATOR }} + steps: + - name: Checkout git repo + uses: actions/checkout@v3 + - name: Generate UUID image name + id: uuid + run: echo "UUID_OPERATOR=$(uuidgen)" >> $GITHUB_ENV + - name: Docker metadata + id: meta + uses: docker/metadata-action@v4 + with: + # An anonymous, emphemeral registry built on ttl.sh + images: registry.uffizzi.com/${{ env.UUID_OPERATOR }} + tags: type=raw,value=48h + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Build and Push Image to Uffizzi Ephemeral Registry + uses: docker/build-push-action@v3 + with: + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + context: ./ + cache-from: type=gha + cache-to: type=gha,mode=max + - name: Create Helm Values File + run: | + cat < helm-values.yaml + image: + repository: registry.uffizzi.com/${{ env.UUID_OPERATOR }} + tag: 48h + EOF + cat helm-values.yaml # For debugging, to check the contents of the file. + - name: Upload Helm Values as Artifact + uses: actions/upload-artifact@v3 + with: + name: helm-values + path: helm-values.yaml diff --git a/.github/workflows/e2e-with-cluster.yaml b/.github/workflows/e2e.yaml similarity index 63% rename from .github/workflows/e2e-with-cluster.yaml rename to .github/workflows/e2e.yaml index 1b867c6f..29833172 100644 --- a/.github/workflows/e2e-with-cluster.yaml +++ b/.github/workflows/e2e.yaml @@ -1,4 +1,4 @@ -name: EnvTest with Cluster +name: Tests - E2E - EnvTest with Cluster # e2e tests running against a k8s cluster on: pull_request: @@ -19,12 +19,9 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Setup Flux CLI + - name: Setup Flux CLI # used in the make command uses: fluxcd/flux2/action@main - - name: Setup k3d - uses: ./.github/actions/k3d - - name: Run e2e tests against current cluster run: | make test-e2e-with-cluster-local @@ -43,12 +40,31 @@ jobs: - name: Setup Flux CLI uses: fluxcd/flux2/action@main - - name: Setup k3d - uses: ./.github/actions/k3d - - name: Run e2e tests against current tainted cluster run: | make test-e2e-with-tainted-cluster-local - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 + + minikube-perf-test: + name: Run e2e tests against Minikube + if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Flux CLI + uses: fluxcd/flux2/action@main + + - name: Start Minikube + run: | + make start-test-minikube + + - name: Run e2e tests against current cluster + run: | + make test-e2e-perf-with-cluster-local + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 \ No newline at end of file diff --git a/.github/workflows/helm-install-e2e.yaml b/.github/workflows/helm-install-test.yaml similarity index 67% rename from .github/workflows/helm-install-e2e.yaml rename to .github/workflows/helm-install-test.yaml index 5e88f2d7..525adefa 100644 --- a/.github/workflows/helm-install-e2e.yaml +++ b/.github/workflows/helm-install-test.yaml @@ -11,38 +11,6 @@ permissions: id-token: write jobs: - build-operator: - name: Build and Push `operator` Image - runs-on: ubuntu-latest - if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }} - outputs: - tags: ${{ steps.meta.outputs.tags }} - uuid: ${{ env.UUID_OPERATOR }} - steps: - - name: Checkout git repo - uses: actions/checkout@v3 - - name: Generate UUID image name - id: uuid - run: echo "UUID_OPERATOR=$(uuidgen)" >> $GITHUB_ENV - - name: Docker metadata - id: meta - uses: docker/metadata-action@v4 - with: - # An anonymous, emphemeral registry built on ttl.sh - images: registry.uffizzi.com/${{ env.UUID_OPERATOR }} - tags: type=raw,value=48h - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Build and Push Image to Uffizzi Ephemeral Registry - uses: docker/build-push-action@v3 - with: - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - context: ./ - cache-from: type=gha - cache-to: type=gha,mode=max - uffizzi-cluster: name: Deploy Helm chart to Uffizzi Virtual Cluster needs: @@ -53,6 +21,11 @@ jobs: - name: Checkout uses: actions/checkout@v3 + - name: Download Helm Values Artifact + uses: actions/download-artifact@v3 + with: + name: helm-values + # Identify comment to be updated - name: Find comment for Ephemeral Environment uses: peter-evans/find-comment@v2 @@ -92,21 +65,6 @@ jobs: - name: Apply Helm Chart id: prev run: | - # install krew - - # set -x; cd "$(mktemp -d)" && - # OS="$(uname | tr '[:upper:]' '[:lower:]')" && - # ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" && - # KREW="krew-${OS}_${ARCH}" && - # curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" && - # tar zxvf "${KREW}.tar.gz" && - # ./"${KREW}" install krew - - # cd - - - # install kuttl - # ./"${KREW}" install kuttl - if [[ ${RUNNER_DEBUG} == 1 ]]; then echo "`pwd`" echo "`ls`" @@ -115,10 +73,7 @@ jobs: export KUBECONFIG="`pwd`/kubeconfig" helm dep update ./chart helm upgrade --install --wait pr-${{ github.event.pull_request.number }} \ - ./chart --set image.repository=registry.uffizzi.com/${{ needs.build-operator.outputs.uuid }},image.tag=48h - - # kubectl apply -f examples/k3s-manifest-basic.yml - # kubectl apply -f examples/k8s-manifest-basic.yml + ./chart -f helm-values.yaml - name: Create or Update Comment with Deployment URL uses: peter-evans/create-or-update-comment@v2 diff --git a/.github/workflows/helm-release.yml b/.github/workflows/helm-release.yml index 787580f4..29adc445 100644 --- a/.github/workflows/helm-release.yml +++ b/.github/workflows/helm-release.yml @@ -1,4 +1,4 @@ -name: Release Helm Charts +name: Release - Helm Chart on: push: diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull-request.yaml similarity index 94% rename from .github/workflows/pull_request.yaml rename to .github/workflows/pull-request.yaml index 9332c0f0..6eb0e5fa 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull-request.yaml @@ -1,4 +1,4 @@ -name: Unit Tests and Coverage +name: Tests - Unit Tests and Coverage on: pull_request: diff --git a/Makefile b/Makefile index 637bf956..877039ae 100644 --- a/Makefile +++ b/Makefile @@ -170,6 +170,10 @@ test-e2e-without-cluster: manifests generate fmt vet envtest ## Run test. test-e2e-with-cluster: manifests generate fmt vet envtest ## Run test. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" ENVTEST_REMOTE=true go test ./... -coverprofile=coverage.txt -v +.PHONY: test-e2e-perf-with-cluster +test-e2e-perf-with-cluster: manifests generate fmt vet envtest ## Run test. + ./hack/run-e2e-perf.sh + .PHONY: test-e2e-with-cluster-local test-e2e-with-cluster-local: start-test-minikube test-e2e-with-cluster ## Run test. @@ -180,6 +184,9 @@ test-e2e-with-tainted-cluster: manifests generate fmt vet envtest ## Run test. .PHONY: test-e2e-with-tainted-cluster-local test-e2e-with-tainted-cluster-local: start-test-minikube-tainted test-e2e-with-tainted-cluster ## Run test. +.PHONY: test-e2e-perf-with-cluster-local +test-e2e-perf-with-cluster-local: start-test-minikube test-e2e-perf-with-cluster ## Run test. + ##@ Build .PHONY: build diff --git a/hack/e2e/001-multicluster.sh b/hack/e2e/001-multicluster.sh new file mode 100644 index 00000000..aa8a3a9e --- /dev/null +++ b/hack/e2e/001-multicluster.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +# create multiple uffizzi clusters + +for i in {1..10}; do + kubectl create -f hack/e2e/manifests/001-multicluster.yaml +done + +# Retrieve the names of the newly created UffizziCluster resources +# Assuming 'uffizzicluster' is the kind for the UffizziCluster resources +uffizzi_clusters=($(kubectl get uffizzicluster -o jsonpath='{.items[*].metadata.name}')) + +# Check if we have any clusters to monitor +if [ ${#uffizzi_clusters[@]} -eq 0 ]; then + echo "No UffizziClusters found. Exiting..." + exit 1 +fi + +echo "Monitoring the following UffizziClusters for readiness: ${uffizzi_clusters[@]}" + +# Function to check the APIReady condition of a UffizziCluster +check_api_ready() { + local cluster_name=$1 + api_ready=$(kubectl get uffizzicluster "$cluster_name" -o jsonpath='{.status.conditions[?(@.type=="APIReady")].status}') + echo "$api_ready" +} + +# Monitor each UffizziCluster until the APIReady condition is True +start_time=$(date +%s) +for cluster in "${uffizzi_clusters[@]}"; do + while true; do + api_ready=$(check_api_ready "$cluster") + if [ "$api_ready" == "True" ]; then + echo "UffizziCluster $cluster is ready." + break + else + echo "Waiting for UffizziCluster $cluster to become ready..." + sleep 5 + fi + done +done +end_time=$(date +%s) + +# Calculate the total time taken for all UffizziClusters to become ready +total_time=$((end_time - start_time)) +echo "All UffizziClusters are ready. Total time taken: $total_time seconds." diff --git a/hack/e2e/manifests/001-multicluster.yaml b/hack/e2e/manifests/001-multicluster.yaml new file mode 100644 index 00000000..9b06d897 --- /dev/null +++ b/hack/e2e/manifests/001-multicluster.yaml @@ -0,0 +1,4 @@ +kind: UffizziCluster +apiVersion: uffizzi.com/v1alpha1 +metadata: + generateName: multicluster- \ No newline at end of file