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

The CustomResourceDefinition "cronjobs.batch.tutorial.kubebuilder.io" is invalid #1544

Closed
zehuaiWANG opened this issue Jun 2, 2020 · 19 comments · Fixed by #1850
Closed

The CustomResourceDefinition "cronjobs.batch.tutorial.kubebuilder.io" is invalid #1544

zehuaiWANG opened this issue Jun 2, 2020 · 19 comments · Fixed by #1850
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Milestone

Comments

@zehuaiWANG
Copy link

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

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Jun 2, 2020
@zehuaiWANG
Copy link
Author

zehuaiWANG commented Jun 2, 2020

/assign @camilamacedo86
Could you help me to have a look with this? Thanks a lot.

@zehuaiWANG
Copy link
Author

If I use kubernentes 1.16, it won't happen. I guess it's a problem after kubernetes 1.18.

@camilamacedo86
Copy link
Member

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

@camilamacedo86
Copy link
Member

/assign @camilamacedo86

@estroz
Copy link
Contributor

estroz commented Jun 23, 2020

This is likely related to kubernetes-sigs/controller-tools#444.

@camilamacedo86
Copy link
Member

camilamacedo86 commented Jun 24, 2020

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.

@izackwu
Copy link

izackwu commented Jul 9, 2020

So how to solve this issue? I encountered exactly the same problem when learning kubebuilder. 😟

@zehuaiWANG
Copy link
Author

@keithnull if you use the minikube, you can change the version of kubernetes to 1.16, and it will not happen.

@izackwu
Copy link

izackwu commented Jul 10, 2020

@zehuaiWANG Thanks, but it's just a work-around. Any way to solve this problem in 1.18?

@zehuaiWANG
Copy link
Author

@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.

@camilamacedo86
Copy link
Member

camilamacedo86 commented Jul 10, 2020

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.

@estroz
Copy link
Contributor

estroz commented Aug 8, 2020

Seems to be fixed by kubernetes-sigs/controller-tools#440

@atomerz
Copy link

atomerz commented Sep 30, 2020

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

@camilamacedo86
Copy link
Member

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.

@dgkanatsios
Copy link

dgkanatsios commented Nov 5, 2020

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!

@estroz
Copy link
Contributor

estroz commented Nov 6, 2020

@zhouxinyu
Copy link

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.

@estroz
Copy link
Contributor

estroz commented Nov 16, 2020

@zhouxinyu see #1544 (comment)

@gabbifish gabbifish added the triage/accepted Indicates an issue or PR is ready to be actively worked on. label Nov 17, 2020
@gabbifish gabbifish self-assigned this Nov 17, 2020
@bilalcaliskan
Copy link

bilalcaliskan commented Nov 29, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
10 participants