| Crates.io | envtest |
| lib.rs | envtest |
| version | 0.0.1 |
| created_at | 2025-09-21 08:41:11.635442+00 |
| updated_at | 2025-09-21 08:41:11.635442+00 |
| description | A lightweight, type‑safe wrapper around the Kubernetes `envtest` Go package that lets you spin up a temporary control plane from Rust. |
| homepage | |
| repository | https://github.com/kube-rs/envtest |
| max_upload_size | |
| id | 1848617 |
| size | 75,459 |
A lightweight, type‑safe wrapper around the Kubernetes
envtestGo 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.
Server instance is dropped.kube::config::Kubeconfig.Add envtest to your Cargo.toml:
[dependencies]
envtest = "0.1"
kube = { version = "1" }
Note:
rust2gorequires a working Go toolchain andclangfor the bindgen step.
Make sure that Go (GO111MODULE=on) is available on your PATH.
use envtest::Environment;
use kube::{Client, config::Kubeconfig};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. Build the default environment (latest envtest binaries)
let env = Environment::default();
// 2. Spin up a temporary control plane
let server = env.create()?;
// 3. Retrieve a strongly‑typed kubeconfig
let kubeconfig: Kubeconfig = server.kubeconfig()?;
// 4. Create a `kube` client
let client = Client::try_from(kubeconfig)?;
// 5. `server` is dropped at the end of scope, cleaning up the control plane
Ok(())
}
Environment exposes two nested structs:
| 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. |
with_crdsuse envtest::{Environment, BinaryAssetsSettings};
use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let env = Environment::default()
.with_crds(vec![CustomResourceDefinition::default()])?;
let server = env.create()?;
Ok(())
}
The Server implements Drop, but you can destroy it manually:
let server = env.create()?;
server.destroy()?;
envtest generates Go bindings at compile time via rust2go. The build process relies on:
rust2go (which uses bindgen under the hood)GO111MODULE=on)clang (for bindgen)Refer to the bindgen requirements for more details.
MIT license – see the LICENSE file for details.