All Projects → clux → Kube Rs

clux / Kube Rs

Licence: apache-2.0
kubernetes rust client and futures controller runtime

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Kube Rs

AMLeaksFinder
A small tool for automatically detecting the [controller, view memory leak] in the project. 一款用于自动检测项目中【控制器内存泄漏,View 内存泄漏】的小工具,支持 ObjC,Swift。
Stars: ✭ 89 (-85.48%)
Mutual labels:  runtime, controller
Sysbox
Sysbox repository
Stars: ✭ 596 (-2.77%)
Mutual labels:  runtime
Vercel Php
▲ Vercel PHP runtime • vercel-php • now-php • 🐘+ λ = ❤
Stars: ✭ 429 (-30.02%)
Mutual labels:  runtime
Dart native
Write iOS&Android Code using Dart. This package liberates you from redundant glue code and low performance of Flutter Channel.
Stars: ✭ 564 (-7.99%)
Mutual labels:  runtime
Open Stage Control
Libre and modular OSC / MIDI controller
Stars: ✭ 436 (-28.87%)
Mutual labels:  controller
Jetpack Musicplayer
即使不用云音乐听曲儿,也请务必收藏好该库!🔥 一行代码即可接入,音乐播放控制组件 - Even if you don't listen to the music by Spotify, be sure to collect this library, please! 🔥 This music player component can be accessed by only one line of code. Supporting by LiveData & AndroidX.
Stars: ✭ 577 (-5.87%)
Mutual labels:  controller
Actix Net
A collection of lower-level libraries for composable network services.
Stars: ✭ 415 (-32.3%)
Mutual labels:  runtime
Sys Con
Nintendo Switch sysmodule that allows support for third-party controllers
Stars: ✭ 603 (-1.63%)
Mutual labels:  controller
Reflection
DEPRECATED
Stars: ✭ 592 (-3.43%)
Mutual labels:  runtime
Wasmtime
Standalone JIT-style runtime for WebAssembly, using Cranelift
Stars: ✭ 6,413 (+946.17%)
Mutual labels:  runtime
Erlangrt
Erlang Replacement Therapy. Another attempt to make Erlang runtime (BEAM emulator) in Rust. Good news: I know what to do. Bad news: I have no clue how to Rust
Stars: ✭ 531 (-13.38%)
Mutual labels:  runtime
Io Ts
Runtime type system for IO decoding/encoding
Stars: ✭ 5,086 (+729.69%)
Mutual labels:  runtime
Pl Compiler Resource
程序语言与编译技术相关资料(持续更新中)
Stars: ✭ 578 (-5.71%)
Mutual labels:  runtime
Telegram Bot
Ruby gem for building Telegram Bot with optional Rails integration
Stars: ✭ 433 (-29.36%)
Mutual labels:  controller
Typescript Is
Stars: ✭ 595 (-2.94%)
Mutual labels:  runtime
Ph7
An Embedded Implementation of PHP (C Library)
Stars: ✭ 422 (-31.16%)
Mutual labels:  runtime
Go Runtime Metrics
Collect Golang Runtime Metrics, outputting to a stats handler
Stars: ✭ 501 (-18.27%)
Mutual labels:  runtime
Unswitch
🕹 A tiny event handler for Switch controllers!
Stars: ✭ 574 (-6.36%)
Mutual labels:  controller
Druntime
Low level runtime library for the D programming language
Stars: ✭ 608 (-0.82%)
Mutual labels:  runtime
Unifi Api Client
A PHP API client class to interact with Ubiquiti's UniFi Controller API
Stars: ✭ 602 (-1.79%)
Mutual labels:  controller

kube-rs

CircleCI Client Capabilities Client Support Level Crates.io Discord chat

Rust client for Kubernetes in the style of a more generic client-go, a runtime abstraction inspired by controller-runtime, and a derive macro for CRDs inspired by kubebuilder.

These crates makes certain assumptions about the kubernetes apimachinery + api concepts to enable generic abstractions. These abstractions allow rust reinterpretations of reflectors, informers, controllers, and custom resource interfaces, so that you can write applications easily.

Installation

Select a version of kube along with the generated k8s-openapi types corresponding for your cluster version:

[dependencies]
kube = "0.51.0"
kube-runtime = "0.51.0"
k8s-openapi = { version = "0.11.0", default-features = false, features = ["v1_20"] }

Features are available.

We recommend turning off default-features for k8s-openapi to speed up your compilation.

Upgrading

Please check the CHANGELOG when upgrading.

Usage

