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

protobuf: During generation, copy protobuf tags back #19426

Merged
merged 1 commit into from
Jan 26, 2016

Conversation

smarterclayton
Copy link
Contributor

The protobuf tags contain the assigned tag id, which then ensures
subsequent generation is consistently tagging (tags don't change across
generations unless someone deletes the protobuf tag).

In addition, generate final proto IDL that is free of gogoproto
extensions for ease of generation into other languages.

@kubernetes/sig-api-machinery

@k8s-github-robot
Copy link

Labelling this PR as size/L

@k8s-github-robot k8s-github-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 8, 2016
@smarterclayton
Copy link
Contributor Author

Follow up from #17854

@k8s-bot
Copy link

k8s-bot commented Jan 8, 2016

GCE e2e test build/test passed for commit 7616f1c7deed78107af5e3ef4877232f9066608d.

p.OmitGogo = true
}

// generate, but do so without gogoprotobuf extensions
Copy link
Member

Choose a reason for hiding this comment

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

nit, i would kill the newline above and put this command before the for loop

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'm going to also make this optional so people can see the fully qualified IDL.

@smarterclayton
Copy link
Contributor Author

Removed some round trip prototag loading for optional and repeated - it didn't actually help, and those should be controlled by the generator.

@k8s-bot
Copy link

k8s-bot commented Jan 22, 2016

GCE e2e test build/test passed for commit 6a535b8f793304ec630648de4f11ca823bc88acc.

@k8s-bot
Copy link

k8s-bot commented Jan 22, 2016

GCE e2e test build/test passed for commit 46ea05db21fce1d010819dd2b854da147cf2499f.

continue
}
if len(f.Names) > 1 {
log.Printf("WARNING: struct %s field %d %s: defined multiple names but single protobuf tag", t.Name.Name, i, f.Names[0].Name)
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 supposed to cover the case where someone has a field tagged with json:"foo" yaml:"bar" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Someone did "Foo, Bar string protobuf:"baz"" which means we have the same
field defined twice.

On Mon, Jan 25, 2016 at 11:13 AM, Paul Morie notifications@github.com
wrote:

In cmd/libs/go2idl/go-to-protobuf/protobuf/package.go
#19426 (comment)
:

  •   return false
    
  • }
  • switch s := t.Type.(type) {
  • case *ast.StructType:
  •   for i, f := range s.Fields.List {
    
  •       if len(f.Tag.Value) == 0 {
    
  •           continue
    
  •       }
    
  •       tag := strings.Trim(f.Tag.Value, "`")
    
  •       protobufTag := reflect.StructTag(tag).Get("protobuf")
    
  •       if len(protobufTag) == 0 {
    
  •           continue
    
  •       }
    
  •       if len(f.Names) > 1 {
    
  •           log.Printf("WARNING: struct %s field %d %s: defined multiple names but single protobuf tag", t.Name.Name, i, f.Names[0].Name)
    

Is this supposed to cover the case where someone has a field tagged with json:"foo"
yaml:"bar" ?


Reply to this email directly or view it on GitHub
https://github.com/kubernetes/kubernetes/pull/19426/files#r50714702.

Copy link
Member

Choose a reason for hiding this comment

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

bleh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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 OK if we outlaw that...

On Mon, Jan 25, 2016 at 6:46 PM, Clayton Coleman notifications@github.com
wrote:

In cmd/libs/go2idl/go-to-protobuf/protobuf/package.go
#19426 (comment)
:

  •   return false
    
  • }
  • switch s := t.Type.(type) {
  • case *ast.StructType:
  •   for i, f := range s.Fields.List {
    
  •       if len(f.Tag.Value) == 0 {
    
  •           continue
    
  •       }
    
  •       tag := strings.Trim(f.Tag.Value, "`")
    
  •       protobufTag := reflect.StructTag(tag).Get("protobuf")
    
  •       if len(protobufTag) == 0 {
    
  •           continue
    
  •       }
    
  •       if len(f.Names) > 1 {
    
  •           log.Printf("WARNING: struct %s field %d %s: defined multiple names but single protobuf tag", t.Name.Name, i, f.Names[0].Name)
    

Someone did "Foo, Bar string protobuf:"baz"" which means we have the
same field defined twice.
… <#-1348009057_>
On Mon, Jan 25, 2016 at 11:13 AM, Paul Morie notifications@github.com
wrote: In cmd/libs/go2idl/go-to-protobuf/protobuf/package.go <#19426
(comment)
https://github.com/kubernetes/kubernetes/pull/19426#discussion_r50714702>
: > + return false > + } > + > + switch s := t.Type.(type) { > + case
*ast.StructType: > + for i, f := range s.Fields.List { > + if
len(f.Tag.Value) == 0 { > + continue > + } > + tag :=
strings.Trim(f.Tag.Value, "`") > + protobufTag :=
reflect.StructTag(tag).Get("protobuf") > + if len(protobufTag) == 0 { > +
continue > + } > + if len(f.Names) > 1 { > + log.Printf("WARNING: struct %s
field %d %s: defined multiple names but single protobuf tag", t.Name.Name,
i, f.Names[0].Name) Is this supposed to cover the case where someone has a
field tagged with json:"foo" yaml:"bar" ? — Reply to this email directly or
view it on GitHub <
https://github.com/kubernetes/kubernetes/pull/19426/files#r50714702>.


Reply to this email directly or view it on GitHub
https://github.com/kubernetes/kubernetes/pull/19426/files#r50790202.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@smarterclayton
Copy link
Contributor Author

Comments addressed

@k8s-bot
Copy link

k8s-bot commented Jan 26, 2016

GCE e2e test build/test passed for commit 08fb7d777cfaea54f20c9d3e889d9dea726d8f5e.

The protobuf tags contain the assigned tag id, which then ensures
subsequent generation is consistently tagging (tags don't change across
generations unless someone deletes the protobuf tag).

In addition, generate final proto IDL that is free of gogoproto
extensions for ease of generation into other languages.

Add a flag --keep-gogoproto which preserves the gogoproto extensions in
the final IDL.
@pmorie pmorie added lgtm "Looks good to me", indicates that a PR is ready to be merged. e2e-not-required labels Jan 26, 2016
@k8s-bot
Copy link

k8s-bot commented Jan 26, 2016

GCE e2e test build/test passed for commit 14a3aaf.

@k8s-github-robot
Copy link

Automatic merge from submit-queue

k8s-github-robot pushed a commit that referenced this pull request Jan 26, 2016
@k8s-github-robot k8s-github-robot merged commit 3254df3 into kubernetes:master Jan 26, 2016
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. 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.

7 participants