-
Hello, I'm new to kubernetes and should preface by saying I'm using Claude to help create a system for deploying containers through Kube API. I'm deriving a CustomResource but Rust complains that I'm not implementing the I'm defining my service spec as follows: #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, CustomResource, JsonSchema)]
#[kube(
group = "tangle.tools",
version = "v1",
kind = "EnvioIndexer",
status = "ServiceStatus",
derive = "Default",
namespaced
)]
pub struct EnvioIndexerSpec {
pub spec: EnvioIndexerConfig,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<ServiceStatus>,
} and implementing a trait pub trait ServiceSpec:
Clone
+ Send
+ Sync
+ Resource<Scope = NamespaceResourceScope>
+ DeserializeOwned
+ JsonSchema
+ Debug
+ Serialize
+ 'static
{
fn get_name(&self) -> String;
fn to_deployment_config(&self, namespace: &str) -> DeploymentConfig;
fn status(&self) -> Option<&ServiceStatus>;
fn status_mut(&mut self) -> Option<&mut ServiceStatus>;
} impl ServiceSpec for EnvioIndexerSpec {
fn get_name(&self) -> String {
self.spec.name.clone()
}
fn to_deployment_config(&self, namespace: &str) -> DeploymentConfig {
create_envio_deployment_config(&self.spec, namespace)
}
fn status(&self) -> Option<&ServiceStatus> {
self.status.as_ref()
}
fn status_mut(&mut self) -> Option<&mut ServiceStatus> {
self.status.as_mut()
}
} Errorerror[E0277]: the trait bound `EnvioIndexerSpec: k8s_openapi::Metadata` is not satisfied
--> src/kubernetes/envio.rs:30:22
|
30 | impl ServiceSpec for EnvioIndexerSpec {
| ^^^^^^^^^^^^^^^^ the trait `k8s_openapi::Metadata` is not implemented for `EnvioIndexerSpec`, which is required by `EnvioIndexerSpec: kube::Resource`
| |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey looks mostly sensible. You need to implement your traits on the generated top level type Elaboration; only the top level spec gets the traits generated. The Spec struct is the "user struct", but it's not the one we use for the Kubernetes API (because it does not have explicit metadata and type information). Moving this to discussions. |
Beta Was this translation helpful? Give feedback.
-
Brilliant, saved me a lot of debugging time thank you @clux! I definitely missed the generated top level type existing hah. |
Beta Was this translation helpful? Give feedback.
Hey looks mostly sensible. You need to implement your traits on the generated top level type
EnvioIndexer
rather thanEnvioIndexerSpec
, then you should probably get it working.Elaboration; only the top level spec gets the traits generated. The Spec struct is the "user struct", but it's not the one we use for the Kubernetes API (because it does not have explicit metadata and type information).
Moving this to discussions.