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 openapi model generation for apply when x-int-or-string is set #97172

Merged
merged 3 commits into from Jan 13, 2021

Conversation

Jefftree
Copy link
Member

@Jefftree Jefftree commented Dec 9, 2020

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

This is a cleanup of #90656.

#85127 and #90902 point out that we cannot build models for openapiv3 types if x-int-or-string is set. Moving schema.Unfold() above StripValueValidations lets us strip the anyOf tags that schema.Unfold() generates and fixes the invalid schema issue.

Which issue(s) this PR fixes:

Fixes #85127

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


And also, the current code only understands V2, so we should use that
exclusively, or we're guaranteed to have errors in the future.
@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. 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. release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Dec 9, 2020
@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Dec 9, 2020
@Jefftree
Copy link
Member Author

/test pull-kubernetes-integration

@@ -103,14 +103,14 @@ func BuildSwagger(crd *apiextensionsv1.CustomResourceDefinition, version string,
if opts.AllowNonStructural || len(structuralschema.ValidateStructural(nil, ss)) == 0 {
schema = ss

schema = schema.Unfold()
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a comment that this will add anyOf that needs to be stripped by the line below.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this moved? In order to also skip the value validations coming from unfolding?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Unfolding adds the anyOf tag if x-int-or-string is set. The tag isn't compatible with the v2 schema so we need to strip them via schema.StripValueValidations()

Copy link
Contributor

Choose a reason for hiding this comment

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

lgtm

@fedebongio
Copy link
Contributor

/assign @apelisse
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/test sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 10, 2020
@Jefftree Jefftree changed the title [WIP] Use openapi V2 for building openapi models for apply Fix openapi model generation for apply when x-int-or-string is set Dec 10, 2020
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 10, 2020
@apelisse
Copy link
Member

@sttts Would you mind taking a look at this? This has a change in behavior that I think we discussed and agreed would be better (don't use the schema when it's not structural). That should finally fix that bug you've been asking about! 😅
@jennybuckley Would you mind also looking at this since you wrote the initial code here?

@apelisse
Copy link
Member

apelisse commented Dec 12, 2020

The addition of the test is a great step in the right direction, and gives us the confidence that we'll be able to possibly solve these bugs faster in the future, or even prevent them from happening, thanks @Jefftree! LGTM for me.

@sttts sttts added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Jan 7, 2021
@k8s-ci-robot k8s-ci-robot removed the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Jan 7, 2021
@sttts
Copy link
Contributor

sttts commented Jan 7, 2021

Sgtm.

Leaving lgtm to @apelisse.

@apelisse
Copy link
Member

apelisse commented Jan 7, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 7, 2021
}

return staticSpec, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Am not a fan of tests in staging repos that use files outside. This makes splitting repos hard some day.

Copy link
Member

Choose a reason for hiding this comment

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

+1, in addition to the fact that we don't need most of the types defined in this file (and json unmarshalling deep structures is slooooow in race mode)

Copy link
Member

Choose a reason for hiding this comment

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

opened #98694 with a local / trimmed swagger.json to use for the test

for _, test := range tests {
crd.Spec.Versions[0].Schema = &test
if _, err := buildOpenAPIModelsForApply(staticSpec, &crd); err != nil {
t.Fatalf("failed to convert to apply model: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

t.Error

Copy link
Contributor

@sttts sttts Jan 12, 2021

Choose a reason for hiding this comment

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

and print the index, or give the tests names

@apelisse
Copy link
Member

I don't disagree. We could copy the file but it's not super useful now, and it's not really hard to do the day we're trying to split.

@sttts
Copy link
Contributor

sttts commented Jan 12, 2021

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Jefftree, sttts

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

},
}

staticSpec, err := getOpenAPISpecFromFile()
Copy link
Member

Choose a reason for hiding this comment

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

this line takes ~12 seconds to run in unit tests run with -race detection

}

return staticSpec, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

+1, in addition to the fact that we don't need most of the types defined in this file (and json unmarshalling deep structures is slooooow in race mode)


for _, test := range tests {
crd.Spec.Versions[0].Schema = &test
if _, err := buildOpenAPIModelsForApply(staticSpec, &crd); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

this line takes ~6 seconds to run in unit tests with -race detection on

}

return staticSpec, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

opened #98694 with a local / trimmed swagger.json to use for the test

davidfestal added a commit to davidfestal/kcp-kubernetes that referenced this pull request Aug 4, 2021
... to bypass issue kubernetes#85127
until we possibly rebase this branch to get the real fix.

Signed-off-by: David Festal <dfestal@redhat.com>
@Jefftree Jefftree deleted the opentest branch December 7, 2021 17:26
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/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/testing Categorizes an issue or PR as relevant to SIG Testing. 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.

nullable in OpenAPI schema breaks server-side-apply
6 participants