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

CustomResources: in OpenAPI spec allow additionalProperties without properties #62333

Merged
merged 1 commit into from Apr 11, 2018

Conversation

@sttts
Contributor

sttts commented Apr 10, 2018

This implements @ayushpateria's idea #59485 (comment).

With this PR it becomes possible to specify map[string]Interface{} non-object types, e.g. map[string]string for selectors. On the other hand, "normal" objects use properties, mutually exclusively to additionalProperties. This way we avoid a conflict with Kubernetes API conventions that unknown objects fields are dropped.

Fixes #59485

Allow additionalProperties in CRD OpenAPI v3 specification for validation, mutually exclusive to properties.
@sttts

This comment has been minimized.

Contributor

sttts commented Apr 10, 2018

@k8s-ci-robot k8s-ci-robot requested review from nikhita, ash2k and anguslees Apr 10, 2018

@k8s-ci-robot

This comment has been minimized.

Contributor

k8s-ci-robot commented Apr 10, 2018

@sttts: GitHub didn't allow me to request PR reviews from the following users: ayushpateria.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @nikhita @ash2k @anguslees @ayushpateria @tamalsaha

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot requested a review from tamalsaha Apr 10, 2018

@sttts

This comment has been minimized.

Contributor

sttts commented Apr 10, 2018

@@ -45,6 +45,7 @@ func (s *JSONSchemaPropsOrBool) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &sch); err != nil {
return err
}
nw.Allows = true

This comment has been minimized.

@sttts

sttts Apr 10, 2018

Contributor

This mistake saved us 🎉

Because for additionalProperties: {...} we forgot to set allows: true (and we reject Allows == false in general), it was not possible to define a CRD with anything other than additionalProperties: true.

@k8s-ci-robot k8s-ci-robot added size/L and removed size/M labels Apr 10, 2018

if schema.AdditionalProperties.Allows == false {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("additionalProperties"), "additionalProperties cannot be set to false"))
if len(schema.Properties) != 0 {
if schema.AdditionalProperties.Allows == false || schema.AdditionalProperties.Schema != nil {

This comment has been minimized.

@tamalsaha

tamalsaha Apr 10, 2018

Member

Is this extra check necessary?

This comment has been minimized.

@tamalsaha

tamalsaha Apr 10, 2018

Member

If allowed= true and schema = nil, that will cause panic. I can see that it is not possible to generate such object when unmarshaling.

This comment has been minimized.

@sttts

sttts Apr 10, 2018

Contributor

the implicit default of additionalProperties is true. So schema.AdditionalProperties.Allows == true must be allowed.

This comment has been minimized.

@tamalsaha

tamalsaha Apr 10, 2018

Member

My bad, there is not issue with panic when allowed= true and schema = nil.

@tamalsaha

This comment has been minimized.

Member

tamalsaha commented Apr 10, 2018

/lgtm

CustomResources: in OpenAPI spec allow additionalProperties without p…
…roperties

This allows to specify map[string]Interface{} non-object types, e.g. map[string]string
for selectors.
@ash2k

ash2k approved these changes Apr 10, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm label Apr 10, 2018

@k8s-ci-robot

This comment has been minimized.

Contributor

k8s-ci-robot commented Apr 10, 2018

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ash2k, sttts, tamalsaha

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

The pull request process is described 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-merge-robot

This comment has been minimized.

Contributor

k8s-merge-robot commented Apr 11, 2018

Automatic merge from submit-queue (batch tested with PRs 59027, 62333, 57661, 62086, 61584). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-merge-robot k8s-merge-robot merged commit f3cad46 into kubernetes:master Apr 11, 2018

15 checks passed

Submit Queue Queued to run github e2e tests a second time.
Details
cla/linuxfoundation sttts authorized
Details
pull-kubernetes-bazel-build Job succeeded.
Details
pull-kubernetes-bazel-test Job succeeded.
Details
pull-kubernetes-cross Skipped
pull-kubernetes-e2e-gce Job succeeded.
Details
pull-kubernetes-e2e-gce-device-plugin-gpu Job succeeded.
Details
pull-kubernetes-e2e-gke Skipped
pull-kubernetes-e2e-kops-aws Job succeeded.
Details
pull-kubernetes-integration Job succeeded.
Details
pull-kubernetes-kubemark-e2e-gce Job succeeded.
Details
pull-kubernetes-local-e2e Skipped
pull-kubernetes-node-e2e Job succeeded.
Details
pull-kubernetes-typecheck Job succeeded.
Details
pull-kubernetes-verify Job succeeded.
Details
@tamalsaha

This comment has been minimized.

Member

tamalsaha commented Apr 11, 2018

Thanks @sttts for fixing this. This pr fixes an important use-case for map type fields validation as I explained here.

Can this be cherry picked into 1.10 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment