-
Notifications
You must be signed in to change notification settings - Fork 204
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
Support +mapType, +structType markers #178
Support +mapType, +structType markers #178
Conversation
What is struct type? In CRDs we only have list-type and map-type. |
|
/hold |
and convert both of them to openapi extension: x-kubernetes-map-type. Also adding minor changes to the integration tests README to ensure that it's up to date after recent changes that add v2 support (PR #166). wip
/hold cancel |
package maptype | ||
|
||
// +k8s:openapi-gen=true | ||
type AtomicMap struct { |
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.
Are these types supposed to generate something in some golden data? I don't see a corresponding update to some golden data
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.
Hm, good point. Not sure. The steps in the integration tests README don't change the golden data. The only thing that edits golden.v2.json
is the builder
script 🤔 I'll dig into it a bit as I don't know this codebase that well - let me know if it's something obvious I'm missing!
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.
I'm specifically concerned since the tests don't pass for me but they pass for the CI ...
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.
OK I can reproduce the failure on this pull-request while having master work.
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.
wait no it passes now ...
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.
Ahah it's absolutely terrible. You have to add your objects to:
We should have a way to fail if this is not done somehow ...
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.
Thanks! Added them with a0384dd - though if I'm honest I only partially understand what they're testing 🤔
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.
The test generates the openapi corresponding to the types that you have. Now we can look at the report.v2.json
and see that it generates what we expect from the tags.
Looks good to me, a few super small nits. @sttts PTAL |
It's atomic/granular, not only atomic.
Looks good to me now! |
Is there anything else to be done here? /cc @sttts |
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.
I've left a couple of nits, but this looks really really good, thanks at ton @mariantalla !
"additionalProperties": { | ||
"type": "string" | ||
}, | ||
"x-kubernetes-map-type": "granular" |
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.
The doc above says that we don't generate an openapi extension on the granular case?
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.
Which doc are you referring to? 🤔 (happy to change it, just to make sure I understand)
|
||
// +k8s:openapi-gen=true | ||
type GranularStruct struct { | ||
// +structType=granular |
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.
is this in the right place? the structType is annotating a string. Should it fail some sort of validation?
(and same problem above on the AtomicStruct
)
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.
Yeah, the annotation is applied to the string; "correctly" (in that Field
gets the right tag in the produced API spec) but it's super confusing the way I've written it. I've changed it so that the marker annotates a "proper" struct - let me know what you think.
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.
Indeed interesting that the validation didn't fail though when using structType
on a string 🤔 I'll experiment with it and see if there's a problem here 🤔
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.
Thanks for fixing this.
Looks good overall. Leaving lgtm to @apelisse. |
/wg apply |
pkg/idl/doc.go
Outdated
// openapi extension, as this will also be interpreted as the default | ||
// behavior in the openapi definition. | ||
// can be updated individually (i.e. the equivalent of `granular`). | ||
// This default WILL NOT generate any openapi extension, as this will also |
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.
Which doc are you referring to?
This doc :-)
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.
We talked about it during the meeting, but making my comment "official". I think it's strictly better to have the "granular" explicitly in the openapi than rely on the missing value.
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.
Done 👌 (for structType
too).
Let me know when all looks good and I'll squash. |
) | ||
|
||
func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { | ||
return map[string]common.OpenAPIDefinition{ | ||
"k8s.io/kube-openapi/test/integration/testdata/custom.Bac": common.EmbedOpenAPIDefinitionIntoV2Extension(custom.Bac{}.OpenAPIV3Definition(), custom.Bac{}.OpenAPIDefinition()), |
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 are these gone?
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.
huh, no idea. Will re-run the generation and see if I can either reproduce or fix it that way.
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.
I reset the changes in openapi_generated.go
as the README in test/integration suggests. However it's still strange that the generation omits some types. Taking a look now to see if anything stands out... 🤔
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.
Fixed (I think!) - problem was that the script that generates the API violations report did not get testdata/custom
as input. User error 🙃
I think this is good, I'm just a little concerned about some types disappearing ( |
to print API rule violations to the file, the generator will return error to stderr | ||
on API rule violations. | ||
|
||
```bash | ||
$ go run ../../cmd/openapi-gen/openapi-gen.go \ | ||
-i "k8s.io/kube-openapi/test/integration/testdata/listtype,k8s.io/kube-openapi/test/integration/testdata/dummytype,k8s.io/kube-openapi/test/integration/testdata/uniontype" \ | ||
-i "k8s.io/kube-openapi/test/integration/testdata/custom,k8s.io/kube-openapi/test/integration/testdata/listtype,k8s.io/kube-openapi/test/integration/testdata/maptype,k8s.io/kube-openapi/test/integration/testdata/structtype,k8s.io/kube-openapi/test/integration/testdata/dummytype,k8s.io/kube-openapi/test/integration/testdata/uniontype" \ |
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.
OK So it looks like it shouldn't have worked before? These tests are requiring people to pay too much attention, we should improve that ...
That looks really good, thank you! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: apelisse 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 |
This PR adds support for markers
// +mapType=<atomic/granular>
,// +structType=<atomic/granular>
; they should both map to the OpenAPI extensionx-kubernetes-map-type
.Also adding minor changes to the integration tests README to ensure that
it's up to date after recent changes that add v2 support (#166).
fixes #177