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

Empty "Items" object for array in generated v1 CRD is invalid #477

Closed
grdryn opened this issue Aug 24, 2020 · 4 comments
Closed

Empty "Items" object for array in generated v1 CRD is invalid #477

grdryn opened this issue Aug 24, 2020 · 4 comments

Comments

@grdryn
Copy link

grdryn commented Aug 24, 2020

We've got a CRD generated by controller-gen that gets an empty Items object for a list/array in the yaml output. Given that this is a v1 CRD, this results in the CRD not being applicable to a cluster (k8s 1.16+ at least, it seems). It doesn't seem possible to add any markers to influence this, so I'm currently working around it by changing it after generation to have type: object.

Also, I'm not sure if it's related (might be why items is empty?), is that this type is recursive: a Route instance can have a Routes field, which is a []Route.

Here's the type definition that the offending CRD is generated from, and here's how it's generated.

This might be related to the discussion in #342 where @sttts and @DirectXMan12 talk about possibly having :items: markers, but I'm not sure. Maybe at a minimum it should by default be able to add the required type: object for this case (without needing a marker)?

@Wenfeng-GAO
Copy link

I meet the same problem, it seems that it doesn't work well for recursive struct definition.

When I apply generated crd to k8s, it prints out

The CustomResourceDefinition "daemonsets.kube-manager.karrier.io" is invalid: spec.validation.openAPIV3Schema.properties[spec].properties[updateStrategy].properties[priorityStrategy].properties[orderPriority].items.properties[orderPriority].items.type: Required value: must not be empty for specified array items

And my struct is recursive list as well:

type PriorityStrategy struct {
	OrderPriority []OrderPriorityItem `json:"orderPriority,omitempty"`
}

type OrderPriorityItem struct {
	Selector      metav1.LabelSelector `json:"selector,omitempty"`
	OrderPriority []OrderPriorityItem  `json:"orderPriority,omitempty"`
}

generated crd is :

                  priorityStrategy:
                    properties:
                      orderPriority:
                        items:
                          properties:
                            orderPriority:
                              items: {}
                              type: array
                            selector:

@DirectXMan12
Copy link
Contributor

DirectXMan12 commented Sep 9, 2020

Ah. This... could be a clearer error message.

There's no way to have a CRD with recursive types right now, because that would require references, and SIG API Machinery has thus far been reluctant to support references in CRDs.

Specifically, Route --> Routes --> []Route is the recursive issue here.

@DirectXMan12
Copy link
Contributor

I'm going to close this out and file a bug for erroring on recursive types. Feel free to comment there if you have more input

@grdryn
Copy link
Author

grdryn commented Sep 13, 2020

Thanks @DirectXMan12! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants