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

Support +mapType, +structType markers #178

Merged
merged 7 commits into from
Jan 30, 2020
Merged

Support +mapType, +structType markers #178

merged 7 commits into from
Jan 30, 2020

Conversation

mariantalla
Copy link
Contributor

@mariantalla mariantalla commented Nov 6, 2019

This PR adds support for markers // +mapType=<atomic/granular>, // +structType=<atomic/granular>; they should both map to the 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 (#166).

fixes #177

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 6, 2019
@sttts
Copy link
Contributor

sttts commented Nov 6, 2019

What is struct type? In CRDs we only have list-type and map-type.

@mariantalla
Copy link
Contributor Author

structType seems to have been added as part of the server-side apply work (for native objects). Unless I got this wrong 🤔

@mariantalla
Copy link
Contributor Author

/hold
there's a mistake in the implementation with structType in any case - +structType should also convert to x-kubernetes-map-type

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 11, 2019
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
@mariantalla
Copy link
Contributor Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 12, 2019
package maptype

// +k8s:openapi-gen=true
type AtomicMap struct {
Copy link
Member

@apelisse apelisse Dec 12, 2019

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

Copy link
Contributor Author

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!

Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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:

https://github.com/kubernetes/kube-openapi/blob/master/test/integration/builder/main.go#L105-L117

We should have a way to fail if this is not done somehow ...

Copy link
Contributor Author

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 🤔

Copy link
Member

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.

@apelisse
Copy link
Member

Looks good to me, a few super small nits. @sttts PTAL

@apelisse
Copy link
Member

Looks good to me now!

@mariantalla
Copy link
Contributor Author

Is there anything else to be done here?

/cc @sttts

Copy link
Member

@apelisse apelisse left a 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"
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

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)

Copy link
Contributor Author

@mariantalla mariantalla Jan 21, 2020

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.

Copy link
Contributor Author

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 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for fixing this.

@sttts
Copy link
Contributor

sttts commented Jan 20, 2020

Looks good overall. Leaving lgtm to @apelisse.

@apelisse
Copy link
Member

/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
Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👌 (for structType too).

@mariantalla
Copy link
Contributor Author

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()),
Copy link
Member

Choose a reason for hiding this comment

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

Why are these gone?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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 🙃

@apelisse
Copy link
Member

apelisse commented Jan 27, 2020

I think this is good, I'm just a little concerned about some types disappearing (custom.Bac,...)?

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" \
Copy link
Member

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

@apelisse
Copy link
Member

That looks really good, thank you!
/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 30, 2020
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 30, 2020
@k8s-ci-robot k8s-ci-robot merged commit cdac1c7 into kubernetes:master Jan 30, 2020
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for +mapType, +structType
4 participants