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

Add package name to crit protobuf files #90

Merged
merged 1 commit into from
Sep 5, 2022

Conversation

snprajwal
Copy link
Member

@snprajwal snprajwal commented Sep 3, 2022

In Podman, the core.proto and sa.proto files from https://github.com/letsencrypt/boulder conflict with identically named proto files in crit, causing a panic during the build. As a workaround, these two files have been renamed to criu-core.proto and criu-sa.proto.

@adrianreber
Copy link
Member

Can you describe the problem a bit more in detail.

@codecov-commenter
Copy link

Codecov Report

Merging #90 (4ca4d9a) into master (287ed08) will not change coverage.
The diff coverage is n/a.

❗ Current head 4ca4d9a differs from pull request most recent head def02ab. Consider uploading reports for the commit def02ab to get more accurate results

@@           Coverage Diff           @@
##           master      #90   +/-   ##
=======================================
  Coverage   51.38%   51.38%           
=======================================
  Files           2        2           
  Lines         288      288           
=======================================
  Hits          148      148           
  Misses        105      105           
  Partials       35       35           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@rst0git
Copy link
Member

rst0git commented Sep 3, 2022

Can you describe the problem a bit more in detail.

This pull request adds a fix for the problem that occurred in containers/podman#15591 after updating go-criu to v6.0.0:

panic: proto: file "sa.proto" is already registered
	previously from: "github.com/letsencrypt/boulder/sa/proto"
	currently from:  "github.com/checkpoint-restore/go-criu/v6/crit/images"
See https://developers.google.com/protocol-buffers/docs/reference/go/faq#namespace-conflict

Copy link
Member

@rst0git rst0git left a comment

Choose a reason for hiding this comment

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

LGTM

@adrianreber
Copy link
Member

Not really convinced about this. This global protobuf namespace is very unfortunate. Can we fix it in another way?

In the link there is something about a go_package option. Can that be passed during proto -> pb.go compilation?

@snprajwal
Copy link
Member Author

snprajwal commented Sep 4, 2022

In the link there is something about a go_package option. Can that be passed during proto -> pb.go compilation?

@adrianreber According to the language guide at https://developers.google.com/protocol-buffers/docs/proto#packages:

  • In Go, the package directive is ignored, and the generated .pb.go file is in the package named after the corresponding go_proto_library rule.

The go_package option is used to indicate the import path the the protoc compiler for .proto files with imports. This can be passed during compile time as --go-opt=Mpath/to/proto=importpath. We are doing this with the proto_opts variable in the Makefile here.

@adrianreber
Copy link
Member

I also looked at it and found no real solution. The thing about this change is that it seems temporary until we meet another namespace collision. So maybe we have to namespace all files now. Would something like this work:

$ for i in criu-temp/images/*.proto; do if [[ "$i" == *"opts.proto" ]]; then continue; fi; sed -e 's,import\s",import "criu-,g' -i $i; done
$ for i in criu-temp/images/*.proto; do cp -v $i ./images/criu-$(basename $i); done

This is really unfortunate. Maybe we need to do this change on the CRIU level. It should not break the content of the existing images, I hope, but if we include the namespacing already in CRIU the changes here are no longer necessary.

@snprajwal
Copy link
Member Author

snprajwal commented Sep 4, 2022

@adrianreber @rst0git The issue is fixed in Go by adding a package directive to all the .proto files. This prevents conflicts in the protobuf namespace, while keeping the Go bindings unchanged. To ensure we don't have any more conflicts in the future, it would be prudent to pick a unique and verbose package name. I would suggest package checkpoint.restore (I tested with this, podman is building successfully).

Unfortunately, this change on criu breaks the generated C bindings. The package name is prepended to all protobuf messages, eg. checkpoint__restore__core_entry in core.pb-c.c, which generates a considerable number of errors. It would require a major overhaul of every reference to the messages in the codebase, which doesn't look like a practical refactor to me. Instead, we can keep the package directive exclusive to the Go bindings only, possibly by injecting it through the gen-proto target in crit/Makefile with something like:

ls crit/images/*.proto | xargs sed -i '/syntax/a package checkpoint.restore;\n'

@adrianreber
Copy link
Member

If that works. That sounds much cleaner to me.

@snprajwal snprajwal force-pushed the proto-rename branch 2 times, most recently from 999ed5b to 6473aca Compare September 5, 2022 10:00
@snprajwal snprajwal changed the title fix(crit): rename sa.proto and core.proto Add package name to crit protobuf files Sep 5, 2022
@adrianreber
Copy link
Member

Looking at the change now, especially with a possible integration of this change in the main CRIU repository, I think criu as package name would make more sense than checkpoint.restore as all files are from the CRIU repository/project.

@snprajwal
Copy link
Member Author

@adrianreber that was indeed my first thought too, but we cannot use package criu as it conflicts with the criu field in opts.proto.

@adrianreber
Copy link
Member

@adrianreber that was indeed my first thought too, but we cannot use package criu as it conflicts with the criu field in opts.proto.

What is the error message you get?

@snprajwal
Copy link
Member Author

What is the error message you get?

Something along the lines of criu has already been declared. Oddly enough, I tried it again now, and it works 🤔 will change and push

To prevent namespace conflicts against protobuf files
from other projects, the files of this repository are
now registered under the package name `criu`.

Signed-off-by: Prajwal S N <[email protected]>
@adrianreber
Copy link
Member

What is the error message you get?

Something along the lines of criu has already been declared. Oddly enough, I tried it again now, and it works thinking will change and push

😄 I also tried it and it was working, that's why I asked. Good to see that it works now.

@adrianreber
Copy link
Member

This PR works for me. @rst0git what do you think.

At some point we can try to push this change to CRIU and remove the sed line here.

Copy link
Member

@rst0git rst0git left a comment

Choose a reason for hiding this comment

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

LGTM

@rst0git rst0git merged commit 53fb11a into checkpoint-restore:master Sep 5, 2022
@snprajwal snprajwal deleted the proto-rename branch September 6, 2022 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants