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 serialization of x-kubernetes-validations OpenAPI extension #107970

Merged
merged 2 commits into from Feb 9, 2022

Conversation

liggitt
Copy link
Member

@liggitt liggitt commented Feb 5, 2022

What type of PR is this?

/kind bug
/kind flake

What this PR does / why we need it:

Switches the openapi serialized extension for x-kubernetes-validations to use the external type with correct json tags. It was getting serialized incorrectly as [{"Message":"...", "Rule":"..."}]

Makes the jsonschemaprops -> openapi -> jsonschemaprops roundtrip test more strict

Fix OpenAPI serialization of the x-kubernetes-validations field

/cc @benluddy @sttts
/sig api-machinery

@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Feb 5, 2022
@k8s-ci-robot
Copy link
Contributor

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

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

In response to this:

What type of PR is this?

/kind bug
/kind flake

What this PR does / why we need it:

Makes the jsonschemaprops -> openapi -> jsonschemaprops roundtrip test more strict

TODO: resolve what to do for the serialization of the structured XValidations rule which is using capital Rule and Message fields.

Fix OpenAPI serialization of the x-kubernetes-validations field

/cc @benluddy @sttts
/sig api-machinery

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 added kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 5, 2022
@k8s-ci-robot k8s-ci-robot added kind/flake Categorizes issue or PR as related to a flaky test. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Feb 5, 2022
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Feb 5, 2022
@liggitt
Copy link
Member Author

liggitt commented Feb 5, 2022

serialization issue seen here:

[liggitt@liggitt-macbookpro2 kubernetes]$ TEST_RAND_SEED=389141000 go test k8s.io/apiextensions-apiserver/pkg/apiserver/validation
--- FAIL: TestRoundTrip (0.00s)
    validation_test.go:63: using overridden seed: 389141000
    validation_test.go:105: [unknown field "not.patternProperties.彤Ž叩ǖ搥Õ軯夞ȗ@.x-kubernetes-validations[0].Message" unknown field "not.patternProperties.彤Ž叩ǖ搥Õ軯夞ȗ@.x-kubernetes-validations[0].Rule"]
FAIL
FAIL	k8s.io/apiextensions-apiserver/pkg/apiserver/validation	0.886s

@liggitt liggitt added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 5, 2022
@liggitt
Copy link
Member Author

liggitt commented Feb 5, 2022

This is producing an unserializable extension:

if len(in.XValidations) != 0 {
out.VendorExtensible.AddExtension("x-kubernetes-validations", in.XValidations)
}

Because the referenced XValidations field doesn't set json tags on its rule and message fields.

Options:

  1. add json tags to the internal XValidations Rule and Message fields... not great because this is an internal type
  2. change ConvertJSONSchemaPropsWithPostProcess to use the v1 CRD types which are serializable
  3. translate the XValidations field to a struct private to ConvertJSONSchemaPropsWithPostProcess that is serializable

My instinct is to go with option 2

@liggitt
Copy link
Member Author

liggitt commented Feb 5, 2022

Options:

  1. add json tags to the internal XValidations Rule and Message fields... not great because this is an internal type
  2. change ConvertJSONSchemaPropsWithPostProcess to use the v1 CRD types which are serializable
  3. translate the XValidations field to a struct private to ConvertJSONSchemaPropsWithPostProcess that is serializable

My instinct is to go with option 2

hmm... switching conversion entirely to use v1 schema types wreaks havoc with the handling of raw JSON values for defaults, etc

@liggitt
Copy link
Member Author

liggitt commented Feb 5, 2022

I defined an internal->v1 conversion for the ValidationRules type, and use the v1 type when constructing a structural schema

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/dependency Issues or PRs related to dependency changes kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 5, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt

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

@leilajal
Copy link
Contributor

leilajal commented Feb 8, 2022

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 8, 2022
@liggitt liggitt removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 9, 2022
@liggitt liggitt changed the title Make JSON schema round tripping test more strict Fix serialization of x-kubernetes-validations OpenAPI extension Feb 9, 2022
@liggitt liggitt added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Feb 9, 2022
@k8s-ci-robot k8s-ci-robot removed the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Feb 9, 2022
@k8s-triage-robot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@benluddy
Copy link
Contributor

benluddy commented Feb 9, 2022

/assign

@benluddy
Copy link
Contributor

benluddy commented Feb 9, 2022

/lgtm

@k8s-ci-robot
Copy link
Contributor

@benluddy: changing LGTM is restricted to collaborators

In response to this:

/lgtm

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.

@liggitt
Copy link
Member Author

liggitt commented Feb 9, 2022

/assign @jpbetz
for org member lgtm

@liggitt
Copy link
Member Author

liggitt commented Feb 9, 2022

/retest

@jpbetz
Copy link
Contributor

jpbetz commented Feb 9, 2022

/lgtm

Wow, I'm surprised we didn't notice this till now. Thanks for fixing!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 9, 2022
@k8s-ci-robot k8s-ci-robot merged commit 4c300ff into kubernetes:master Feb 9, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Feb 9, 2022
@liggitt liggitt deleted the validations-round-trip branch February 9, 2022 21:58
k8s-ci-robot added a commit that referenced this pull request Feb 10, 2022
…970-upstream-release-1.23

Automated cherry pick of #107970: Make JSON schema round tripping test more strict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/dependency Issues or PRs related to dependency changes cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/bug Categorizes issue or PR as related to a bug. kind/flake Categorizes issue or PR as related to a flaky test. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants