Is there a way to make a resource with no spec or with a different name for the spec? #1762
Unanswered
johnthompson-ybor
asked this question in
Q&A
Replies: 1 comment
-
hey there. the at the moment the workaround is to ask this is not necessarily a huge job. the derive macro - while configurable - does not really generate that much. here's a copy-paste from a previous discord answer: use k8s_openapi::ClusterResourceScope;
use k8s_openapi::Resource;
use kube::{
Api, Client,
api::{ListParams, ObjectMeta},
};
use serde::Deserialize;
#[derive(Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
struct WorkloadPriorityClass {
metadata: ObjectMeta,
value: i32,
}
impl Resource for WorkloadPriorityClass {
const API_VERSION: &'static str = "kueue.x-k8s.io/v1beta1";
const GROUP: &'static str = "kueue.x-k8s.io";
const VERSION: &'static str = "v1beta1";
const KIND: &'static str = "WorkloadPriorityClass";
const URL_PATH_SEGMENT: &'static str = "workloadpriorityclasses";
type Scope = ClusterResourceScope;
}
impl k8s_openapi::Metadata for WorkloadPriorityClass {
type Ty = ObjectMeta;
fn metadata(&self) -> &Self::Ty {
&self.metadata
}
fn metadata_mut(&mut self) -> &mut Self::Ty {
&mut self.metadata
}
}
#[tokio::main]
async fn main() {
let client = Client::try_default()
.await
.expect("Failed to create k8s client");
let workload_priority_class_api = Api::<WorkloadPriorityClass>::all(client);
let lp = ListParams::default();
let workload_priority_classes = workload_priority_class_api.list(&lp).await.unwrap();
println!("{}", workload_priority_classes.items.len());
for workload_priority_class in workload_priority_classes.items {
println!("{:#?}", workload_priority_class);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a crd from another project where I generated the structs with kopium, and while the crd actually includes the "spec" field, it's been deprecated and a webhook blocks anything that includes it...
I can't figure out how to use the derive custom resource macro in such a way that the spec field either doesn't serialize or has a different name -- is that possible? Can you just create the resource type another way without the derive macro?
Beta Was this translation helpful? Give feedback.
All reactions