ynqa / kubernetes-rust Goto Github PK
View Code? Open in Web Editor NEWRust client for Kubernetes
License: Apache License 2.0
Rust client for Kubernetes
License: Apache License 2.0
The API for CRDs is generated by kube as soon as the CRD is posted. Thus these structs are not normally available in the openapi bindings or something else (the crd might not even have a schema in older versions of kube). This is usually not a problem, because if you're using rust, you might have a more precise struct for this anyway, but it would be nice to have an API wrapper for this call somehow maybe?
The go toolchain does some awkward codegeneration that they force people to do more-or-less manually, but that shouldn't be necessary when you have serde and rust on your side. Still, not sure what's the best way to tackle this.
Currently, am just calling the api the easy way:
https://github.com/Babylonpartners/shipcat/blob/8e1fd9c1e0bfef1a9f642f9d7d64b1b938f00ae2/raftcat/src/kube.rs#L13-L19
(and thus avoiding the openapi bindings entirely because that's all i need atm)
but wondered if you/someone had thoughts on this.
Running the example code:
#[test]
fn test_general() {
let kubeconfig = config::load_kube_config().expect("failed to load kubeconfig");
let kubeclient = APIClient::new(kubeconfig);
let (req, _) = api::Pod::list_namespaced_pod("kube-system", Default::default())
.expect("failed to create a request");
let list_pod = kubeclient
.request::<api::PodList>(req)
.expect("failed to list up pods");
println!("{:?}", list_pod);
}
---- test::test_general stdout ----
thread 'test::test_general' panicked at 'failed to list up pods: Error(Hyper(Error(Connect, Custom { kind: Other, error: Error { code: -67843, message: "The certificate was not trusted." } })), "https://<uuid>.k8s.ondigitalocean.com/api/v1/namespaces/kube-system/pods?")', src/main.rs:76:24
failures:
test::test_general
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
Watch API returns non-json as json:
GET /api/v1/namespaces/test/pods?watch=1&resourceVersion=10245
---
200 OK
Transfer-Encoding: chunked
Content-Type: application/json
{
"type": "ADDED",
"object": {"kind": "Pod", "apiVersion": "v1", "metadata": {"resourceVersion": "10596", ...}, ...}
}
{
"type": "MODIFIED",
"object": {"kind": "Pod", "apiVersion": "v1", "metadata": {"resourceVersion": "11020", ...}, ...}
}
Maybe it's possible to parse each chunk as json? Maybe this needs a custom deserializer?
Just making a note of this. Not sure how to parse this yet.
One thing I noticed is that data returned from the kube api is assumed to be parseable into the struct you give it:
kubernetes-rust/src/client/mod.rs
Line 37 in 9c5f29f
however, we have no real information on what went wrong if kube returns an error struct. We simply get a json parsing failed (usually "unexpected EOF" via serde) because the string is attempted to be coerced into a different struct to the one that contains the error.
This happens if you query for information about your own custom resources and you've failed to add the necessary rbac rules for it, but i'm sure there are many other cases.
There's currently got a fork to help me deal with this issue in my account (and to get some debug back when it's failed for now). I might be looking to submit a pr back if I stumble across a good solution to it. In the mean time, just thought this ought to be raised.
At any rate, thanks for this crate! It's allowed me to write a kube app with rust with only minor tweaks!
Currently there doesn't appear to be a websocket implementation for connect_core_v1_get_namespaced_pod_exec
. It would be great to have one. The python k8s client has an implementation here. The ws
crate could be used for the implementation. Thanks!
Enable to apply config in k8s cluster. Ref, https://github.com/kubernetes-client/go-base/blob/master/config/incluster_config.go
Hey there.
Package names (Cargo.toml) should never contain "-rust" or "_rust".
They are totally redundant and pretty annoying for users.
Add bearer token or basic auth as default header. Ref, https://github.com/kubernetes-client/go-base/blob/master/config/authentication.go
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.