kube-rs / kopium

Kubernetes OPenapI UnMangler
Apache License 2.0
112 stars 21 forks source link

Status attribute not created #272

Open pando85 opened 5 hours ago

pando85 commented 5 hours ago

Hello,

first of all, thanks for this great work I love this crate.

CRD

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: echoes.example.com
spec:
  group: example.com
  names:
    kind: Echo
    plural: echoes
    singular: echo
    shortNames:
      - echo
  scope: Namespaced
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          required:
            - metadata
            - spec
          properties:
            apiVersion:
              description: |-
                APIVersion defines the versioned schema of this representation of an object.
                Servers should convert recognized schemas to the latest internal value, and
                may reject unrecognized values.
                More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
              type: string
            kind:
              description: |-
                Kind is a string value representing the REST resource this object represents.
                Servers may infer this from the endpoint the client submits requests to.
                Cannot be updated.
                In CamelCase.
                More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
              type: string
            metadata:
              type: object
            spec:
              type: object
              required:
                - replicas
              properties:
                replicas:
                  type: integer
                  format: int32
            status:
              type: object
              properties:
                availableReplicas:
                  type: integer
                  description: "The number of available replicas."

Expected

// WARNING: generated by kopium - manual changes will be overwritten
// kopium command: kopium -f charts/echoer/crds/crd-echo.yaml
// kopium version: 0.21.1

#[allow(unused_imports)]
mod prelude {
    pub use kube::CustomResource;
    pub use serde::{Serialize, Deserialize};
    pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition;
}
use self::prelude::*;

#[derive(CustomResource, Serialize, Deserialize, Clone, Debug)]
#[kube(group = "example.com", version = "v1", kind = "Echo", plural = "echoes")]
#[kube(namespaced)]
#[kube(schema = "disabled")]
#[kube(status = "EchoStatus")]
pub struct EchoSpec {
    pub replicas: i32,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct EchoStatus {
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "availableReplicas")]
    pub available_replicas: Option<i64>,
}

Result

// WARNING: generated by kopium - manual changes will be overwritten
// kopium command: kopium -f charts/echoer/crds/crd-echo.yaml
// kopium version: 0.21.1

#[allow(unused_imports)]
mod prelude {
    pub use kube::CustomResource;
    pub use serde::{Serialize, Deserialize};
    pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition;
}
use self::prelude::*;

#[derive(CustomResource, Serialize, Deserialize, Clone, Debug)]
#[kube(group = "example.com", version = "v1", kind = "Echo", plural = "echoes")]
#[kube(namespaced)]
#[kube(schema = "disabled")]
#[kube(status = "EchoStatus")]
pub struct EchoSpec {
    pub replicas: i32,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct EchoStatus {
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "availableReplicas")]
    pub available_replicas: Option<i64>,
}

Summary

Attribute #[kube(status = "EchoStatus")] is missed. I don't know if I'm missing something but that would be the CRD that I would expect.

Thanks,

clux commented 5 hours ago

Strange, we do intend to add that attribute if we find it:

https://github.com/kube-rs/kopium/blob/61ea7b49c82cd4d65e8dc136a78339bc7ece1ea5/src/main.rs#L273-L277

does the crd list the subresource on crd.spec.versions ? The status subresource must be listed in the subresource declaration in the schema