diff --git a/.github/actions/deploy-current-branch/README.md b/.github/actions/deploy-current-branch/README.md new file mode 100644 index 000000000..6f97c7629 --- /dev/null +++ b/.github/actions/deploy-current-branch/README.md @@ -0,0 +1,35 @@ +# Deploy Current Branch Action + +This GitHub composite action builds a Docker image from the current branch commit and deploys it to a KubeVela cluster for development testing. + +## What it does + +- Generates a unique image tag from the latest commit hash +- Builds and loads the Docker image into a KinD cluster +- Applies KubeVela CRDs for upgrade safety +- Upgrades the KubeVela Helm release to use the local development image +- Verifies deployment status and the running image version + +## Usage + +```yaml +- name: Deploy Current Branch + uses: ./path/to/this/action +``` + +## Requirements + +- Docker, Helm, kubectl, and KinD must be available in your runner environment +- Kubernetes cluster access +- `charts/vela-core/crds` directory with CRDs +- Valid Helm chart at `charts/vela-core` + +## Steps performed + +1. **Generate commit hash for image tag** +2. **Build & load Docker image into KinD** +3. **Pre-apply chart CRDs** +4. **Upgrade KubeVela using local image** +5. **Verify deployment and image version** + +--- \ No newline at end of file diff --git a/.github/actions/deploy-current-branch/action.yaml b/.github/actions/deploy-current-branch/action.yaml new file mode 100644 index 000000000..5e296cd49 --- /dev/null +++ b/.github/actions/deploy-current-branch/action.yaml @@ -0,0 +1,89 @@ +name: 'Deploy Current Branch' +description: 'Builds Docker image from current branch commit and deploys it to KubeVela cluster for development testing' + +runs: + using: "composite" + steps: + # ======================================================================== + # Git Commit Hash Generation + # Generate unique image tag from current branch's latest commit + # ======================================================================== + - name: Get commit hash + id: commit_hash + shell: bash + run: | + COMMIT_HASH="git-$(git rev-parse --short HEAD)" + echo "Using commit hash: $COMMIT_HASH" + echo "COMMIT_HASH=$COMMIT_HASH" >> $GITHUB_ENV + + # ======================================================================== + # Docker Image Build and Cluster Loading + # Build development image from current code and load into KinD cluster + # ======================================================================== + - name: Build and load Docker image + shell: bash + run: | + echo "Building development image: vela-core-test:${{ env.COMMIT_HASH }}" + + mkdir -p $HOME/tmp/ + + docker build --no-cache \ + -t vela-core-test:${{ env.COMMIT_HASH }} \ + -f Dockerfile . + + echo "Loading image into KinD cluster..." + TMPDIR=$HOME/tmp/ kind load docker-image vela-core-test:${{ env.COMMIT_HASH }} + + # ======================================================================== + # Custom Resource Definitions Application + # Pre-apply CRDs to ensure upgrade compatibility and prevent conflicts + # ======================================================================== + - name: Pre-apply CRDs from target chart (upgrade-safe) + shell: bash + run: | + CRD_DIR="charts/vela-core/crds" + + echo "Applying CRDs idempotently..." + kubectl apply -f "${CRD_DIR}" + + # ======================================================================== + # KubeVela Helm Chart Upgrade + # Upgrade existing installation to use locally built development image + # ======================================================================== + - name: Upgrade KubeVela to development image + shell: bash + run: | + echo "Upgrading KubeVela to development version..." + helm upgrade kubevela ./charts/vela-core \ + --namespace vela-system \ + --set image.repository=vela-core-test \ + --set image.tag=${{ env.COMMIT_HASH }} \ + --set image.pullPolicy=IfNotPresent \ + --timeout 5m \ + --wait \ + --debug + + # ======================================================================== + # Deployment Status Verification + # Verify successful upgrade and confirm correct image deployment + # ======================================================================== + - name: Verify deployment status + shell: bash + run: | + echo "=== DEPLOYMENT VERIFICATION ===" + echo "Verifying upgrade to local development image..." + + echo "--- Pod Status ---" + kubectl get pods -n vela-system + + echo "--- Deployment Rollout ---" + kubectl rollout status deployment/kubevela-vela-core \ + -n vela-system \ + --timeout=300s + + echo "--- Deployed Image Version ---" + kubectl get deployment kubevela-vela-core \ + -n vela-system \ + -o yaml | grep "image:" | head -1 + + echo "Deployment verification completed successfully!" \ No newline at end of file diff --git a/.github/actions/deploy-latest-release/README.md b/.github/actions/deploy-latest-release/README.md new file mode 100644 index 000000000..4eabbc390 --- /dev/null +++ b/.github/actions/deploy-latest-release/README.md @@ -0,0 +1,32 @@ +# Install Latest KubeVela Release Action + +This GitHub composite action installs the latest stable KubeVela release from the official Helm repository and verifies its deployment status. + +## What it does + +- Discovers the latest stable KubeVela release tag from GitHub +- Adds and updates the official KubeVela Helm chart repository +- Installs KubeVela into the `vela-system` namespace (using Helm) +- Verifies pod status and deployment rollout for successful installation + +## Usage + +```yaml +- name: Install Latest KubeVela Release + uses: ./path/to/this/action +``` + +## Requirements + +- Helm, kubectl, jq, and curl must be available in your runner environment +- Kubernetes cluster access + +## Steps performed + +1. **Release Tag Discovery:** Fetches latest stable tag (without `v` prefix) +2. **Helm Repo Setup:** Adds/updates KubeVela Helm chart repo +3. **Install KubeVela:** Installs latest release in the `vela-system` namespace +4. **Status Verification:** Checks pod status and rollout for readiness + +--- + diff --git a/.github/actions/deploy-latest-release/action.yaml b/.github/actions/deploy-latest-release/action.yaml new file mode 100644 index 000000000..05e0115ef --- /dev/null +++ b/.github/actions/deploy-latest-release/action.yaml @@ -0,0 +1,68 @@ +name: 'Install Latest KubeVela Release' +description: 'Installs the latest stable KubeVela release from official Helm repository with status verification' + +runs: + using: "composite" + steps: + # ======================================================================== + # Latest Release Tag Discovery + # Fetch current stable release version from GitHub API + # ======================================================================== + - name: Get latest KubeVela release tag (no v prefix) + id: get_latest_tag + shell: bash + run: | + TAG=$(curl -s https://api.github.com/repos/kubevela/kubevela/releases/latest | \ + jq -r ".tag_name" | \ + awk '{sub(/^v/, ""); print}') + echo "LATEST_TAG=$TAG" >> $GITHUB_ENV + echo "Discovered latest release: $TAG" + + # ======================================================================== + # Helm Repository Configuration + # Add and update official KubeVela chart repository + # ======================================================================== + - name: Add KubeVela Helm repo + shell: bash + run: | + echo "Adding KubeVela Helm repository..." + helm repo add kubevela https://kubevela.github.io/charts + helm repo update + echo "Helm repository configuration completed" + + # ======================================================================== + # KubeVela Stable Release Installation + # Deploy latest stable version to vela-system namespace + # ======================================================================== + - name: Install KubeVela ${{ env.LATEST_TAG }} + shell: bash + run: | + echo "Installing KubeVela version: ${{ env.LATEST_TAG }}" + helm install \ + --create-namespace \ + -n vela-system \ + kubevela kubevela/vela-core \ + --version ${{ env.LATEST_TAG }} \ + --timeout 10m \ + --wait + echo "KubeVela installation completed" + + # ======================================================================== + # Installation Status Verification + # Verify successful deployment and readiness of KubeVela components + # ======================================================================== + - name: Post-install status + shell: bash + run: | + echo "=== INSTALLATION VERIFICATION ===" + echo "Verifying KubeVela deployment status..." + + echo "--- Pod Status ---" + kubectl get pods -n vela-system + + echo "--- Deployment Rollout ---" + kubectl rollout status deployment/kubevela-vela-core \ + -n vela-system \ + --timeout=300s + + echo "KubeVela installation verification completed successfully!" \ No newline at end of file diff --git a/.github/actions/e2e-test/README.md b/.github/actions/e2e-test/README.md new file mode 100644 index 000000000..ef5ca8b9b --- /dev/null +++ b/.github/actions/e2e-test/README.md @@ -0,0 +1,51 @@ +# Kubevela K8s Upgrade E2E Test Action + +A comprehensive GitHub composite action for running KubeVela Kubernetes upgrade end-to-end (E2E) tests with complete environment setup, multiple test suites, and failure diagnostics. + + +> **Note**: This action requires the `GO_VERSION` environment variable to be set in your workflow. + +## Quick Start + +### Basic Usage + +```yaml +name: E2E Tests +on: [push, pull_request] + +jobs: + e2e-tests: + runs-on: ubuntu-latest + env: + GO_VERSION: '1.23.8' + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run KubeVela E2E Tests + uses: ./.github/actions/upgrade-e2e-test +``` + +## Test Flow Diagram + +``` +┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐ +│ Environment │ │ E2E Environment │ │ Test Execution │ +│ Setup │───▶│ Preparation │───▶│ (3 Suites) │ +│ │ │ │ │ │ +│ • Install tools │ │ • Cleanup │ │ • API tests │ +│ • Setup Go │ │ • Core setup │ │ • Addon tests │ +│ • Dependencies │ │ • Helm tests │ │ • General tests │ +│ • Build project │ │ │ │ │ +└─────────────────┘ └──────────────────┘ └─────────────────┘ + │ + ▼ + ┌─────────────────┐ + │ Diagnostics │ + │ (On Failure) │ + │ │ + │ • Cluster logs │ + │ • System events │ + │ • Test artifacts│ + └─────────────────┘ +``` \ No newline at end of file diff --git a/.github/actions/e2e-test/action.yaml b/.github/actions/e2e-test/action.yaml new file mode 100644 index 000000000..068d6959c --- /dev/null +++ b/.github/actions/e2e-test/action.yaml @@ -0,0 +1,96 @@ +name: 'Kubevela K8s Upgrade e2e Test' +description: 'Runs Kubevela K8s upgrade e2e tests, uploads coverage, and collects diagnostics on failure.' + +inputs: + codecov-token: + description: 'Codecov token for uploading coverage reports' + required: false + default: '' + codecov-enable: + description: 'Enable codecov coverage upload' + required: false + default: 'false' + +runs: + using: "composite" + steps: + # ======================================================================== + # Environment Setup + # ======================================================================== + - name: Configure environment setup + uses: ./.github/actions/env-setup + + - name: Build project + shell: bash + run: make + + # ======================================================================== + # E2E Test Environment Preparation + # ======================================================================== + - name: Prepare e2e environment + shell: bash + run: | + echo "Preparing e2e test environment..." + make e2e-cleanup + make e2e-setup-core + + echo "Running Helm tests..." + helm test -n vela-system kubevela --timeout 5m + + # ======================================================================== + # E2E Test Execution + # ======================================================================== + - name: Run API e2e tests + shell: bash + run: | + echo "Running API e2e tests..." + make e2e-api-test + + - name: Run addon e2e tests + shell: bash + run: | + echo "Running addon e2e tests..." + make e2e-addon-test + + - name: Run general e2e tests + shell: bash + run: | + echo "Running general e2e tests..." + make e2e-test + + - name: Upload coverage report + if: ${{ inputs.codecov-enable == 'true' }} + uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 + with: + token: ${{ inputs.codecov-token }} + files: ./coverage.txt + flags: core-unittests + name: codecov-umbrella + fail_ci_if_error: false + + # ======================================================================== + # Failure Diagnostics + # ======================================================================== + - name: Collect failure diagnostics + if: failure() + shell: bash + run: | + echo "=== FAILURE DIAGNOSTICS ===" + echo "Collecting diagnostic information for debugging..." + + echo "--- Cluster Status ---" + kubectl get nodes -o wide || true + kubectl get pods -A || true + + echo "--- KubeVela System Logs ---" + kubectl logs -n vela-system -l app.kubernetes.io/name=vela-core --tail=100 || true + + echo "--- Recent Events ---" + kubectl get events -A --sort-by='.lastTimestamp' --field-selector type!=Normal || true + + echo "--- Helm Release Status ---" + helm list -A || true + helm status kubevela -n vela-system || true + + echo "--- Test Artifacts ---" + find . -name "*.log" -type f -exec echo "=== {} ===" \; -exec cat {} \; || true \ No newline at end of file diff --git a/.github/actions/env-setup/README.md b/.github/actions/env-setup/README.md new file mode 100644 index 000000000..a4cd04d24 --- /dev/null +++ b/.github/actions/env-setup/README.md @@ -0,0 +1,67 @@ +# Kubevela Test Environment Setup Action + +A GitHub Actions composite action that sets up a complete testing environment for Kubevela projects with Go, Kubernetes tools, and the Ginkgo testing framework. + +## Features + +- 🛠️ **System Dependencies**: Installs essential build tools (make, gcc, jq, curl, etc.) +- ☸️ **Kubernetes Tools**: Sets up kubectl and Helm for cluster operations +- 🐹 **Go Environment**: Configurable Go version with module caching +- 📦 **Dependency Management**: Downloads and verifies Go module dependencies +- 🧪 **Testing Framework**: Installs Ginkgo v2 for BDD-style testing + +## Usage + +```yaml +- name: Setup Kubevela Test Environment + uses: ./path/to/this/action + with: + go-version: '1.23.8' # Optional: Go version (default: 1.23.8) +``` + +### Example Workflow + +```yaml +name: Kubevela Tests +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Test Environment + uses: ./path/to/this/action + with: + go-version: '1.21' + + - name: Run Tests + run: | + ginkgo -r ./tests/e2e/ +``` + +## Inputs + +| Input | Description | Required | Default | Usage | +|-------|-------------|----------|---------|-------| +| `go-version` | Go version to install and use | No | `1.23.8` | Specify Go version for your project | + +## What This Action Installs + +### System Tools +- **make**: Build automation tool +- **gcc**: GNU Compiler Collection +- **jq**: JSON processor for shell scripts +- **ca-certificates**: SSL/TLS certificates +- **curl**: HTTP client for downloads +- **gnupg**: GNU Privacy Guard for security + +### Kubernetes Ecosystem +- **kubectl**: Kubernetes command-line tool (latest stable) +- **helm**: Kubernetes package manager (latest stable) + +### Go Development +- **Go Runtime**: Specified version with module caching enabled +- **Go Modules**: Downloaded and verified dependencies +- **Ginkgo v2.14.0**: BDD testing framework for Go \ No newline at end of file diff --git a/.github/actions/env-setup/action.yaml b/.github/actions/env-setup/action.yaml new file mode 100644 index 000000000..74e7658ad --- /dev/null +++ b/.github/actions/env-setup/action.yaml @@ -0,0 +1,79 @@ +name: 'Kubevela Test Environment Setup' +description: 'Sets up complete testing environment for Kubevela with Go, Kubernetes tools, and Ginkgo framework for E2E testing.' + +inputs: + go-version: + description: 'Go version to use for testing' + required: false + default: '1.23.8' + + +runs: + using: 'composite' + steps: + # ======================================================================== + # Environment Setup + # ======================================================================== + - name: Install system dependencies + shell: bash + run: | + # Update package manager and install essential tools + sudo apt-get update + sudo apt-get install -y \ + make \ + gcc \ + jq \ + ca-certificates \ + curl \ + gnupg + + - name: Install kubectl and helm + shell: bash + run: | + # Detect architecture + ARCH=$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/') + + # Install kubectl + echo "Installing kubectl for architecture: $ARCH" + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${ARCH}/kubectl" + chmod +x kubectl + sudo mv kubectl /usr/local/bin/ + + # Install helm using the official script (more reliable) + echo "Installing Helm using official script..." + curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 + chmod 700 get_helm.sh + ./get_helm.sh + rm get_helm.sh + + # Verify installations + echo "Verifying installations..." + kubectl version --client + helm version + + + - name: Setup Go environment + uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 + with: + go-version: ${{ inputs.go-version }} + cache: true + + - name: Download Go dependencies + shell: bash + run: | + # Download and cache Go module dependencies + go mod download + go mod verify + + - name: Install Ginkgo testing framework + shell: bash + run: | + echo "Installing Ginkgo testing framework..." + go install github.com/onsi/ginkgo/v2/ginkgo@v2.14.0 + + - name: Cache Go Dependencies + uses: actions/cache@v4 + with: + path: .work/pkg + key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-pkg- \ No newline at end of file diff --git a/.github/actions/multicluster-test/README.md b/.github/actions/multicluster-test/README.md new file mode 100644 index 000000000..45c69ef5f --- /dev/null +++ b/.github/actions/multicluster-test/README.md @@ -0,0 +1,35 @@ +# Kubevela K8s Upgrade Multicluster E2E Test Action + +A comprehensive GitHub Actions composite action for running Kubevela Kubernetes upgrade multicluster end-to-end tests with automated coverage reporting and failure diagnostics. + +## Usage + + +```yaml +name: Kubevela Multicluster E2E Tests +on: + push: + branches: [main, develop] + pull_request: + branches: [main] + +jobs: + multicluster-e2e: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Run Multicluster E2E Tests + uses: ./.github/actions/multicluster-test + with: + codecov-enable: 'true' + codecov-token: ${{ secrets.CODECOV_TOKEN }} +``` + +## Inputs + +| Input | Description | Required | Default | Type | +|-------|-------------|----------|---------|------| +| `codecov-token` | Codecov token for uploading coverage reports | No | `''` | string | +| `codecov-enable` | Enable codecov coverage upload | No | `'false'` | string | diff --git a/.github/actions/multicluster-test/action.yaml b/.github/actions/multicluster-test/action.yaml new file mode 100644 index 000000000..61e5882c5 --- /dev/null +++ b/.github/actions/multicluster-test/action.yaml @@ -0,0 +1,76 @@ +name: 'Kubevela K8s Upgrade Multicluster E2E Test' +description: 'Runs Kubevela Kubernetes upgrade multicluster end-to-end tests, uploads coverage, and collects diagnostics on failure.' +author: 'viskumar_gwre' + +inputs: + codecov-token: + description: 'Codecov token for uploading coverage reports' + required: false + default: '' + codecov-enable: + description: 'Enable codecov coverage upload' + required: false + default: 'false' + +runs: + using: 'composite' + steps: + # ======================================================================== + # Environment Setup + # ======================================================================== + - name: Configure environment setup + uses: ./.github/actions/env-setup + + # ======================================================================== + # E2E Test Execution + # ======================================================================== + - name: Prepare e2e test environment + shell: bash + run: | + # Build CLI tools and prepare test environment + echo "Building KubeVela CLI..." + make vela-cli + + echo "Cleaning up previous test artifacts..." + make e2e-cleanup + + echo "Setting up core authentication for e2e tests..." + make e2e-setup-core-auth + + - name: Execute multicluster upgrade e2e tests + shell: bash + run: | + # Add built CLI to PATH and run multicluster tests + export PATH=$(pwd)/bin:$PATH + + echo "Running e2e multicluster upgrade tests..." + make e2e-multicluster-test + + - name: Upload coverage report + if: ${{ inputs.codecov-enable == 'true' }} + uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 + with: + token: ${{ inputs.codecov-token }} + files: /tmp/e2e-profile.out,/tmp/e2e_multicluster_test.out + flags: e2e-multicluster-test + name: codecov-umbrella + + # ======================================================================== + # Failure Diagnostics + # ======================================================================== + - name: Collect failure diagnostics + if: failure() + shell: bash + run: | + echo "=== FAILURE DIAGNOSTICS ===" + echo "Collecting diagnostic information for debugging..." + + echo "--- Cluster Status ---" + kubectl get nodes -o wide || true + kubectl get pods -A || true + + echo "--- KubeVela System Logs ---" + kubectl logs -n vela-system -l app.kubernetes.io/name=vela-core --tail=100 || true + + echo "--- Recent Events ---" + kubectl get events -A --sort-by='.lastTimestamp' --field-selector type!=Normal || true \ No newline at end of file diff --git a/.github/actions/setup-kind-cluster/README.md b/.github/actions/setup-kind-cluster/README.md new file mode 100644 index 000000000..aaf709824 --- /dev/null +++ b/.github/actions/setup-kind-cluster/README.md @@ -0,0 +1,78 @@ +# Setup Kind Cluster Action + +A GitHub Action that sets up a Kubernetes testing environment using Kind (Kubernetes in Docker) for E2E testing. + +## Inputs + +| Input | Description | Required | Default | +|-------|-------------|----------|---------| +| `k8s-version` | Kubernetes version for the kind cluster | No | `v1.31.9` | + +## Quick Start + +```yaml +name: E2E Tests +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: '1.21' + + - name: Setup Kind Cluster + uses: ./.github/actions/setup-kind-cluster + with: + k8s-version: 'v1.31.9' + + - name: Run tests + run: | + kubectl cluster-info + make test-e2e +``` + +## What it does + +1. **Installs Kind CLI** - Downloads Kind v0.29.0 using Go +2. **Cleans up** - Removes any existing Kind clusters +3. **Creates cluster** - Spins up Kubernetes v1.31.9 cluster +4. **Sets up environment** - Configures KUBECONFIG for kubectl access +5. **Loads images** - Builds and loads Docker images using `make image-load` + +## File Structure + +Save as `.github/actions/setup-kind-cluster/action.yaml`: + +```yaml +name: 'SetUp kind cluster' +description: 'Sets up complete testing environment for Kubevela with Go, Kubernetes tools, and Ginkgo framework for E2E testing.' + +inputs: + k8s-version: + description: 'Kubernetes version for the kind cluster' + required: false + default: 'v1.31.9' + +runs: + using: 'composite' + steps: + # ======================================================================== + # Kind cluster Setup + # ======================================================================== + - name: Setup KinD + run: | + go install sigs.k8s.io/kind@v0.29.0 + kind delete cluster || true + kind create cluster --image=kindest/node:${{ inputs.k8s-version }} + shell: bash + + - name: Load image + run: | + mkdir -p $HOME/tmp/ + TMPDIR=$HOME/tmp/ make image-load + shell: bash +``` \ No newline at end of file diff --git a/.github/actions/setup-kind-cluster/action.yaml b/.github/actions/setup-kind-cluster/action.yaml new file mode 100644 index 000000000..824c78285 --- /dev/null +++ b/.github/actions/setup-kind-cluster/action.yaml @@ -0,0 +1,36 @@ +name: 'SetUp kind cluster' +description: 'Sets up a KinD (Kubernetes in Docker) cluster with configurable Kubernetes version and optional cluster naming for testing and development workflows.' +inputs: + k8s-version: + description: 'Kubernetes version for the kind cluster' + required: false + default: 'v1.31.9' + name: + description: 'Name of the kind cluster' + required: false +runs: + using: 'composite' + steps: + # ======================================================================== + # Kind cluster Setup + # ======================================================================== + - name: Setup KinD + run: | + go install sigs.k8s.io/kind@v0.29.0 + if [ -n "${{ inputs.name }}" ]; then + kind delete cluster --name="${{ inputs.name }}" || true + kind create cluster --name="${{ inputs.name }}" --image=kindest/node:${{ inputs.k8s-version }} + kind export kubeconfig --internal --name="${{ inputs.name }}" --kubeconfig /tmp/${{ inputs.name }}.kubeconfig + else + kind delete cluster || true + kind create cluster --image=kindest/node:${{ inputs.k8s-version }} + fi + shell: bash + + - name: Load image + run: | + if [ -z "${{ inputs.name }}" ]; then + mkdir -p $HOME/tmp/ + TMPDIR=$HOME/tmp/ make image-load + fi + shell: bash \ No newline at end of file diff --git a/.github/actions/unit-test/README.md b/.github/actions/unit-test/README.md new file mode 100644 index 000000000..492389bc3 --- /dev/null +++ b/.github/actions/unit-test/README.md @@ -0,0 +1,34 @@ +# Kubevela K8s Upgrade Unit Test Action + +A comprehensive GitHub composite action for running KubeVela Kubernetes upgrade unit tests with coverage reporting and failure diagnostics. + +## Inputs + +| Input | Description | Required | Default | +|-------|-------------|----------|---------| +| `codecov-token` | Codecov token for uploading coverage reports | ❌ | `''` | +| `codecov-enable` | Enable Codecov coverage upload (`'true'` or `'false'`) | ❌ | `'false'` | +| `go-version` | Go version to use for testing | ❌ | `'1.23.8'` | + +## Quick Start + +### Basic Usage + +```yaml +name: Unit Tests with Coverage +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run KubeVela Unit Tests + uses: viskumar_gwre/kubevela-k8s-upgrade-unit-test-action@v1 + with: + codecov-enable: 'true' + codecov-token: ${{ secrets.CODECOV_TOKEN }} + go-version: '1.23.8' +``` \ No newline at end of file diff --git a/.github/actions/unit-test/action.yaml b/.github/actions/unit-test/action.yaml new file mode 100644 index 000000000..e5cf2e198 --- /dev/null +++ b/.github/actions/unit-test/action.yaml @@ -0,0 +1,67 @@ +name: 'Kubevela K8s Upgrade Unit Test' +description: 'Runs Kubevela K8s upgrade unit tests, uploads coverage, and collects diagnostics on failure.' + +inputs: + codecov-token: + description: 'Codecov token for uploading coverage reports' + required: false + default: '' + codecov-enable: + description: 'Enable codecov coverage upload' + required: false + default: 'false' + +runs: + using: "composite" + steps: + # ======================================================================== + # Environment Setup + # ======================================================================== + - name: Configure environment setup + uses: ./.github/actions/env-setup + + # ======================================================================== + # Unit Test Execution + # ======================================================================== + - name: Run unit tests + shell: bash + run: | + echo "Running unit tests..." + make test + + - name: Upload coverage report + if: ${{ inputs.codecov-enable == 'true' }} + uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 + with: + token: ${{ inputs.codecov-token }} + files: ./coverage.txt + flags: core-unittests + name: codecov-umbrella + fail_ci_if_error: false + + # ======================================================================== + # Failure Diagnostics + # ======================================================================== + - name: Collect failure diagnostics + if: failure() + shell: bash + run: | + echo "=== FAILURE DIAGNOSTICS ===" + echo "Collecting diagnostic information for debugging..." + + echo "--- Go Environment ---" + go version || true + go env || true + + echo "--- Cluster Status ---" + kubectl get nodes -o wide || true + kubectl get pods -A || true + + echo "--- KubeVela System Logs ---" + kubectl logs -n vela-system -l app.kubernetes.io/name=vela-core --tail=100 || true + + echo "--- Recent Events ---" + kubectl get events -A --sort-by='.lastTimestamp' --field-selector type!=Normal || true + + echo "--- Test Artifacts ---" + find . -name "*.log" -o -name "*test*.xml" -o -name "coverage.*" | head -20 || true \ No newline at end of file diff --git a/.github/workflows/definition-lint.yml b/.github/workflows/definition-lint.yml index 1714f5c37..bdfa61c0d 100644 --- a/.github/workflows/definition-lint.yml +++ b/.github/workflows/definition-lint.yml @@ -33,9 +33,9 @@ jobs: submodules: true - name: Setup KinD - run: | - go install sigs.k8s.io/kind@v0.29.0 - kind create cluster --image=kindest/node:v1.31.9 + uses: ./.github/actions/setup-kind-cluster + with: + name: linter - name: Definition Doc generate check run: | diff --git a/.github/workflows/e2e-multicluster-test.yml b/.github/workflows/e2e-multicluster-test.yml index b2be990c1..5ac8d12a8 100644 --- a/.github/workflows/e2e-multicluster-test.yml +++ b/.github/workflows/e2e-multicluster-test.yml @@ -44,7 +44,7 @@ jobs: if: needs.detect-noop.outputs.noop != 'true' strategy: matrix: - k8s-version: ["v1.31"] + k8s-version: ["v1.31.9"] concurrency: group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.k8s-version }} cancel-in-progress: true @@ -53,61 +53,31 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 - - name: Install tools - run: | - sudo apt-get update - sudo apt-get install make gcc jq ca-certificates curl gnupg -y - sudo snap install kubectl --classic - sudo snap install helm --classic - - - name: Setup Go - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 + - name: Setup worker cluster kinD + uses: ./.github/actions/setup-kind-cluster with: - go-version: ${{ env.GO_VERSION }} + name: worker + k8s-version: ${{ matrix.k8s-version }} - - name: Get dependencies - run: | - go get -v -t -d ./... - - - name: Setup KinD - run: | - go install sigs.k8s.io/kind@v0.29.0 - kind delete cluster --name worker || true - kind create cluster --name worker --image=kindest/node:v1.31.9 - kind export kubeconfig --internal --name worker --kubeconfig /tmp/worker.kubeconfig - kind delete cluster || true - kind create cluster --image=kindest/node:v1.31.9 - - - name: Load image - run: | - mkdir -p $HOME/tmp/ - TMPDIR=$HOME/tmp/ make image-load - - - name: Cleanup for e2e tests - run: | - make vela-cli - make e2e-cleanup - make e2e-setup-core-auth - - - name: Run e2e multicluster tests - run: | - export PATH=$(pwd)/bin:$PATH - make e2e-multicluster-test - - - name: Stop kubevela, get profile - run: | - make end-e2e-core-shards - - - name: Upload coverage report - uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 + - name: Setup master cluster kinD + uses: ./.github/actions/setup-kind-cluster with: - token: ${{ secrets.CODECOV_TOKEN }} - files: /tmp/e2e-profile.out,/tmp/e2e_multicluster_test.out - flags: e2e-multicluster-test - name: codecov-umbrella + k8s-version: ${{ matrix.k8s-version }} + + - name: Run upgrade multicluster tests + uses: ./.github/actions/multicluster-test + with: + codecov-enable: true + codecov-token: ${{ secrets.CODECOV_TOKEN }} - name: Clean e2e profile - run: rm /tmp/e2e-profile.out + run: | + if [ -f /tmp/e2e-profile.out ]; then + rm /tmp/e2e-profile.out + echo "E2E profile cleaned" + else + echo "E2E profile not found, skipping cleanup" + fi - name: Cleanup image if: ${{ always() }} diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index de063b15f..ee46361ae 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -53,68 +53,26 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 - - name: Install tools - run: | - sudo apt-get update - sudo apt-get install make gcc jq ca-certificates curl gnupg -y - sudo snap install kubectl --classic - sudo snap install helm --classic - - - name: Setup Go - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 - with: - go-version: ${{ env.GO_VERSION }} - - - name: Get dependencies - run: | - go get -v -t -d ./... - - name: Setup KinD - run: | - go install sigs.k8s.io/kind@v0.29.0 - kind delete cluster || true - kind create cluster --image=kindest/node:v1.31.9 + uses: ./.github/actions/setup-kind-cluster - - name: Get Ginkgo - run: | - go install github.com/onsi/ginkgo/v2/ginkgo@v2.14.0 - - - name: Load image - run: | - mkdir -p $HOME/tmp/ - TMPDIR=$HOME/tmp/ make image-load - - - name: Run Make - run: make - - - name: Prepare for e2e tests - run: | - make e2e-cleanup - make e2e-setup-core - helm test -n vela-system kubevela --timeout 5m - - - name: Run api e2e tests - run: make e2e-api-test - - - name: Run addons e2e tests - run: make e2e-addon-test - - - name: Run e2e tests - run: make e2e-test - - - name: Stop kubevela, get profile - run: make end-e2e - - - name: Upload coverage report - uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 + # ======================================================================== + # E2E Test Execution + # ======================================================================== + - name: Run upgrade e2e tests + uses: ./.github/actions/e2e-test with: - token: ${{ secrets.CODECOV_TOKEN }} - files: /tmp/e2e-profile.out - flags: e2etests - name: codecov-umbrella + codecov-enable: true + codecov-token: ${{ secrets.CODECOV_TOKEN }} - name: Clean e2e profile - run: rm /tmp/e2e-profile.out + run: | + if [ -f /tmp/e2e-profile.out ]; then + rm /tmp/e2e-profile.out + echo "E2E profile cleaned" + else + echo "E2E profile not found, skipping cleanup" + fi - name: Cleanup image if: ${{ always() }} diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 1de8a4aa4..1549f8c0b 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -97,28 +97,16 @@ jobs: with: submodules: true - - name: Setup Go - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 - with: - go-version: ${{ env.GO_VERSION }} - + - name: Setup Env + uses: ./.github/actions/env-setup + - name: Setup node uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 with: node-version: "14" - - name: Cache Go Dependencies - uses: actions/cache@v4 - with: - path: .work/pkg - key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }} - restore-keys: ${{ runner.os }}-pkg- - - - name: Setup KinD - run: | - go install sigs.k8s.io/kind@v0.29.0 - kind delete cluster --name kind || true - kind create cluster --name kind --image=kindest/node:v1.31.9 --kubeconfig ~/.kube/config + - name: Setup kinD + uses: ./.github/actions/setup-kind-cluster - name: Run cross-build run: make cross-build diff --git a/.github/workflows/sdk-test.yml b/.github/workflows/sdk-test.yml index 02cbd6327..b150d7c14 100644 --- a/.github/workflows/sdk-test.yml +++ b/.github/workflows/sdk-test.yml @@ -16,11 +16,6 @@ on: permissions: contents: read -env: - # Common versions - GO_VERSION: '1.23.8' - GOLANGCI_VERSION: 'v1.60.1' - jobs: sdk-tests: runs-on: ubuntu-22.04 @@ -28,10 +23,8 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 - - name: Setup Go - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 - with: - go-version: ${{ env.GO_VERSION }} + - name: Setup Env + uses: ./.github/actions/env-setup - name: Install Go tools run: | @@ -39,9 +32,9 @@ jobs: make golangci - name: Setup KinD - run: | - go install sigs.k8s.io/kind@v0.29.0 - kind create cluster --image=kindest/node:v1.31.9 + uses: ./.github/actions/setup-kind-cluster + with: + name: sdk-test - name: Build CLI run: make vela-cli diff --git a/.github/workflows/sync-api.yml b/.github/workflows/sync-api.yml index 359d92e4a..f5f938772 100644 --- a/.github/workflows/sync-api.yml +++ b/.github/workflows/sync-api.yml @@ -10,21 +10,16 @@ on: permissions: contents: read -env: - GO_VERSION: '1.23.8' - jobs: sync-core-api: runs-on: ubuntu-22.04 steps: - - name: Set up Go - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 - with: - go-version: ${{ env.GO_VERSION }} - - name: Check out code into the Go module directory uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + - name: Setup Env + uses: ./.github/actions/env-setup + - name: Get the version id: get_version run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT diff --git a/.github/workflows/sync-sdk.yaml b/.github/workflows/sync-sdk.yaml index ef21596ae..796d9b3a0 100644 --- a/.github/workflows/sync-sdk.yaml +++ b/.github/workflows/sync-sdk.yaml @@ -14,28 +14,16 @@ on: permissions: contents: read -env: - GO_VERSION: '1.23.8' - jobs: sync_sdk: runs-on: ubuntu-22.04 steps: - - name: Set up Go - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 - with: - go-version: ${{ env.GO_VERSION }} - name: Check out code into the Go module directory uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - name: Get the version - id: get_version - run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT - - - name: Get dependencies - run: | - go get -v -t -d ./... + - name: Env setup + uses: ./.github/actions/env-setup - name: Install Go tools run: | @@ -44,6 +32,10 @@ jobs: - name: Build CLI run: make vela-cli + - name: Get the version + id: get_version + run: echo "VERSION=${GITHUB_REF}" >> $GITHUB_OUTPUT + - name: Sync SDK to kubevela/kubevela-go-sdk run: bash ./hack/sdk/sync.sh env: diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index ed78a19be..4e24a315f 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -14,10 +14,6 @@ on: permissions: contents: read -env: - # Common versions - GO_VERSION: "1.23.8" - jobs: detect-noop: permissions: @@ -41,41 +37,19 @@ jobs: if: needs.detect-noop.outputs.noop != 'true' steps: - - name: Set up Go - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 - with: - go-version: ${{ env.GO_VERSION }} - - name: Check out code into the Go module directory uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 with: submodules: true - - name: Cache Go Dependencies - uses: actions/cache@v4 + - name: Setup Env + uses: ./.github/actions/env-setup + + - name: Setup KinD with Kubernetes + uses: ./.github/actions/setup-kind-cluster + + - name: Run unit tests + uses: ./.github/actions/unit-test with: - path: .work/pkg - key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }} - restore-keys: ${{ runner.os }}-pkg- - - - name: Install ginkgo - run: | - sudo sed -i 's/azure\.//' /etc/apt/sources.list - sudo apt-get update - sudo apt-get install -y golang-ginkgo-dev - - - name: Setup KinD - run: | - go install sigs.k8s.io/kind@v0.29.0 - kind create cluster --image=kindest/node:v1.31.9 - - - name: Run Make test - run: make test - - - name: Upload coverage report - uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 #v5.4.3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ./coverage.txt - flags: core-unittests - name: codecov-umbrella + codecov-enable: true + codecov-token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/upgrade-e2e-multicluster-test.yml b/.github/workflows/upgrade-e2e-multicluster-test.yml new file mode 100644 index 000000000..b120efac2 --- /dev/null +++ b/.github/workflows/upgrade-e2e-multicluster-test.yml @@ -0,0 +1,98 @@ +# ============================================================================= +# E2E Upgrade Multicluster Test Workflow +# ============================================================================= +# This workflow performs end-to-end testing for KubeVela multicluster upgrades. +# It tests the upgrade path from the latest released version to the current +# development branch across multiple Kubernetes versions. +# +# Test Flow: +# 1. Install latest KubeVela release +# 2. Build and upgrade to current development version +# 3. Run multicluster e2e tests to verify functionality +# ============================================================================= + +name: E2E Upgrade Multicluster Test + +# ============================================================================= +# Trigger Configuration +# ============================================================================= +on: + # Trigger on pull requests targeting main branches + pull_request: + branches: + - master + - release-* + + # Allow manual workflow execution + workflow_dispatch: {} + +# ============================================================================= +# Security Configuration +# ============================================================================= +permissions: + contents: read # Read-only access to repository contents + +# ============================================================================= +# Global Environment Variables +# ============================================================================= +env: + GO_VERSION: '1.23.8' # Go version for building and testing + +# ============================================================================= +# Job Definitions +# ============================================================================= +jobs: + upgrade-multicluster-tests: + name: Upgrade Multicluster Tests + runs-on: ubuntu-22.04 + if: startsWith(github.head_ref, 'chore/upgrade-k8s-') + timeout-minutes: 60 # Prevent hanging jobs + + # ========================================================================== + # Matrix Strategy - Test against multiple Kubernetes versions + # ========================================================================== + strategy: + fail-fast: false # Continue testing other versions if one fails + matrix: + k8s-version: ['v1.31.9'] + + # ========================================================================== + # Concurrency Control - Prevent overlapping runs + # ========================================================================== + concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.k8s-version }} + cancel-in-progress: true + + steps: + # ======================================================================== + # Environment Setup + # ======================================================================== + + - name: Check out repository + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 + + # ======================================================================== + # Kubernetes Cluster Setup + # ======================================================================== + + - name: Setup worker cluster kinD + uses: ./.github/actions/setup-kind-cluster + with: + name: worker + + - name: Setup KinD master clusters for multicluster testing + uses: ./.github/actions/setup-kind-cluster + with: + k8s-version: ${{ matrix.k8s-version }} + + - name: Deploy latest release + uses: ./.github/actions/deploy-latest-release + + - name: Upgrade from current branch + uses: ./.github/actions/deploy-current-branch + + - name: Run upgarde multicluster tests + uses: ./.github/actions/multicluster-test + with: + codecov-enable: false + codecov-token: '' \ No newline at end of file diff --git a/.github/workflows/upgrade-e2e-test.yml b/.github/workflows/upgrade-e2e-test.yml new file mode 100644 index 000000000..32fc3d8e8 --- /dev/null +++ b/.github/workflows/upgrade-e2e-test.yml @@ -0,0 +1,102 @@ +# ============================================================================= +# Upgrade E2E Test Workflow +# ============================================================================= +# This workflow performs comprehensive end-to-end testing for KubeVela upgrades. +# It validates the upgrade path from the latest stable release to the current +# development version by running multiple test suites including API, addon, +# and general e2e tests. +# +# Test Flow: +# 1. Install latest KubeVela release +# 2. Build and upgrade to current development version +# 3. Run comprehensive e2e test suites (API, addon, general) +# 4. Validate upgrade functionality and compatibility +# ============================================================================= + +name: Upgrade E2E Test + +# ============================================================================= +# Trigger Configuration +# ============================================================================= +on: + # Trigger on pull requests targeting main branches + pull_request: + branches: + - master + - release-* + + # Allow manual workflow execution + workflow_dispatch: {} + +# ============================================================================= +# Environment Variables +# ============================================================================= +env: + GO_VERSION: '1.23.8' + +# ============================================================================= +# Security Configuration +# ============================================================================= +permissions: + contents: read # Read-only access to repository contents + +# ============================================================================= +# Job Definitions +# ============================================================================= +jobs: + upgrade-tests: + name: Upgrade E2E Tests + runs-on: ubuntu-22.04 + if: startsWith(github.head_ref, 'chore/upgrade-k8s-') + timeout-minutes: 90 # Extended timeout for comprehensive e2e testing + + # ========================================================================== + # Matrix Strategy - Test against multiple Kubernetes versions + # ========================================================================== + strategy: + fail-fast: false # Continue testing other versions if one fails + matrix: + k8s-version: ['v1.31.9'] + + # ========================================================================== + # Concurrency Control - Prevent overlapping runs + # ========================================================================== + concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.k8s-version }} + cancel-in-progress: true + + steps: + # ======================================================================== + # Repository Setup + # ======================================================================== + - name: Check out code + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 + + # ======================================================================== + # Kubernetes Cluster Setup + # ======================================================================== + - name: Setup KinD with Kubernetes ${{ matrix.k8s-version }} + uses: ./.github/actions/setup-kind-cluster + with: + k8s-version: ${{ matrix.k8s-version }} + + - name: Build vela CLI + run: make vela-cli + + - name: Build kubectl-vela plugin + run: make kubectl-vela + + - name: Install kustomize + run: make kustomize + + - name: Deploy latest release + uses: ./.github/actions/deploy-latest-release + + - name: Upgrade from current branch + uses: ./.github/actions/deploy-current-branch + + # ======================================================================== + # E2E Test Execution + # ======================================================================== + - name: Run upgrade e2e tests + uses: ./.github/actions/e2e-test \ No newline at end of file diff --git a/.github/workflows/upgrade-unit-test.yml b/.github/workflows/upgrade-unit-test.yml new file mode 100644 index 000000000..bc98a78a2 --- /dev/null +++ b/.github/workflows/upgrade-unit-test.yml @@ -0,0 +1,83 @@ +# ============================================================================= +# Upgrade Unit Test Workflow +# ============================================================================= +# This workflow performs unit testing for KubeVela upgrades by: +# 1. Installing the latest stable KubeVela release +# 2. Building and upgrading to the current development version +# 3. Running unit tests to validate the upgrade functionality +# ============================================================================= + +name: Upgrade Unit Test + +# ============================================================================= +# Trigger Configuration +# ============================================================================= +on: + # Trigger on pull requests targeting main and release branches + pull_request: + branches: + - master + - release-* + + # Allow manual workflow execution + workflow_dispatch: {} + +# ============================================================================= +# Security Configuration +# ============================================================================= +permissions: + contents: read # Read-only access to repository contents + +# ============================================================================= +# Job Definitions +# ============================================================================= +jobs: + upgrade-tests: + name: Upgrade Unit Tests + runs-on: ubuntu-22.04 + if: startsWith(github.head_ref, 'chore/upgrade-k8s-') + timeout-minutes: 45 # Prevent hanging jobs + + # ========================================================================== + # Matrix Strategy - Test against multiple Kubernetes versions + # ========================================================================== + strategy: + fail-fast: false # Continue testing other versions if one fails + matrix: + k8s-version: ['v1.31.9'] + + # ========================================================================== + # Concurrency Control - Prevent overlapping runs + # ========================================================================== + concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.k8s-version }} + cancel-in-progress: true + + steps: + # ======================================================================== + # Environment Setup + # ======================================================================== + + - name: Check out code + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 + + # ======================================================================== + # Kubernetes Cluster Setup + # ======================================================================== + + - name: Setup KinD with Kubernetes ${{ matrix.k8s-version }} + uses: ./.github/actions/setup-kind-cluster + with: + k8s-version: ${{ matrix.k8s-version }} + + - name: Deploy latest release + uses: ./.github/actions/deploy-latest-release + + - name: Upgrade from current branch + uses: ./.github/actions/deploy-current-branch + + - name: Run unit tests + uses: ./.github/actions/unit-test + with: + codecov-enable: false + codecov-token: ''