I have Context
objects - essentially a join record between a Cluster
and a User
- in a kubernetes config yaml ( ~/.kube/config ) i'd like to parse in to a struct that looks something like this:
struct Context {
name: String,
cluster: Cluster,
user: User
}
struct Cluster {
server: String
// ..
}
struct User {
name: String,
// ..
}
the yaml itself encodes these in to separate arrays, e.g.:
contexts:
- name: some_context
context:
cluster: some_cluster
user: some_user
clusters:
- name: some_cluster
cluster:
// many other, important fields ..
users:
- name: some_user
user:
// many other, important fields ..
i have no idea where to even begin with this - it seems as though i will need to have access to an interim representation of the document before i could "look ahead" to parse some of the complex structures in other parts of the document in to these structs external to Context
I've found the go-to kubernetes client crate is parsing this exact file, but it shies away from doing this and just provides the "raw" string keys
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Context {
pub cluster: String, // ideally cluster: Cluster
pub user: String, // ideally user: User
pub namespace: Option<String>,
pub extensions: Option<Vec<NamedExtension>>,
}
( comments in above snippet by me )
is there an example for how to do this serde?