Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trait Metadata not implemented for custom spec #1642

Closed
drewstone opened this issue Nov 20, 2024 · 1 comment
Closed

trait Metadata not implemented for custom spec #1642

drewstone opened this issue Nov 20, 2024 · 1 comment

Comments

@drewstone
Copy link

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 Metadata trait. Everything I read online says this derive should generate and implement these traits automatically, but I have had no success debugging manually.

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()
    }
}

Error

error[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`
   |
@clux
Copy link
Member

clux commented Nov 20, 2024

Hey looks mostly sensible. You need to implement your traits on the generated top level type EnvioIndexer rather than EnvioIndexerSpec, 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.

@kube-rs kube-rs locked and limited conversation to collaborators Nov 20, 2024
@clux clux converted this issue into discussion #1643 Nov 20, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants