This project uses kubevirtci for development and e2e testing with real KubeVirt VirtualMachines.
- Native KubeVirt Support: Comes with KubeVirt pre-installed and configured
- Real VM Testing: Test webhook RBAC validation with actual VirtualMachine resources
- Realistic Environment: Same environment as KubeVirt users
- Nested Virtualization: Handles complexity of running VMs in tests
- Docker (recommended) or Podman for running containers
- Docker is preferred for running the cluster (runs as root, better /dev/kvm access)
- Podman can be used for building/pushing images
- Git (for cloning kubevirtci)
- Make
Note: If using both Docker and Podman, the scripts automatically use Docker for cluster operations and Podman for image building. This is optimal for hardware virtualization support.
make cluster-upThis will:
- Clone kubevirtci (if not already present in
_kubevirtci/) - Start a Kubernetes cluster (kind-1.34) with KubeVirt pre-installed
- Export KUBECONFIG for the cluster
make cluster-syncThis will:
- Build the webhook container image
- Load it into the kubevirtci cluster
- Install cert-manager (if needed)
- Deploy the webhook with all ClusterRoles
- Wait for webhook to be ready
make cluster-functestThis will run comprehensive e2e tests including:
- Full-admin permission tests
- Storage-admin permission tests (volumes, disks, filesystems)
- CD-ROM user permission tests (media swap only)
- Network-admin permission tests
- Compute-admin permission tests (CPU, memory)
- Lifecycle-admin permission tests (start/stop)
- Devices-admin permission tests (GPUs, host devices)
- Backwards compatibility tests
- Combined permissions tests
make cluster-downmake cluster-cleanThis removes the kubevirtci directory and all cached data.
Typical development cycle:
# Start cluster (once)
make cluster-up
# Make code changes, then sync and test
make cluster-sync
make cluster-functest
# Or combine: sync + test
make cluster-sync && make cluster-functest
# When done
make cluster-downConfiguration is managed in hack/config.sh:
IMAGE_REGISTRY: Container registry (default:localhost:5000)IMAGE_NAME: Image name (default:kubevirt-rbac-webhook)IMAGE_TAG: Image tag (default:devel)KUBEVIRT_PROVIDER: Kubernetes version (default:kind-1.34)KUBEVIRTCI_VERSION: kubevirtci version/tag (default:2510141807-f21813f1)
After running make cluster-up, kubectl.sh works automatically:
_kubevirtci/cluster-up/kubectl.sh get nodes
_kubevirtci/cluster-up/kubectl.sh get vms -A
_kubevirtci/cluster-up/kubectl.sh get pods -n kubevirtHow it works:
- During
make cluster-up, the installation appendsexport KUBEVIRTCI_TAG=<version>to kubevirtci'scluster-up/hack/common.sh - kubectl.sh automatically sources that file, so all required environment variables are set
export KUBECONFIG=$(pwd)/_kubevirtci/_ci-configs/kind-1.34/.kubeconfig
kubectl get nodes
kubectl get vms -AHelper scripts source hack/config.sh and use the kubevirtci::kubectl function:
#!/usr/bin/env bash
source hack/common.sh
source hack/config.sh
kubevirtci::kubectl get nodeskubectl get pods -n kubevirt-rbac-webhook-system
kubectl logs -n kubevirt-rbac-webhook-system -l control-plane=controller-managerkubectl get pods -n kubevirt
kubectl get virt -n kubevirt# Restart cluster
make cluster-down
make cluster-up
make cluster-syncmake cluster-clean
make cluster-up
make cluster-syncThe GitHub Actions workflow (.github/workflows/test-e2e.yml) automatically:
- Sets up kubevirtci cluster
- Builds and deploys webhook
- Runs all e2e tests
- Collects logs on failure
- Cleans up cluster
The kubevirtci integration consists of:
common.sh: Core kubevirtci functions (up, down, load image, etc.)config.sh: Configuration variablescluster-up.sh: Start clustercluster-down.sh: Stop clustercluster-sync.sh: Build and deploycluster-functest.sh: Run e2e tests
- VM creation helpers (
CreateTestVM,CreateVMWithCDRom) - RBAC helpers (
CreateServiceAccount,CreateRoleBinding) - Impersonation helpers (
KubectlAs,PatchResourceAs)
webhook_rbac_test.go: Comprehensive RBAC validation testse2e_suite_test.go: Test suite setup (supports both kind and kubevirtci)e2e_test.go: Infrastructure tests (deployment, metrics, certificates)
| Feature | kind | kubevirtci |
|---|---|---|
| KubeVirt | Manual install | Pre-installed |
| VirtualMachine CRDs | Manual install | Pre-installed |
| Nested VMs | Not supported | Supported |
| Setup time | Fast (~1 min) | Slower (~3-5 min) |
| Resource usage | Light | Heavier |
| Test realism | Basic | Production-like |
- Keep cluster running during development - Start once, sync many times
- Use
cluster-syncafter code changes - Rebuilds and redeploys - Run
cluster-functestfrequently - Fast feedback on changes - Clean up when switching branches -
make cluster-clean && make cluster-up - Check webhook logs when debugging -
kubectl logs -n kubevirt-rbac-webhook-system ...
The test suite supports these environment variables:
USE_KUBEVIRTCI=true: Use kubevirtci mode in testsPROJECT_IMAGE: Override webhook image (set bycluster-functest)KUBECONFIG: Path to cluster kubeconfig (set by kubevirtci)