Skip to main content
Version: 3.4

GitHub Actions

Loft provides the following GitHub Actions for use in workflows:

Spaces Too!

Check out the Spaces Integration section for examples of using the Space create/delete GitHub Actions plugins.

Virtual Clusters for Pull Requests

These examples show how to create and delete Virtual Clusters for pull requests.

This example shows how to create and delete a virtual cluster for testing an application named my-app on pull requests.

# .github/workflows/vclusters.yaml
name: Pull Request Checks
on:
pull_request:
branches:
- 'main'
jobs:
e2e:
runs-on: ubuntu-latest
steps:
- name: Install Loft CLI
uses: loft-sh/setup-loft@main
with:
url: ${{ secrets.LOFT_URL }}
access-key: ${{ secrets.LOFT_ACCESS_KEY }}
- name: Create Virtual Cluster for PR
uses: loft-sh/create-vcluster@main
with:
name: pr-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ github.run_id }}
- name: Deploy Application
run: kubectl apply -Rf ./kubernetes
- name: Wait for Deployment
run: kubectl rollout status deployments/my-app
- name: Run Tests
run: make e2e
- name: Delete PR Virtual Cluster
uses: loft-sh/delete-vcluster@main
with:
name: pr-${{ github.event.pull_request.number }}-${{ github.sha }}-${{ github.run_id }}

Explanation:

  1. The Setup Loft action is used to install the Loft CLI and login using the provided url and access-key.
  2. The Create Virtual Cluster action is used to create a unique virtual cluster using information about the pull request. This will automatically configure the kube context for the following steps.
  3. The next step deploys the application using the runner provided kubectl and manifests located under ./kubernetes.
  4. Before running tests, we use kubectl to wait for the my-app deployment to become ready.
  5. Now we run the end-to-end tests. In this example we're using make to run tests, but the command should be customized for your testing framework.
  6. Finally, the Delete Virtual Cluster GitHub Action is used to delete the virtual cluster.