kube
kube copied to clipboard
Add examples for node cordon and node drain
Is it possible to perform node operations like add labels, drain, cordon, etc. I'm not seeing it in the Api documentation at all.
Add label:
let nodes: Api<Node> = Api::all(client);
nodes
.patch(
"name",
&PatchParams::default(),
&Patch::Merge(serde_json::json!({ "metadata": { "labels": { "app": "example" } } })),
)
.await?;
Cordon should be:
let nodes: Api<Node> = Api::all(client);
nodes
.patch(
"name",
&PatchParams::default(),
&Patch::Merge(serde_json::json!({ "spec": { "unschedulable": true } })),
)
.await?;
Drain should be cordon + evicting all pods in it.
You can use kubectl with --v=9 to find the API requests.
We can probably add convenience methods like in https://github.com/kube-rs/kube-rs/pull/635/files for cordon/uncordon.
Yeah, even in client-go operations like drain and cordon are not among its core verbs. These "operations" are just kubectl helpers: cordon.go + drain.go
I'm ok with having drain + cordon as utility helpers or examples (as a start). We support the eviction subresource (Api::evict) necessary for this. If you would like to try writing a drainer example or a utility fn for Drain then that would be welcome - i'd be happy to help.
#762 now adds Api<Node>::cordon and Api<Node>::uncordon thanks to @ChinYing-Li :tada:
The only thing left here is an example for Api<Node>::drain. As it stands currently herein, this is non-trivial to unit-test / integration test an Api<Node>::drain fn since it probably requires a real node, with real pods, to be created and drained. I think it's OK for this to be done in an example for now. But am open to suggestions. kubectl does have some fairly verbose tests for drain - no idea how fast or sensible these are yet.