Crates.io | k8s-rs-pb |
lib.rs | k8s-rs-pb |
version | 0.4.0 |
source | src |
created_at | 2024-11-21 18:30:26.564782+00 |
updated_at | 2025-05-17 20:07:06.044089+00 |
description | Bindings from k8s-openapi to rust-protobuf which support application/vnd.kubernetes.protobuf |
homepage | https://github.com/DMoscicki/k8s-rs-pb/ |
repository | https://github.com/DMoscicki/k8s-rs-pb/ |
max_upload_size | |
id | 1456539 |
size | 54,166,332 |
Inspired by k8s-pb
This experimental package aims to bridge the gap between Kubernetes OpenAPI objects and Rust's Protobuf ecosystem. It provides seamless conversion utilities to transform Kubernetes objects from k8s-openapi
(used in kube-rs) into Rust-Protobuf representations, and vice versa.
This tool was born out of necessity for kubesman, where describing each Kubernetes object in JSON for frontend consumption became a cumbersome task. With k8s-rs-pb
, you can generate Protobuf definitions tailored to your specific Kubernetes version, making it easier to work with Kubernetes objects in a type-safe and efficient manner.
The crate supports multiple versions of the Kubernetes API via Cargo features. You can choose which version to use based on your project requirements:
Feature | Description |
---|---|
v1_30 |
Support for Kubernetes API version 1.30 |
v1_31 |
Support for Kubernetes API version 1.31 |
v1_32 |
Support for Kubernetes API version 1.32 |
v1_33 |
Support for Kubernetes API version 1.33 |
earliest |
Enables the oldest supported version (v1_30 ) |
latest |
Enables the latest supported version (v1_33 ) |
To use a specific version, activate the corresponding feature in your Cargo.toml
:
[dependencies]
k8s-rs-pb = { version = "0.4.0", features = ["v1_32"] }
k8s-openapi
and Protobuf formats effortlessly.Unknown
message encapsulation. The KubeAPIServerMessage
trait automatically decodes responses using the k8s protobuf wire format.KUBERNETES_VERSION
variable in the justfile
.k8s-openapi
to Protobufuse k8s_rs_pb::api::core::v1::Pod;
use k8s_openapi::api::core::v1::Pod as OtherPod;
let pod_openapi = OtherPod::default();
let pod_pb: Pod = k8s_rs_pb::converter::from_openapi(pod_openapi).unwrap();
assert_eq!(pod_pb.has_metadata(), true);
k8s-openapi
use k8s_rs_pb::api::core::v1::Pod;
use k8s_openapi::api::core::v1::Pod as OtherPod;
let pod_pb = Pod::default();
let pod_openapi: OtherPod = k8s_rs_pb::converter::to_openapi(pod_pb).unwrap();
use k8s_rs_pb::extension::KubeAPIServerMessage;
use k8s_rs_pb::api::core::v1::Pod;
// Handles the "k8s\x00" magic prefix and Unknown wrapper
let pod = Pod::parse_from_apiserver_bytes(&raw_apiserver_response).unwrap();
To use this package, ensure you have the following tools installed:
find
.If you're working on a project that involves Kubernetes and requires efficient serialization/deserialization of Kubernetes objects, k8s-rs-pb
can significantly streamline your workflow. By leveraging Protobuf, you can achieve faster serialization, smaller payloads, and better compatibility with frontend or cross-language systems.
This project is experimental and open to contributions! If you encounter any issues or have ideas for improvements, feel free to open an issue or submit a pull request. Your feedback is invaluable in shaping the future of this tool.
This project is licensed under the Apache License. See the LICENSE file for details.
Made with ❤️ for Kubernetes enthusiasts and Rustaceans alike!