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

Generated CRD object uses inflected plural form over explicitly specified #480

Closed
nightkr opened this issue Mar 28, 2021 · 4 comments
Closed
Labels
bug Something isn't working derive kube-derive proc_macro related invalid rejected as a valid issue

Comments

@nightkr
Copy link
Member

nightkr commented Mar 28, 2021

Reported on Discord by @Pscheidl

Basically, this struct:

#[derive(CustomResource, Serialize, Deserialize, Debug, PartialEq, Clone, JsonSchema)]
#[kube(
    group = "pavel.cool",
    version = "v1",
    kind = "Echo",
    shortname = "echo",
    plural = "echoes",
    derive = "PartialEq"
)]
struct EchoSpec {
    replicas: i32,
}

Generates this (abridged) CRD:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: echos.pavel.cool
spec:
  group: pavel.cool
  names:
    kind: Echo
    plural: echos
    singular: echo
    shortNames:
      - echo

When it should be:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: echoes.pavel.cool
spec:
  group: pavel.cool
  names:
    kind: Echo
    plural: echoes
    singular: echo
    shortNames:
      - echo
@nightkr nightkr changed the title Generated CRD name uses inflected plural form over explicitly specified Generated CRD uses inflected plural form over explicitly specified Mar 28, 2021
@nightkr nightkr added bug Something isn't working derive kube-derive proc_macro related labels Mar 28, 2021
@nightkr nightkr changed the title Generated CRD uses inflected plural form over explicitly specified Generated CRD object uses inflected plural form over explicitly specified Mar 28, 2021
@clux
Copy link
Member

clux commented Mar 28, 2021

I believe extending our Resource trait with the plural and having kube-derive implement kube::Resource directly, rather than k8s_openapi::Resource will fix this.

That is what #468 wants to do, but it got a little sidelined by the big Resource/Meta restructurings. I'll see if I can get that moving again.

@clux clux linked a pull request Mar 28, 2021 that will close this issue
@clux
Copy link
Member

clux commented Mar 28, 2021

Although, looking at the code, I'm a bit confused of why this is happening as is. The metadata.name is generated from the plural passed in as an attr:

    let crd_meta_name = format!("{}.{}", plural, group);
    let crd_meta = quote! { { "name": #crd_meta_name } };

@clux
Copy link
Member

clux commented Mar 28, 2021

Yeah, setting #[kube(plural = "echoes")] totally does work.

The abridged output of your example is actually:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: echoes.pavel.cool
spec:
  group: pavel.cool
  names:
    kind: Echo
    plural: echoes
    shortNames:
      - echo
    singular: echo
  scope: Cluster

So this is slightly invalid. The point that Pavel brings up is that while the CRD is correct, the url generation does not use that, because that information is not contained in our Meta/Resource trait.

@clux clux added the invalid rejected as a valid issue label Mar 28, 2021
@clux
Copy link
Member

clux commented Mar 28, 2021

Closing in favour of #467

@clux clux closed this as completed Mar 28, 2021
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 invalid rejected as a valid issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants