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

Reactivate OpenAPI v3 JSON+Proto roundtrip integration test #126731

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

luxas
Copy link
Member

@luxas luxas commented Aug 16, 2024

What type of PR is this?

/kind bug

What this PR does / why we need it:

Hi folks, reactivating the integration test which makes sure JSON and Proto encodings of OpenAPI v3 are equal.
This can be done now that the earlier issue #106387 is solved.

As can be seen, they are in fact not exactly similar, so maybe we should fix the JSON encoding of the OpenAPI v3 spec to not include "default": {}?

(FYI: Discovered this from digging into supporting OpenAPI v3 "natively" using the client-go discovery client)

cc recent kube-openapi contributors @sttts @Jefftree @apelisse @alexzielenski @thockin

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 16, 2024
@k8s-ci-robot k8s-ci-robot added area/test sig/testing Categorizes an issue or PR as relevant to SIG Testing. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Aug 16, 2024
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Aug 16, 2024
// In the JSON/YAML OpenAPI definitions, however, there are cases with "default": {}, deserializing into JSON as map[string]any.
// From protobuf, however, these deserialize naturally into nil, as they are not expressed.
// We should probably patch the OpenAPI v3 spec to not include any empty struct defaults at all in JSON form, as proto doesn't support it.
// For now, however, we can ignore these differences.
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, every JSON value could show up as default. How do we ensure these never hit these (outside of tests) ?

Copy link
Contributor

@sttts sttts Aug 16, 2024

Choose a reason for hiding this comment

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

If we are sure, these can never show up in the proto spec, we can restrict the fuzzing here (equivalent to your ignoreEmptyStructDefaults below).

Actually, we are in an integration test here. So the arbitrary defaults show up?

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean that someone would put "default": {"foo": "bar"} into the OpenAPI?

The other alternative is changing proto to support struct defaults I guess. Does that sound feasible?

Copy link
Member Author

Choose a reason for hiding this comment

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

Tested this now with CRDs as well. The findings:
a) native types have at least "simple" defaults that proto support, e.g. string, number, bool. These show up in OpenAPI
b) if one specified defaults in a CRD OpenAPI schema declaratively, these show up in server's OpenAPI schema as well as you'd expect
c) however CRD declarative defaulting can be non-simple types, sth like {"cronSpec": "5 0 * * *", "image": "foo"}. This shows up correctly in JSON OpenAPI v3, but NOT at all in proto, here's the diff from this test in that case:

json is -
proto is +
         						"spec": {
          							VendorExtensible: {},
          							SchemaProps: spec.SchemaProps{
          								... // 6 identical fields
          								Format:           "",
          								Title:            "",
        - 								Default:          map[string]any{"cronSpec": string("5 0 * * *"), "image": string("foo")},
        + 								Default:          nil,
          								Maximum:          nil,
          								ExclusiveMaximum: false,
          								... // 24 identical fields
          							},
          							SwaggerSchemaProps: {},
          							ExtraProps:         nil,

Copy link
Contributor

Choose a reason for hiding this comment

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

Have double checks that we expose defaults of CRDs. So how do these show up in a proto serialization?

@k8s-ci-robot k8s-ci-robot added the area/dependency Issues or PRs related to dependency changes label Aug 16, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: luxas
Once this PR has been reviewed and has the lgtm label, please assign thockin for approval. For more information see the Kubernetes Code Review Process.

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

@luxas
Copy link
Member Author

luxas commented Aug 16, 2024

xref: google/gnostic-models#11

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 28, 2024
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dependency Issues or PRs related to dependency changes area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants