Skip to content

Test apps

Test apps #66

name: Test apps
on:
workflow_dispatch:
inputs:
find_args:
description: 'Specify a set of folders to test apps from, e.g., "apps/nirmata apps/wandb"'
required: false
default: 'apps'
masters:
description: 'Number of master nodes'
required: false
default: '1'
workers:
description: 'Number of worker nodes'
required: false
default: '1'
schedule:
- cron: '0 9 * * *' # 09:00 UTC
push:
branches:
- '**'
paths:
- apps/*/example/**
- scripts/**
- .github/workflows/helm-app-deploy.yml
pull_request:
types: [opened, synchronize, reopened]
paths:
- apps/*/example/**
- scripts/**
- .github/workflows/helm-app-deploy.yml
jobs:
detect-tested-apps:
runs-on: ubuntu-latest
outputs:
changed_folders: ${{ steps.get-tested-apps.outputs.folders }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0 # Ensure full commit history
- name: Ensure the main branch is available
run: |
git fetch origin main --depth=1
- name: Get Tested Apps
id: get-tested-apps
run: |
if [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then
echo "Running: find ${{ github.event.inputs.find_args }}"
all_detected_files=$(find ${{ github.event.inputs.find_args }} -type d -name example)
elif [[ ${{ github.event_name }} == 'schedule' ]]; then
if [[ "${{ vars.ENABLE_CRON }}" == "1" ]]; then
all_detected_files=$(find apps -type d -name example)
else
echo "Repo var ENABLE_CRON is not set or does not equal '1'."
all_detected_files=""
fi
else
all_detected_files=$(git diff --name-only --diff-filter=ACMRT origin/main HEAD)
fi
echo "$all_detected_files"
tested_folders=$(echo "$all_detected_files" | tr ' ' '\n' | grep -E '^apps/[^/]+/' | cut -d '/' -f2 | sort -u | grep -vF "k0rdent-utils" | jq -R -s -c 'split("\n")[:-1]')
echo "Detected changes in: $tested_folders"
echo "folders=$tested_folders" >> "$GITHUB_OUTPUT"
test-app:
needs: detect-tested-apps
runs-on: ubuntu-latest
if: ${{ needs.detect-tested-apps.outputs.changed_folders != '[]' }} # Skip if no changed folders
strategy:
fail-fast: false
matrix:
folder: ${{ fromJson(needs.detect-tested-apps.outputs.changed_folders) }}
steps:
- name: Checkout Repository
uses: actions/checkout@v6
with:
fetch-depth: 0 # Ensure full commit history
- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r scripts/requirements.txt
- name: Get app test settings
run: |
app=${{ matrix.folder }}
test_settings=$(python3 ./scripts/utils.py print-test-vars "$app")
echo "$test_settings"
echo "$test_settings" >> $GITHUB_ENV
echo "DEBUG=${{ runner.debug }}"
echo "DEBUG=${{ runner.debug }}" >> $GITHUB_ENV
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "Pull request - use fork ghcr registry"
repo_url="$(echo "oci://ghcr.io/${{ github.event.pull_request.head.repo.owner.login }}/${{ github.event.pull_request.head.repo.name }}/charts" | tr '[:upper:]' '[:lower:]')"
elif [ "${{ github.repository }}" != "k0rdent/catalog" ] && [ "${{ github.ref }}" != "refs/heads/main" ]; then
echo "'In fork' test - use fork ghcr registry"
repo_url="$(echo "oci://ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/charts" | tr '[:upper:]' '[:lower:]')"
fi
if [ -n "$repo_url" ]; then
echo "REPO_URL=$repo_url"
echo "REPO_URL=$repo_url" >> $GITHUB_ENV
fi
- name: Check app charts changed
run: |
app=${{ matrix.folder }}
git diff --name-only --diff-filter=ACMRT origin/main HEAD -- "apps/$app/charts"
if ! git diff --name-only --diff-filter=ACMRT --quiet origin/main HEAD -- "apps/$app/charts"; then
echo "App charts changed"
echo "APP_CHARTS_CHANGED=true" >> $GITHUB_ENV
else
echo "App charts not changed"
echo "APP_CHARTS_CHANGED=false" >> $GITHUB_ENV
fi
- name: Use fork ghcr registry in example Helm chart
if: (env.DEPLOY_CHART == 'true' || env.DEPLOY_MULTICLUSTERSERVICE == 'true') && env.APP_CHARTS_CHANGED == 'true'
run: |
export APP=${{ matrix.folder }}
if [ -n "$REPO_URL" ]; then
echo "Replacing 'ghcr.io/k0rdent/catalog/charts' with '$repo_path' for forked/non-main build"
sed -i "s|oci://ghcr.io/k0rdent/catalog/charts|$REPO_URL|g" apps/$APP/example/Chart.yaml
./scripts/retry.sh helm dependency update "apps/$APP/example"
fi
- name: Test - Show service templates install commands
if: env.DEPLOY_CHART == 'true' || env.DEPLOY_MULTICLUSTERSERVICE == 'true'
run: |
export APP=${{ matrix.folder }}
python3 ./scripts/utils.py install-servicetemplates $APP -e example
- name: Test - Ensure MultiClusterService config
if: env.DEPLOY_CHART == 'true' || env.DEPLOY_MULTICLUSTERSERVICE == 'true'
run: |
export APP=${{ matrix.folder }}
./scripts/ensure_mcs_config.sh
- name: Install kubectl
if: env.DEPLOY_CHART == 'true' || env.DEPLOY_MULTICLUSTERSERVICE == 'true'
run: |
curl -LO "https://dl.k8s.io/release/v1.35.0/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
- name: Install Helm
if: env.DEPLOY_CHART == 'true' || env.DEPLOY_MULTICLUSTERSERVICE == 'true'
run: |
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-4 | bash
- name: Check updates
run: |
app=${{ matrix.folder }}
python3 ./scripts/chart_ctl.py check-updates "$app"
- name: Install crane
if: env.CHECK_IMAGES == 'true'
run: |
OS=Linux
ARCH=x86_64
VERSION=v0.20.6
curl -L "https://github.com/google/go-containerregistry/releases/download/${VERSION}/go-containerregistry_${OS}_${ARCH}.tar.gz" -o go-containerregistry.tar.gz
tar -zxvf go-containerregistry.tar.gz -C /usr/local/bin/ crane
crane version
- name: Check images
if: env.CHECK_IMAGES == 'true'
run: |
app=${{ matrix.folder }}
python3 ./scripts/chart_ctl.py check-images "$app"
- name: Install Kind
if: env.DEPLOY_CHART == 'true' || env.DEPLOY_MULTICLUSTERSERVICE == 'true'
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.30.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
kind version
- name: Create Kind Cluster config
if: env.DEPLOY_CHART == 'true' || env.DEPLOY_MULTICLUSTERSERVICE == 'true'
run: |
export MASTERS=${{ github.event.inputs.masters || '1' }}
export WORKERS=${{ github.event.inputs.workers || '1' }}
./scripts/create_kind_config.sh
- name: Create Kind Cluster for example Helm chart test
if: env.DEPLOY_CHART == 'true'
run: |
kind create cluster --name test-k8s
kubectl cluster-info --context kind-test-k8s
kind get kubeconfig -n test-k8s > "kcfg_local"
- name: Test - Install example Helm chart
if: env.DEPLOY_CHART == 'true'
run: |
export APP=${{ matrix.folder }}
export TEST_MODE=local
./scripts/deploy_example_chart.sh
- name: Test - Uninstall Helm chart
if: env.DEPLOY_CHART == 'true'
run: |
export APP=${{ matrix.folder }}
export TEST_MODE=local
./scripts/uninstall_example_chart.sh
- name: Test - Install kcm (k0rdent mothership cluster)
if: env.INSTALL_SERVICETEMPLATES == 'true'
run: |
export HELM_VALUES=./scripts/config/min-kcm-values.yaml
./scripts/deploy_k0rdent.sh
kubectl apply -f ./scripts/config/min-kcm-management.yaml
kubectl create ns projectsveltos
./scripts/deploy_k0rdent.sh
- name: Test - Install service template
if: env.INSTALL_SERVICETEMPLATES == 'true'
run: |
export APP=${{ matrix.folder }}
./scripts/install_servicetemplates.sh
- name: Test - Install adopted cluster (k0rdent child)
if: env.DEPLOY_MULTICLUSTERSERVICE == 'true'
run: |
export APP=${{ matrix.folder }}
export TEST_MODE=adopted
./scripts/deploy_cld.sh
- name: Test - Deploy MultiClusterDeployment
if: env.DEPLOY_MULTICLUSTERSERVICE == 'true'
run: |
export APP=${{ matrix.folder }}
export TEST_MODE=adopted
./scripts/deploy_mcs.sh
- name: Test - Uninstall MultiClusterDeployment
if: env.DEPLOY_MULTICLUSTERSERVICE == 'true'
run: |
export APP=${{ matrix.folder }}
export TEST_MODE=adopted
./scripts/remove_mcs.sh