The CustomResourceDefinition "cronjobs.batch.tutorial.kubebuilder.io" is invalid
zehuaiWANG opened this issue · 19 comments
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
/assign @camilamacedo86
Could you help me to have a look with this? Thanks a lot.
If I use kubernentes 1.16, it won't happen. I guess it's a problem after kubernetes 1.18.
Hi @zehuaiWANG,
The /kubebuilder/docs/book/src/cronjob-tutorial/testdata/project
is outdated. I have been working on a PR to update that. See: #1492
/assign @camilamacedo86
This is likely related to kubernetes-sigs/controller-tools#444.
Hi @estroz,
See that the user is trying to check the example code in the repo:
[root@test ~/kubebuilder/docs/book/src/cronjob-tutorial/testdata/project]# kubectl version --short
The project cronjob-tutorial/testdata/project
which is used to do the doc is a scaffold project. However, it is NOT updated when we run the golden script. It is very outdated. So, we need to update the scaffolded project cronjob-tutorial/testdata/project
to the latest versions of the projects gen with the tool and then, I believe that it will be solved as well.
So how to solve this issue? I encountered exactly the same problem when learning kubebuilder. 😟
@keithnull if you use the minikube, you can change the version of kubernetes to 1.16, and it will not happen.
@zehuaiWANG Thanks, but it's just a work-around. Any way to solve this problem in 1.18?
@keithnull I haven't found a good way to solve this problem in kubernetes 1.18, this seems to be caused by a field validation introduced by kubernetes 1.18.
maybe @camilamacedo86 will know more details, you can ask her for help.
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 #933 and #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.
Seems to be fixed by kubernetes-sigs/controller-tools#440
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 #933 and #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.
I started out with building the project by following the instructions on the tutorial and I got the error. Then I tried cloning the project and still see the same error.
I'm using
$ kubectl version --short
Client Version: v1.19.0
Server Version: v1.19.1
The issue still:
$ make install
/Users/camilamacedo/go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/Users/camilamacedo/go/bin/kustomize build config/crd | kubectl apply -f -
The CustomResourceDefinition "cronjobs.batch.tutorial.kubebuilder.io" is invalid:
* 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
* 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
make: *** [Makefile:33: install] Error 1
As @estroz described it shows to be related to kubernetes-sigs/controller-tools#444 and after we get merged the changes in the PR #1644 and update the examples in the docs/book/src/
it might be solved.
Any workaround till latest controller-tools is merged?
For context, I'm having a CRD with a field of corev1.PodSpec
and I'm getting
The CustomResourceDefinition "testcrd.example.com" is invalid:
* spec.validation.openAPIV3Schema.properties[spec].properties[podSpec].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[podSpec].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
thanks!
Do we have any solution about this issue? My CRD contains a field of PodTemplateSpec also can't be installed into a 1.18 k8s cluster.
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.