envtest
A lightweight, type‑safe wrapper around the Kubernetes envtest Go package that lets you spin up a temporary control plane from Rust.
envtest aims to make integration testing with real Kubernetes components straightforward. This project is based on the envtest Go package, but provides a Rust interface for the library usage.
Table of Contents
Features
- Create an isolated test environment with a fully‑working control plane.
- Destroy the environment automatically when the
Serverinstance is dropped. - Retrieve the kubeconfig as a strongly‑typed
kube::config::Kubeconfig. - Pre‑install user CRDs from in‑memory definitions.
Getting Started
Installation
Add envtest to your Cargo.toml:
[]
= "0.1"
Note:
rust2gorequires a working Go toolchain andclangfor the bindgen step.
Make sure that Go (GO111MODULE=on) is available on your PATH.
Basic Usage
use Environment;
Customizing the Environment
You can tweak binary download behavior through binary_assets_settings:
| Field | Purpose |
|---|---|
crd_install_options.paths |
Paths to directories or files with CRDs. |
crd_install_options.crds |
In‑memory CRDs to install. |
crd_install_options.error_if_path_missing |
Fail if a a CRD path is missing. |
binary_assets_settings.download_binary_assets |
false → use binaries from $KUBEBUILDER_ASSETS. |
binary_assets_settings.binary_assets_directory |
Cache directory for downloaded binaries. |
binary_assets_settings.download_binary_assets_version |
Specific envtest version to download. |
binary_assets_settings.download_binary_assets_index_url |
URL pointing to the envtest release index. |
use Environment;
Using with_crds
use Environment;
Explicit Cleanup
The Server implements Drop, but you can destroy it manually:
let server = env.create?;
server.destroy?;
Usage in testing
envtest is most useful in combination with the kube feature (enabled by default), which provides a strongly typed API client for interacting with the Kubernetes API.
use Environment;
use ;
use Namespace;
async
For test suites, prefer one Environment per test to avoid shared state between cases.
Building the Bindings
envtest generates Go bindings at compile time via rust2go. The build process relies on:
rust2go(which usesbindgenunder the hood)- A working Go toolchain (
GO111MODULE=on) clang(for bindgen)
Refer to the bindgen requirements for more details.
License
MIT license – see the LICENSE file for details.