kubebuilder: The CustomResourceDefinition "cronjobs.batch.tutorial.kubebuilder.io" is invalid

I followed the tutorial but the cronjob install failed. I clone the master code, but it seems to not work. Could anyone tell me what to do next? Thanks a lot.

[root@test ~/kubebuilder/docs/book/src/cronjob-tutorial/testdata/project]# kubectl version --short
Client Version: v1.18.0
Server Version: v1.19.0-beta.0.318+b618411f1edb98

[root@test ~/kubebuilder/docs/book/src/cronjob-tutorial/testdata/project]# make install
/usr/local/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./api/...;./controllers/..." output:crd:artifacts:config=config/crd/bases
kubectl apply -f config/crd/bases
The CustomResourceDefinition "cronjobs.batch.tutorial.kubebuilder.io" is invalid: 
* spec.validation.openAPIV3Schema.properties[spec].properties[jobTemplate].properties[spec].properties[template].properties[spec].properties[initContainers].items.properties[ports].items.properties[protocol].default: Required value: this property is in x-kubernetes-list-map-keys, so it must have a default or be a required property
* spec.validation.openAPIV3Schema.properties[spec].properties[jobTemplate].properties[spec].properties[template].properties[spec].properties[containers].items.properties[ports].items.properties[protocol].default: Required value: this property is in x-kubernetes-list-map-keys, so it must have a default or be a required property
make: *** [install] Error 1

/kind bug

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 19 (9 by maintainers)

Most upvoted comments

Here is how i solved the issue;

  • In the api/v1/cronjob_webhook.go , add the following 2 options to the // +kubebuilder:webhook:mutating=false and // +kubebuilder:webhook:mutating=true markers;
    admissionReviewVersions=v1,sideEffects=None
    
  • Run make install in the project root directory again and enjoy your newly created CRD.

Hi @keithnull,

The project cronjob-tutorial/testdata/project has not been updated with the changes made in the tool. We need to update this project. You can check the testdadata/ dir where has projects which are updated and verified for each PR.

However, regards the k8s version its has changes we would need to check the error to better assist you. See https://github.com/kubernetes-sigs/kubebuilder/issues/933 and https://github.com/kubernetes-sigs/kubebuilder/issues/1065 which might helps you with.

Also, I’d recommend you use the tool to follow up the steps and build the tutorial example instead of trying to use it. . If you face problems by following this recommendation please raise a new issue with the steps performed and further details for we are able to reproduce and help you with.