Skip to content
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

CustomResource derive injects empty defaults for unset fields #1680

Open
clux opened this issue Jan 23, 2025 · 1 comment
Open

CustomResource derive injects empty defaults for unset fields #1680

clux opened this issue Jan 23, 2025 · 1 comment
Labels
bug Something isn't working derive kube-derive proc_macro related help wanted Not immediately prioritised, please help!

Comments

@clux
Copy link
Member

clux commented Jan 23, 2025

Current and expected behavior

A kube derived CRD spec using say;

#[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)]
#[kube(kind = "Document", group = "kube.rs", version = "v1", namespaced)]
#[kube(status = "DocumentStatus")]
pub struct DocumentSpec {
    pub title: String,
}

injects the following .spec properties (outside the schema):

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: documents.kube.rs
spec:
  group: kube.rs
  names:
    categories: []
    kind: Document
    plural: documents
    shortNames: []
    singular: document
  scope: Namespaced
  versions:
  - additionalPrinterColumns: []
    name: v1
    schema: BIGBLOB_NOT_RELEVANT_HERE

in particular
.spec.names.categories and .spec.names.shortNames and .spec.versions[].additionalPrinterColumn are set even without us explicitly setting the corresponding kube attributes for printcolumn, shortname, nor category.

This is a violation of the spec for CRDs;

Possible solution

Only emit these vectors when they are non-empty. If there are no values in our internal code we have never called any of the attributes and so they should be treated as unset rather than explicit empty.

Additional context

See #1678

Affected crates

kube-derive

Would you like to work on fixing this bug?

maybe

@clux clux added bug Something isn't working help wanted Not immediately prioritised, please help! labels Jan 23, 2025
@clux
Copy link
Member Author

clux commented Jan 23, 2025

A solution here is probably something along the lines of what we do already for selectable fields, inject the surrounding key only if it's non-empty:

let selectable = if !selectable.is_empty() {
quote! { "selectableFields": fields, }
} else {
quote! {}
};

But also probably needs some improvement in the ::crd fn:

let categories: Vec<String> = #serde_json::from_str(#categories_json).expect("valid categories");
let shorts : Vec<String> = #serde_json::from_str(#short_json).expect("valid shortnames");

@clux clux added the derive kube-derive proc_macro related label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working derive kube-derive proc_macro related help wanted Not immediately prioritised, please help!
Projects
None yet
Development

No branches or pull requests

1 participant