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

conversion-gen: support recursive types #49747

Merged

Conversation

nikhita
Copy link
Member

@nikhita nikhita commented Jul 27, 2017

Currently, conversion-gen goes into an infinite recursion for recursive types. This fixes it to support recursive types.

Needed for #47263.

Release note:

NONE

/cc @sttts

@k8s-ci-robot k8s-ci-robot requested a review from sttts July 27, 2017 20:54
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 27, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @nikhita. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

I understand the commands that are listed here.

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/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 27, 2017
@k8s-github-robot k8s-github-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels Jul 27, 2017
@sttts
Copy link
Contributor

sttts commented Jul 27, 2017

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 27, 2017
@sttts sttts assigned smarterclayton and lavalamp and unassigned lavalamp Jul 27, 2017
@sttts
Copy link
Contributor

sttts commented Jul 27, 2017

@lavalamp I think you reviewed basically the same thing in gengo already. This time it's in conversion-gen. ptal.

if currentlyBuildingTypes[in] {
return true
}
currentlyBuildingTypes[in] = true
Copy link
Member

Choose a reason for hiding this comment

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

In Go passing map means effectively passing a pointer to map. Since noone is deleting anything from that map, you end up with map with a bunch of things at the end.

This probably isn't a big deal, but I think calling it "currentlyBuildingTypes" is a bit misleading then.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. I was a bit unsure about the name too. How about "alreadyVisitedTypes"?

Copy link
Member

Choose a reason for hiding this comment

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

It's definitely better in my opinion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@nikhita nikhita force-pushed the conversion-gen-recursive-types branch from ad46f2a to 23d0445 Compare July 28, 2017 12:31
@nikhita
Copy link
Member Author

nikhita commented Jul 28, 2017

/retest

@@ -338,36 +338,42 @@ func (e equalMemoryTypes) Equal(a, b *types.Type) bool {
if equal, ok := e[conversionPair{b, a}]; ok {
return equal
}
result := e.equal(a, b)
result := e.equal(a, b, alreadyVisitedTypes)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering, do we need the parameter inEqual at all? Can't we create the empty map here?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't do that because we need the populated map in line 366, 372, 374 and 376 below. If we create an empty map here and those lines are executed, they will see the type as "not visited" - which will defeat our purpose. :)

Also, tried it out. Gives the goroutine stack exceeds 1000000000-byte limit error.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, didn't realize the recursion goes through Equal and not equal.

Copy link
Contributor

Choose a reason for hiding this comment

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

But, everything here in Equal can be moved to equal and then we can recursively call equal instead of Equal, can't it? Then my suggestion should work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't make the code easier to read though. Let's leave it as it is.

@nikhita nikhita force-pushed the conversion-gen-recursive-types branch from 23d0445 to f98b74b Compare July 28, 2017 18:40
@nikhita
Copy link
Member Author

nikhita commented Jul 28, 2017

/retest

@@ -329,6 +329,13 @@ func (e equalMemoryTypes) Skip(a, b *types.Type) {
}

func (e equalMemoryTypes) Equal(a, b *types.Type) bool {
// alreadyVisitedTypes holds all the types that have been converted. This is used to avoid
Copy link
Contributor

@sttts sttts Jul 28, 2017

Choose a reason for hiding this comment

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

here it's not about "been converted", but about comparing that two structs have the same memory structure. If they have, we can use unsafe.Pointer to replace conversion by a type cast.

Better:

// alreadyVisitedTypes holds all the types that have already been checked in the structural type recursion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Currently, the conversion-gen goes into an infinite recursion
for recursive types.

rename: currentlyBuildingTypes -> alreadyVisitedTypes

use a cachingEqual func

update comment
@nikhita nikhita force-pushed the conversion-gen-recursive-types branch from f98b74b to c4656c3 Compare July 28, 2017 19:13
@sttts
Copy link
Contributor

sttts commented Jul 28, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 28, 2017
@sttts
Copy link
Contributor

sttts commented Jul 28, 2017

@wojtek-t approved?

@nikhita
Copy link
Member Author

nikhita commented Jul 28, 2017

/retest

@wojtek-t
Copy link
Member

/approve no-issue

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nikhita, sttts, wojtek-t

Associated issue: 47263

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 31, 2017
@nikhita
Copy link
Member Author

nikhita commented Jul 31, 2017

/retest

1 similar comment
@nikhita
Copy link
Member Author

nikhita commented Jul 31, 2017

/retest

@nikhita
Copy link
Member Author

nikhita commented Jul 31, 2017

/test pull-kubernetes-unit

@nikhita
Copy link
Member Author

nikhita commented Jul 31, 2017

/test pull-kubernetes-e2e-kops-aws

@nikhita
Copy link
Member Author

nikhita commented Jul 31, 2017

/test pull-kubernetes-bazel

@nikhita
Copy link
Member Author

nikhita commented Jul 31, 2017

/retest

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

@nikhita
Copy link
Member Author

nikhita commented Jul 31, 2017

Submit Queue says Required Github CI test is not green: pull-kubernetes-unit. But pull-kubernetes-unit is green...

@nikhita
Copy link
Member Author

nikhita commented Jul 31, 2017

/retest

@nikhita
Copy link
Member Author

nikhita commented Jul 31, 2017

/test pull-kubernetes-e2e-kops-aws

@nikhita
Copy link
Member Author

nikhita commented Jul 31, 2017

/retest

1 similar comment
@nikhita
Copy link
Member Author

nikhita commented Jul 31, 2017

/retest

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 49651, 49707, 49662, 47019, 49747)

@k8s-github-robot k8s-github-robot merged commit 088c198 into kubernetes:master Jul 31, 2017
k8s-github-robot pushed a commit that referenced this pull request Aug 30, 2017
Automatic merge from submit-queue

apiextensions: validation for customresources

- [x] Add types for validation of CustomResources
- [x] Fix conversion-gen: #49747
- [x] Fix defaulter-gen: kubernetes/gengo#61
- [x] Convert to OpenAPI types
- [x] Validate CR using go-openapi
- [x] Validate CRD Schema
- [x] Add integration tests
- [x] Fix round trip tests: #51204 
- [x] Add custom fuzzer functions
- [x] Add custom conversion functions
- [x] Fix data race while updating CRD: #50098 
- [x] Add feature gate for CustomResourceValidation
- [x] Fix protobuf generation

Proposal: kubernetes/community#708
Additional discussion: #49879, #50625

**Release note**:

```release-note
Add validation for CustomResources via JSON Schema.
```

/cc @sttts @deads2k
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. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants