This guide explains how to set up your environment for developing Krator.
To build Krator, you will need
- The latest stable version of Rust
- openssl (Or use the
rustls-tls
feature) - git
If you want to test Krator, you will also require
- A Kubernetes cluster.
- kubectl
We use cargo
to build our programs:
$ cargo build
Krator is a library crate, meaning that you cannot run Krator directly, but must import it into other "binary" crates which can then be run. To see an example of using Krator in this way, check out the moose example.
Krator does not configure k8s-openapi
to use a specific version of
Kubernetes. You will need to select a version and enable its feature
when building your application:
[dependencies.k8s-openapi]
version = "0.13"
default-features = false
features = ["v1_22"]
Krator is tested against Kubernetes v1.22.
If you are on a system that doesn't have OpenSSL (or has the incorrect version), you have the option to build Krator using the Rustls project (Rust native TLS implementation):
$ cargo build --no-default-features --features rustls-tls
The same flags can be passed to cargo run
if you want to just run
the project instead.
The underlying dependencies for Rustls do not support certs with IP SANs (subject alternate names). Because of this, the serving certs requested during bootstrap will not work for local development options like minikube or KinD as they do not have an FQDN
You can build Krator on WSL but will need a few prerequisites that aren't included in the Ubuntu distro in the Microsoft Store:
$ sudo apt install build-essential libssl-dev pkg-config
NOTE: We've had mixed success developing Krator on WSL. It has been successfully run on WSL2 using the WSL2-enabled Docker Kubernetes or Azure Kubernetes. If you're on WSL1 you may be better off running in a full Linux VM under Hyper-V.
We have support for building on Windows using PowerShell:
$ cargo build --no-default-features --features rustls-tls
NOTE: Windows builds use the rustls
library, which means there are some
things to be aware of. See the caveats section for more details
The included example with Krator is the moose example.
cargo run --example moose
Krator contains both unit tests and doc tests, and is routinely checked using
clippy
and rustfmt
as well.
For unit tests:
$ cargo test --workspace
For doc tests:
$ cargo test --doc --all
For clippy
:
$ cargo clippy --workspace
For rustfmt
:
cargo fmt --all -- --check
If you want to create your own Operator based on Krator, all you need to do is
implement an Operator
. See the moose example to
see how this is done.