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
Conversation
And also, the current code only understands V2, so we should use that exclusively, or we're guaranteed to have errors in the future.
/test pull-kubernetes-integration |
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler_test.go
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler_test.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler_test.go
Show resolved
Hide resolved
@@ -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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
/assign @apelisse |
@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! 😅 |
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. |
Sgtm. Leaving lgtm to @apelisse. |
/lgtm |
} | ||
|
||
return staticSpec, nil | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.Error
There was a problem hiding this comment.
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
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. |
/approve |
[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 |
}, | ||
} | ||
|
||
staticSpec, err := getOpenAPISpecFromFile() |
There was a problem hiding this comment.
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 | ||
} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 | ||
} |
There was a problem hiding this comment.
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
... to bypass issue kubernetes#85127 until we possibly rebase this branch to get the real fix. Signed-off-by: David Festal <dfestal@redhat.com>
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()
aboveStripValueValidations
lets us strip the anyOf tags thatschema.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?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: