-
Notifications
You must be signed in to change notification settings - Fork 24
node-installer: add integration test and add special handlings for k3s #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d00f040
node-installer: add integration test
Mossaka aca6e02
ci: Add integration test workflow for node-installer
Mossaka 54a1faf
node-installer: modify the makefile for binary handling
Mossaka 63badf2
node-installer: add integration tests for multiple distributions
Mossaka c68b1c2
node-installer: make integration tests work
Mossaka 336a8ef
node-installer: remove accidentally checked in yaml file
Mossaka 768d6dc
node-installer: moved kind-config.yaml to inline in the script
Mossaka 9fee749
node-installer: move things around
Mossaka ecbee0d
node-installer: remove k3s-kwasm-job.yml file
Mossaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| name: Publish node-installer image | ||
| name: Build, Test, and Publish node-installer image | ||
|
|
||
| on: | ||
| workflow_call: | ||
|
|
@@ -9,57 +9,130 @@ on: | |
| required: true | ||
|
|
||
| jobs: | ||
| # Note: assumes being called in a workflow where build has already run and | ||
| # required artifacts have been uploaded | ||
| publish: | ||
| build-and-test: | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| distribution: [kind, minikube, microk8s, k3s] | ||
| outputs: | ||
| release_version: ${{ steps.set_version.outputs.RELEASE_VERSION }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set RELEASE_VERSION env var | ||
| id: set_version | ||
| run: | | ||
| if [[ "${{ startsWith(inputs.ref, 'refs/tags/v')}}" == "true" ]]; then | ||
| echo "RELEASE_VERSION=$(echo -n ${{ inputs.ref }} | cut -d '/' -f 3)" >> $GITHUB_ENV | ||
| RELEASE_VERSION=$(echo -n ${{ inputs.ref }} | cut -d '/' -f 3) | ||
| else | ||
| echo "RELEASE_VERSION=$(date +%Y%m%d-%H%M%S)-g$(git rev-parse --short HEAD)" >> $GITHUB_ENV | ||
| RELEASE_VERSION=$(date +%Y%m%d-%H%M%S)-g$(git rev-parse --short HEAD) | ||
| fi | ||
| echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV | ||
| echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT | ||
|
|
||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| path: _artifacts | ||
|
|
||
| # Setup buildx to build multiarch image: https://github.com/docker/build-push-action/blob/master/docs/advanced/multi-platform.md | ||
| - name: Set up QEMU | ||
| uses: docker/setup-qemu-action@v3 | ||
|
|
||
| - name: Setup buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Login to GitHub container registry | ||
| uses: docker/login-action@v3 | ||
| - name: Extract musl artifacts into ./node-installer/.tmp/linux/(amd64|arm64) dir | ||
| run: | | ||
| mkdir -p ./node-installer/.tmp/linux/amd64 | ||
| mkdir -p ./node-installer/.tmp/linux/arm64 | ||
| for f in ./_artifacts/*/*-x86_64.tar.gz; do tar -xf $f --directory ./node-installer/.tmp/linux/amd64; done | ||
| for f in ./_artifacts/*/*-aarch64.tar.gz; do tar -xf $f --directory ./node-installer/.tmp/linux/arm64; done | ||
|
|
||
| - name: Build node-installer image for testing | ||
| run: make build-dev-installer-image | ||
| working-directory: node-installer | ||
|
|
||
| - uses: helm/[email protected] | ||
| if: matrix.distribution == 'kind' | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
| install_only: true | ||
|
|
||
| - uses: medyagh/[email protected] | ||
| if: matrix.distribution == 'minikube' | ||
| with: | ||
| start: false | ||
| container-runtime: containerd | ||
|
|
||
| - uses: balchua/[email protected] | ||
| if: matrix.distribution == 'microk8s' | ||
|
|
||
| - name: Run KIND test | ||
| if: matrix.distribution == 'kind' | ||
| run: make test-kind | ||
| working-directory: node-installer | ||
|
|
||
| - name: Run MiniKube test | ||
| if: matrix.distribution == 'minikube' | ||
| run: make test-minikube | ||
| working-directory: node-installer | ||
|
|
||
| - name: Run MicroK8s test | ||
| if: matrix.distribution == 'microk8s' | ||
| run: make test-microk8s | ||
| working-directory: node-installer | ||
|
|
||
| - name: Run K3s test | ||
| if: matrix.distribution == 'k3s' | ||
| run: make test-k3s | ||
| working-directory: node-installer | ||
|
|
||
| - name: Collect k3s debug logs | ||
| if: matrix.distribution == 'k3s' && failure() | ||
| run: | | ||
| sudo k3s kubectl describe pods -n kwasm | ||
| sudo k3s kubectl describe pods | ||
|
|
||
| publish: | ||
| needs: build-and-test | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| path: _artifacts | ||
|
|
||
| - name: Set up QEMU | ||
| uses: docker/setup-qemu-action@v3 | ||
|
|
||
| - name: Setup buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| # Build and push node-installer image | ||
| # TODO: remove once https://github.com/spinkube/runtime-class-manager handles this | ||
| - name: Extract musl artifacts into ./node-installer/.tmp/linux/(amd64|arm64) dir | ||
| run: | | ||
| mkdir -p ./node-installer/.tmp/linux/amd64 | ||
| mkdir -p ./node-installer/.tmp/linux/arm64 | ||
| for f in ./_artifacts/*/*-x86_64.tar.gz; do tar -xf $f --directory ./node-installer/.tmp/linux/amd64; done | ||
| for f in ./_artifacts/*/*-aarch64.tar.gz; do tar -xf $f --directory ./node-installer/.tmp/linux/arm64; done | ||
|
|
||
| - name: Login to GitHub container registry | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Build and push node-installer image | ||
| uses: docker/build-push-action@v5 | ||
| with: | ||
| push: true | ||
| tags: | | ||
| ghcr.io/${{ github.repository }}/node-installer:${{ env.RELEASE_VERSION }} | ||
| ghcr.io/${{ github.repository }}/node-installer:${{ needs.build-and-test.outputs.release_version }} | ||
| context: node-installer | ||
| platforms: linux/amd64,linux/arm64 | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| kind: Cluster | ||
| apiVersion: kind.x-k8s.io/v1alpha4 | ||
| name: spin-test | ||
| nodes: | ||
| - role: control-plane | ||
| extraPortMappings: | ||
| - containerPort: 80 | ||
| hostPort: 8080 | ||
| protocol: TCP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| : ${IMAGE_NAME:=ghcr.io/spinkube/containerd-shim-spin/node-installer:dev} | ||
|
|
||
| echo "Installing K3s..." | ||
| curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--disable=traefik --write-kubeconfig-mode=644" sh - | ||
|
|
||
| echo "Waiting for K3s to be ready..." | ||
| sleep 10 | ||
| export KUBECONFIG=/etc/rancher/k3s/k3s.yaml | ||
| until kubectl get nodes | grep -q " Ready"; do | ||
| echo "Waiting for node to be ready..." | ||
| sleep 5 | ||
| done | ||
|
|
||
| echo "=== Step 2: Create namespace and deploy RuntimeClass ===" | ||
| kubectl create namespace kwasm || true | ||
| kubectl apply -f ../deployments/workloads/runtime.yaml | ||
|
|
||
| echo "=== Step 3: Build and deploy the KWasm node installer ===" | ||
| if ! docker image inspect $IMAGE_NAME >/dev/null 2>&1; then | ||
| echo "Building node installer image..." | ||
| PLATFORM=$(uname -m) | ||
| if [ "$PLATFORM" = "x86_64" ]; then | ||
| PLATFORM="linux/amd64" | ||
| ARCH="x86_64" | ||
| elif [ "$PLATFORM" = "aarch64" ] || [ "$PLATFORM" = "arm64" ]; then | ||
| PLATFORM="linux/arm64" | ||
| ARCH="aarch64" | ||
| else | ||
| echo "Unsupported platform: $PLATFORM" | ||
| exit 1 | ||
| fi | ||
|
|
||
| PLATFORM=$PLATFORM ARCH=$ARCH IMAGE_NAME=$IMAGE_NAME make build-dev-installer-image | ||
| fi | ||
|
|
||
| echo "Loading node installer image into K3s..." | ||
| docker save $IMAGE_NAME > node-installer.tar | ||
| sudo k3s ctr images import node-installer.tar | ||
| rm node-installer.tar | ||
|
|
||
| NODE_NAME=$(kubectl get nodes -o jsonpath='{.items[0].metadata.name}') | ||
| cp kwasm-job.yml k3s-kwasm-job.yml | ||
| sed -i "s/spin-test-control-plane-provision-kwasm/k3s-provision-kwasm/g" k3s-kwasm-job.yml | ||
| sed -i "s/spin-test-control-plane-provision-kwasm-dev/k3s-provision-kwasm-dev/g" k3s-kwasm-job.yml | ||
| sed -i "s/spin-test-control-plane/${NODE_NAME}/g" k3s-kwasm-job.yml | ||
|
|
||
| echo "Applying KWasm node installer job..." | ||
| kubectl apply -f ./k3s-kwasm-job.yml | ||
|
|
||
| echo "Waiting for node installer job to complete..." | ||
| kubectl wait -n kwasm --for=condition=Ready pod --selector=job-name=k3s-provision-kwasm --timeout=90s || true | ||
| kubectl wait -n kwasm --for=jsonpath='{.status.phase}'=Succeeded pod --selector=job-name=k3s-provision-kwasm --timeout=60s | ||
|
|
||
| if ! kubectl get pods -n kwasm | grep -q "k3s-provision-kwasm.*Completed"; then | ||
| echo "Node installer job failed!" | ||
| kubectl logs -n kwasm $(kubectl get pods -n kwasm -o name | grep k3s-provision-kwasm) | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "=== Step 4: Apply the workload ===" | ||
| sudo k3s ctr images pull ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:v0.18.0 | ||
| kubectl apply -f ../deployments/workloads/workload.yaml | ||
|
|
||
| echo "Waiting for deployment to be ready..." | ||
| kubectl wait --for=condition=Available deployment/wasm-spin --timeout=120s | ||
|
|
||
| echo "Checking pod status..." | ||
| kubectl get pods | ||
|
|
||
| echo "=== Step 5: Test the workload ===" | ||
| echo "Waiting for service to be ready..." | ||
| sleep 10 | ||
|
|
||
| echo "Testing workload with curl..." | ||
| kubectl port-forward svc/wasm-spin 8888:80 & | ||
| FORWARD_PID=$! | ||
| sleep 5 | ||
|
|
||
| MAX_RETRIES=3 | ||
| RETRY_COUNT=0 | ||
| SUCCESS=false | ||
|
|
||
| while [ $RETRY_COUNT -lt $MAX_RETRIES ] && [ "$SUCCESS" = false ]; do | ||
| if curl -s http://localhost:8888/hello | grep -q "Hello world from Spin!"; then | ||
| SUCCESS=true | ||
| echo "Workload test successful!" | ||
| else | ||
| echo "Retrying in 3 seconds..." | ||
| sleep 3 | ||
| RETRY_COUNT=$((RETRY_COUNT+1)) | ||
| fi | ||
| done | ||
|
|
||
| kill $FORWARD_PID || true | ||
Mossaka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if [ "$SUCCESS" = true ]; then | ||
| echo "=== Integration Test Passed! ===" | ||
| sudo /usr/local/bin/k3s-uninstall.sh | ||
| sudo rm -rf /etc/rancher/k3s | ||
| sudo rm -rf /var/lib/rancher/k3s | ||
| exit 0 | ||
| else | ||
| echo "=== Integration Test Failed! ===" | ||
| echo "Could not get a successful response from the workload." | ||
| kubectl describe pods | ||
| kubectl logs $(kubectl get pods -o name | grep wasm-spin) | ||
| sudo /usr/local/bin/k3s-uninstall.sh | ||
| sudo rm -rf /etc/rancher/k3s | ||
| sudo rm -rf /var/lib/rancher/k3s | ||
| exit 1 | ||
| fi | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.