Skip to content

Commit df82b76

Browse files
authored
Update Protobuf dependencies for code generation (#6130)
This removes our direct dependency on github.com/golang/protobuf, which has been superseded by google.golang.org/protobuf. Some notable changes since the last time we updated: * The versioning scheme for Protobuf has changed (see https://protobuf.dev/support/version-support/) * The Golang gRPC code generator is now a standalone tool (protoc-gen-go-grpc) and is no longer included as a plugin in protoc-gen-go. With protoc-gen-go-grpc, the service implementations must embed the corresponding `Unimplemented<ServiceName>Server` for future compatibility (which we are now doing for `CNIServer`). A new codegen image is released: antrea/codegen:kubernetes-1.29.2-build.0 New versions: * protoc: v26.0 * protoc-gen-go: v1.33.0 * protoc-gen-go-grpc: v1.3.0 In our case, we don't have to worry about client-server compatibility, given that antrea-cni (client) is always reinstalled by the antrea-agent Pod. Even if it was a concern for us, there has been no change in the Protobuf wire format. Signed-off-by: Antonin Bas <[email protected]>
1 parent a177044 commit df82b76

File tree

10 files changed

+222
-172
lines changed

10 files changed

+222
-172
lines changed

build/images/codegen/Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ FROM ubuntu:22.04 as protoc
1818
RUN apt-get update && \
1919
apt-get install -y --no-install-recommends wget ca-certificates unzip
2020

21-
RUN PROTOBUF_VERSION=3.0.2; ZIPNAME="protoc-${PROTOBUF_VERSION}-linux-x86_64.zip"; \
21+
RUN PROTOBUF_VERSION=26.0; ZIPNAME="protoc-${PROTOBUF_VERSION}-linux-x86_64.zip"; \
2222
mkdir /tmp/protoc && cd /tmp/protoc && \
2323
wget "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/${ZIPNAME}" && \
2424
unzip "${ZIPNAME}" && \
@@ -47,7 +47,8 @@ RUN go install k8s.io/code-generator/cmd/client-gen@kubernetes-$K8S_VERSION && \
4747
go install k8s.io/code-generator/cmd/go-to-protobuf@kubernetes-$K8S_VERSION && \
4848
go install k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo@kubernetes-$K8S_VERSION && \
4949
go install go.uber.org/mock/[email protected] && \
50-
go install github.com/golang/protobuf/[email protected] && \
50+
go install google.golang.org/protobuf/cmd/[email protected] && \
51+
go install google.golang.org/grpc/cmd/[email protected] && \
5152
go install golang.org/x/tools/cmd/goimports@latest && \
5253
go install sigs.k8s.io/controller-tools/cmd/[email protected]
5354

build/images/codegen/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ docker push antrea/codegen:<TAG>
1616
The `docker push` command will fail if you do not have permission to push to the
1717
`antrea` Dockerhub repository.
1818

19+
The image can only be built on an x86_64 machine (no arm support).
20+
1921
Here is the table of codegen images that have been uploaded:
2022

2123
| Tag | Change |
2224
| :----------------------------- | ---------------------------------------------------- |
25+
| kubernetes-1.29.2-build.0 | Upgraded protoc (v26.0), protoc-gen-go (v1.33.0), protoc-gen-go-grpc (v1.3.0) |
2326
| kubernetes-1.29.2 | Upgraded K8s libraries to v1.29.2 |
2427
| kubernetes-1.26.4-build.1 | Replace github.com/golang/mock with go.uber.org/mock |
2528
| kubernetes-1.26.4-build.0 | Upgraded Go to v1.21 |

docs/contributors/code-generation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
## CNI
44

5-
Antrea uses [protoc](https://github.com/protocolbuffers/protobuf) and [protoc-gen-go](
6-
https://github.com/golang/protobuf) to generate CNI gRPC service code.
5+
Antrea uses [protoc](https://github.com/protocolbuffers/protobuf), [protoc-gen-go](https://github.com/protocolbuffers/protobuf-go)
6+
and [protoc-gen-go-grpc](https://github.com/grpc/grpc-go) to generate CNI gRPC service code.
77

88
If you make any change to [cni.proto](../../pkg/apis/cni/v1beta1/cni.proto), you can
99
re-generate the code by invoking `make codegen`.

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ require (
2626
github.com/gammazero/deque v0.1.2
2727
github.com/go-logr/logr v1.4.1
2828
github.com/gogo/protobuf v1.3.2
29-
github.com/golang/protobuf v1.5.3
3029
github.com/google/btree v1.1.2
3130
github.com/google/uuid v1.6.0
3231
github.com/hashicorp/memberlist v0.5.1
@@ -139,6 +138,7 @@ require (
139138
github.com/go-openapi/swag v0.22.3 // indirect
140139
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
141140
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
141+
github.com/golang/protobuf v1.5.3 // indirect
142142
github.com/google/cel-go v0.17.7 // indirect
143143
github.com/google/gnostic-models v0.6.8 // indirect
144144
github.com/google/go-cmp v0.6.0 // indirect

hack/update-codegen-dockerized.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fi
8585

8686
function generate_antrea_client_code {
8787
# Generate protobuf code for CNI gRPC service with protoc.
88-
protoc --go_out=plugins=grpc:. pkg/apis/cni/v1beta1/cni.proto
88+
protoc --go_out=. --go-grpc_out=. pkg/apis/cni/v1beta1/cni.proto
8989

9090
# Generate clientset and apis code with K8s codegen tools.
9191
$GOPATH/bin/client-gen \

hack/update-codegen.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set -o errexit
1818
set -o pipefail
1919

2020
ANTREA_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
21-
IMAGE_NAME="antrea/codegen:kubernetes-1.29.2"
21+
IMAGE_NAME="antrea/codegen:kubernetes-1.29.2-build.0"
2222

2323
# Recent versions of Git will not access .git directories which are owned by
2424
# another user (as a security measure), unless the directories are explicitly

multicluster/hack/update-codegen.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set -o errexit
1818
set -o pipefail
1919

2020
ANTREA_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../../" && pwd )"
21-
IMAGE_NAME="antrea/codegen:kubernetes-1.29.2"
21+
IMAGE_NAME="antrea/codegen:kubernetes-1.29.2-build.0"
2222

2323
# Recent versions of Git will not access .git directories which are owned by
2424
# another user (as a security measure), unless the directories are explicitly

pkg/agent/cniserver/server.go

+5
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ func (arbitrator *containerAccessArbitrator) unlockContainer(containerKey string
102102
}
103103

104104
type CNIServer struct {
105+
// CNIServer must embed UnimplementedCniServer. It is required by the code generated by
106+
// protoc-gen-go-grpc (although it is possible to opt-out). It technically enables
107+
// forward-compatibility when new methods are added to the gRPC service but are not
108+
// implemented yet.
109+
cnipb.UnimplementedCniServer
105110
cniSocket string
106111
serverVersion string
107112
nodeConfig *config.NodeConfig

pkg/apis/cni/v1beta1/cni.pb.go

+8-164
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)