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

Prepare for chaining autogenerated conversion methods #7431

Merged
merged 2 commits into from Apr 30, 2015

Conversation

wojtek-t
Copy link
Member

Part of #6800

This PR is prerequisite for chaining autogenerated conversion methods. The next steps are:

  • test checking whether auto-generated code wasn't manually edited
  • call auto-generated methods one from another [this is easy modulo effective handling of defaulting functions]

@lavalamp @smarterclayton @fgrzadkowski

@wojtek-t
Copy link
Member Author

@lavalamp @smarterclayton
To be clear on calling auto-generated methods one from another. The issue with it is that defaulting functions, are performed on reflections:
https://github.com/GoogleCloudPlatform/kubernetes/blob/master/pkg/conversion/converter.go#L462
So far, I have no idea how to avoid reflections for that, so if you have any suggestions please let me know.

[update]
I think it might be doable if we will be storing the defaulting functions as "interface{}" instead of "reflect.Value". Then, while generating code we will know how to cast the given interface. So I think that should work. But please let me know if you have any better suggestions.

@smarterclayton
Copy link
Contributor

In this change, please add instructions on generation to docs/api_changes.md so that folks needing to add things to the API (@liggitt) have some place to go.

@wojtek-t
Copy link
Member Author

In this change, please add instructions on generation to docs/api_changes.md so that folks needing to add things to the API (@liggitt) have some place to go.

I've started writing this doc and uploaded few lines of it. However, I might not be able to finish it today. So it would be great if you could take a look at the code, before I'm done with the document.

@wojtek-t wojtek-t force-pushed the conversion_chains branch 2 times, most recently from 9f66589 to 6135d99 Compare April 28, 2015 14:41
@smarterclayton
Copy link
Contributor

Separate the conversion changes into their own commit so it's easier to review. We probably want to formalize that in the policy around handling these (always put generations in a separate commit).

@wojtek-t
Copy link
Member Author

Separate the conversion changes into their own commit so it's easier to review. We probably want to formalize that in the policy around handling these (always put generations in a separate commit).

Done

@smarterclayton
Copy link
Contributor