See the examples directory for how to use any of these crates.

Some real world examples:

  • version-rs: super lightweight reflector deployment with actix 2 and prometheus metrics

  • controller-rs: Controller owned by a Manager inside actix

  • krustlet: a complete WASM running kubelet

Api

The direct Api type takes a client, and is constructed with either the ::global or ::namespaced functions:

use k8s_openapi::api::core::v1::Pod;
let pods: Api<Pod> = Api::namespaced(client, "default");

let p = pods.get("blog").await?;
println!("Got blog pod with containers: {:?}", p.spec.unwrap().containers);

let patch = json!({"spec": {
    "activeDeadlineSeconds": 5
}});
let patched = pods.patch("blog", &pp, serde_json::to_vec(&patch)?).await?;
assert_eq!(patched.spec.active_deadline_seconds, Some(5));

pods.delete("blog", &DeleteParams::default()).await?;

See the examples ending in _api examples for more detail.

Custom Resource Definitions

Working with custom resources uses automatic code-generation via proc_macros in kube-derive.

You need to #[derive(CustomResource)] and some #[kube(attrs..)] on a spec struct:

#[derive(CustomResource, Serialize, Deserialize, Default, Clone)]
#[kube(group = "clux.dev", version = "v1", kind = "Foo", namespaced)]
pub struct FooSpec {
    name: String,
    info: String,
}

Then you can use the generated wrapper struct Foo:

assert_eq!("Foo", Foo::KIND); // impl k8s_openapi::Resource for Foo
let foos: Api<Foo> = Api::namespaced(client, "default");
let f = Foo::new("my-foo");
println!("foo: {:?}", f)
println!("crd: {}", serde_yaml::to_string(Foo::crd());

There are a ton of kubebuilder like instructions that you can annotate with here. See the documentation or the crd_ prefixed examples for more.

NB: #[derive(CustomResource)] requires the derive feature enabled on kube.

Runtime

The kube_runtime crate contains sets of higher level abstractions on top of the Api and Resource types so that you don't have to do all the watch/resourceVersion/storage book-keeping yourself.

Watchers

A low level streaming interface (similar to informers) that presents Applied, Deleted or Restarted events.

let api = Api::<Pod>::namespaced(client, "default");
let watcher = watcher(api, ListParams::default());

This now gives a continual stream of events and you do not need to care about the watch having to restart, or connections dropping.

let apply_events = try_flatten_applied(watcher).boxed_local()
while let Some(event) = watcher.try_next().await? {
    println!("Applied: {}", Meta::name(&event));
}

NB: the plain stream items a watcher returns are different from WatchEvent. If you are following along to "see what changed", you should flatten it with one of the utilities like try_flatten_applied or try_flatten_touched.

Reflectors

A reflector is a watcher with Store on K. It acts on all the Event<K> exposed by watcher to ensure that the state in the Store is as accurate as possible.

let nodes: Api<Node> = Api::namespaced(client, &namespace);
let lp = ListParams::default()
    .labels("beta.kubernetes.io/instance-type=m4.2xlarge");
let store = reflector::store::Writer::<Node>::default();
let reader = store.as_reader();
let rf = reflector(store, watcher(nodes, lp));

At this point you can listen to the reflector as if it was a watcher, but you can also query the reader at any point.

Controllers

A Controller is a reflector along with an arbitrary number of watchers that schedule events internally to send events through a reconciler:

Controller::new(root_kind_api, ListParams::default())
    .owns(child_kind_api, ListParams::default())
    .run(reconcile, error_policy, context)
    .for_each(|res| async move {
        match res {
            Ok(o) => info!("reconciled {:?}", o),
            Err(e) => warn!("reconcile failed: {}", Report::from(e)),
        }
    })
    .await;

Here reconcile and error_policy refer to functions you define. The first will be called when the root or child elements change, and the second when the reconciler returns an Err.

Rustls

Kube has basic support (with caveats) for rustls as a replacement for the openssl dependency. To use this, turn off default features, and enable rustls-tls:

[dependencies]
kube = { version = "0.51.0", default-features = false, features = ["rustls-tls"] }
kube-runtime = { version = "0.51.0", default-features = false, features = ["rustls-tls"] }
k8s-openapi = { version = "0.11.0", default-features = false, features = ["v1_20"] }

This will pull in the variant of reqwest that also uses its rustls-tls feature.

musl-libc

Kube will work with distroless, scratch, and alpine (it's also possible to use alpine as a builder with some caveats).

License

Apache 2.0 licensed. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].