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

🐛 Fix validation errors happening in v1.18 #440

Closed

Conversation

dgrisonnet
Copy link
Member

This PR intends to fix validation errors happening when creating generated controllers in Kubernetes v1.18.

The CustomResourceDefinition "cronjobs.testdata.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
* spec.validation.openAPIV3Schema.properties[spec].properties[embeddedResource].properties: Required value: must not be empty if x-kubernetes-embedded-resource is true without x-kubernetes-preserve-unknown-fields
The CustomResourceDefinition "cronjobs.testdata.kubebuilder.io" is invalid:
* spec.validation.openAPIV3Schema.properties[spec].properties[defaultedObject].default.nested.foo: Required value

In order to fix embeddedResource, and defaultedObject required value errors, this PR adds the missing values inside of cronjob_types.go.

For the protocol validation errors, this PR injects the default Protocol value inside of the scheme.

Fixes #438

pkg: add default: "TCP" to api/core/v1.Procotol scheme.

cronjob_types: add DefaultedObject required field and use NestedObject
type for EmbeddedResource.

Signed-off-by: Damien Grisonnet <dgrisonn@redhat.com>
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 6, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dgrisonnet
To complete the pull request process, please assign mengqiy
You can assign the PR to them by writing /assign @mengqiy in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested review from droot and mengqiy May 6, 2020 17:07
@k8s-ci-robot
Copy link
Contributor

Welcome @dgrisonnet!

It looks like this is your first PR to kubernetes-sigs/controller-tools 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-tools has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 6, 2020
@dgrisonnet
Copy link
Member Author

/assign @mengqiy

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@@ -110,7 +110,7 @@ type CronJobSpec struct {
DefaultedSlice []string `json:"defaultedSlice"`

// This tests that object defaulting can be performed.
// +kubebuilder:default={{nested: {foo: "baz", bar: true}},{nested: {bar: false}}}
// +kubebuilder:default={{nested: {foo: "baz", bar: true}},{nested: {foo: "baz", bar: false}}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to add the extra nested object?

@@ -119,7 +119,7 @@ type CronJobSpec struct {

// +kubebuilder:validation:EmbeddedResource
// +kubebuilder:validation:nullable
EmbeddedResource runtime.RawExtension `json:"embeddedResource"`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was testing an arbitrary embedded object, which would mean we should set x-kubernetes-preserve-unknown-fields: true, right?

"k8s.io/api/core/v1": func(p *Parser, pkg *loader.Package) {
p.Schemata[TypeIdent{Name: "Protocol", Package: pkg}] = apiext.JSONSchemaProps{
Type: "string",
Default: &apiext.JSON{Raw: []byte(strconv.Quote("TCP"))},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't quite right... the default isn't inherent to the type, it's contextual (Protocol inside ServicePort and ContainerPort defaults to "TCP", but other uses might not)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you suggest we do here then?

@kensipe
Copy link

kensipe commented Aug 12, 2020

I thought @jennybuckley was working on an upstream solution. Is this until that lands? or ?

@dgrisonnet
Copy link
Member Author

Closing as #480 was merged.

@dgrisonnet dgrisonnet closed this Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CRD validation errors in Kubernetes 1.18
8 participants