Instead of

    err := newer.Scheme.AddGeneratedConversionFuncs(
        func(in *AWSElasticBlockStoreVolumeSource, out *newer.AWSElasticBlockStoreVolumeSource, s conversion.Scope) error {
            return convertV1beta3AWSElasticBlockStoreVolumeSourceToApiAWSElasticBlockStoreVolumeSource(in, out, s)
        },

do

    err := newer.Scheme.AddGeneratedConversionFuncs(
        convertV1beta3AWSElasticBlockStoreVolumeSourceToApiAWSElasticBlockStoreVolumeSource,

@wojtek-t
Copy link
Member Author

I'm going to improve how the cmd/kube-conversion/conversion.go is used in this PR too (tomorrow), but this won't change the code that is generated. So it would be great if you could look into that. Thanks!

@smarterclayton
Copy link
Contributor

Instead of convertV1beta3AWSElasticBlockStoreVolumeSourceToApiAWSElasticBlockStoreVolumeSource can you do convert_v1beta3_AWSElasticBlockStoreVolumeSource_To_internal_AWSElasticBlockStoreVolumeSource

@smarterclayton
Copy link
Contributor

What's the golang limit on function names?

@@ -0,0 +1,22 @@
API Changes
Copy link
Member

Choose a reason for hiding this comment

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

we already have a docs/devel/api_changes.md - merge?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @thockin - sounds good to me. I will merge those two files (most probably tomorrow).

@@ -27,6 +27,7 @@ import (
type Generator interface {
GenerateConversionsForType(version string, reflection reflect.Type) error
WriteConversionFunctions(w io.Writer) error
WriteConversionFunctionsForRegister(w io.Writer) error
Copy link
Member

Choose a reason for hiding this comment

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

What does "ForRegister" mean?

Copy link
Member Author

Choose a reason for hiding this comment

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

This wasn't the best name. Fixed.

@wojtek-t wojtek-t force-pushed the conversion_chains branch 3 times, most recently from b06a158 to b890642 Compare April 29, 2015 08:52
@wojtek-t
Copy link
Member Author

Instead of convertV1beta3AWSElasticBlockStoreVolumeSourceToApiAWSElasticBlockStoreVolumeSource can you do convert_v1beta3_AWSElasticBlockStoreVolumeSource_To_internal_AWSElasticBlockStoreVolumeSource

I think that names without underscores ale closer to the styleguide (I didn't see any names with underscores anywhere). Why do you want to change this?

All the other comments are applied - PTAL

@smarterclayton
Copy link
Contributor

On Apr 29, 2015, at 4:57 AM, Wojciech Tyczynski notifications@github.com wrote:

Instead of convertV1beta3AWSElasticBlockStoreVolumeSourceToApiAWSElasticBlockStoreVolumeSource can you do convert_v1beta3_AWSElasticBlockStoreVolumeSource_To_internal_AWSElasticBlockStoreVolumeSource

I think that names without underscores ale closer to the styleguide (I didn't see any names with underscores anywhere). Why do you want to change this?

The style guide really doesn't apply to generated functions. The fully transformed version is almost unreadable, so the underscores bring it back.

I'd be willing to make an exception in our style guide to improve the readability and scanability of the list. Also, it preserves the original casing of the names which is probably better.

All the other comments are applied - PTAL


Reply to this email directly or view it on GitHub.

@wojtek-t
Copy link
Member Author

The style guide really doesn't apply to generated functions. The fully transformed version is almost unreadable, so the underscores bring it back.
I'd be willing to make an exception in our style guide to improve the readability and scanability of the list. Also, it preserves the original casing of the names which is probably better.

I don't fully agree with that, but I see your point. Changed.

PTAL

@wojtek-t
Copy link
Member Author

BTW - I have almost ready the next PR, that is calling those conversion functions one from another without using reflections. That PR gives us another ~75% improvements (which is more than 10x from the original results), but since that new PR depends on this one, I will wait with submitting that one before this one is merged.

@smarterclayton
Copy link
Contributor

One more nag - please alpha sort the conversion function references in

newer.Scheme.AddGeneratedConversionFuncs(
convert_v1beta3_AWSElasticBlockStoreVolumeSource_To_api_AWSElasticBlockStoreVolumeSource,

So you can quickly binary search visually to find them. Will make it easier to identify missed conversion bugs and diffs. Best order is a forced order.

@wojtek-t
Copy link
Member Author

One more nag - please alpha sort the conversion function references in

newer.Scheme.AddGeneratedConversionFuncs(
convert_v1beta3_AWSElasticBlockStoreVolumeSource_To_api_AWSElasticBlockStoreVolumeSource,

So you can quickly binary search visually to find them. Will make it easier to identify missed conversion bugs and diffs. Best order is a forced order.

Done - PTAL

@smarterclayton
Copy link
Contributor

This is LGTM barring any final review from @lavalamp

@smarterclayton smarterclayton added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 29, 2015
@wojtek-t
Copy link
Member Author

Thanks @smarterclayton !

@lavalamp
Copy link
Member

My feedback is that it's not obvious which sections of the file are autogenerated and which aren't (add comments before the functions?) and that maybe you could generate it for v1, too, to keep that in sync?

@lavalamp
Copy link
Member

But I don't think that needs to block the PR.

@wojtek-t
Copy link
Member Author

My feedback is that it's not obvious which sections of the file are autogenerated and which aren't (add comments before the functions?)

I definitely agree with it - tomorrow I will be working on the test whether the generated code wasn't manually edited and I will add it as part of it.

and that maybe you could generate it for v1, too, to keep that in sync?

Can I do it in a separate PR?

But I don't think that needs to block the PR.

If you're fine with merging as is, that would be great. I will address your two comments in a separate PR tomorrow.

fgrzadkowski added a commit that referenced this pull request Apr 30, 2015
Prepare for chaining autogenerated conversion methods
@fgrzadkowski fgrzadkowski merged commit 2312841 into kubernetes:master Apr 30, 2015
@wojtek-t wojtek-t deleted the conversion_chains branch April 30, 2015 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants