Skip to content

Commit

Permalink
Move protobuf generation/configuration to buf (#1833)
Browse files Browse the repository at this point in the history
https://docs.buf.build/

Buf is the successor to https://github.com/uber/prototool which we
already use for linting.

This dramatically simplifies our Makefiles, which are both extremely
complicated and have led to numerous bugs historically, such as
#1678.

This will make changes to the generation much simpler as well. For
example, to migrate to gogo protobuf, we will just need to change `gogo`
-> `go` in one location, rather than trying to wrangle 500 lines of
Makefiles. Additionally, its quite a bit faster - the whole proto stuff
is done in <1s now.
  • Loading branch information
howardjohn authored Jan 29, 2021
1 parent bf37a09 commit 2bcca53
Show file tree
Hide file tree
Showing 66 changed files with 2,982 additions and 4,044 deletions.
443 changes: 13 additions & 430 deletions Makefile.core.mk

Large diffs are not rendered by default.

102 changes: 51 additions & 51 deletions authentication/v1alpha1/policy.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions buf.gen-noncrd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: v1beta1
plugins:
- name: gogofast
out: .
opt: plugins=grpc,paths=source_relative,Mgogoproto/gogo.proto=github.com/gogo/protobuf/gogoproto,Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/descriptor.proto=github.com/gogo/protobuf/protoc-gen-gogo/descriptor,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/rpc/status.proto=istio.io/gogo-genproto/googleapis/google/rpc,Mgoogle/rpc/code.proto=istio.io/gogo-genproto/googleapis/google/rpc,Mgoogle/rpc/error_details.proto=istio.io/gogo-genproto/googleapis/google/rpc,Mgoogle/api/field_behavior.proto=istio.io/gogo-genproto/googleapis/google/api
- name: docs
out: .
opt: warnings=false,dictionary=./dictionaries/en-US,custom_word_list=./dictionaries/custom.txt,per_file=true,mode=html_fragment_with_front_matter
- name: python
out: python/istio_api
19 changes: 19 additions & 0 deletions buf.gen.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: v1beta1
build:
roots:
- .
25 changes: 25 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Copyright Istio Authors

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu

PATTERNS="_deepcopy.gen.go .gen.json .pb.go .pb.html _json.gen.go customresourcedefinitions.gen.yaml"
shopt -s globstar

for p in $PATTERNS; do
rm -f ./**/*"${p}"
done
rm -rf python/istio_api
43 changes: 43 additions & 0 deletions gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

# Copyright Istio Authors

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu

# Generate all protos
buf generate \
--path networking \
--path security \
--path type \
--path analysis \
--path authentication \
--path meta

# These folders do not have the full plugins used, as they are not full CRDs.
# We pass them a custom configuration to exclude the non-required files
buf generate --template buf.gen-noncrd.yaml \
--path operator \
--path mcp \
--path mesh

# Custom hacks to post-process some outputs
go run ./operator/fixup_structs/main.go -f operator/v1alpha1/operator.pb.go
go run ./operator/fixup_structs/main.go -f mesh/v1alpha1/config.pb.go
go run ./operator/fixup_structs/main.go -f mesh/v1alpha1/network.pb.go
go run ./operator/fixup_structs/main.go -f mesh/v1alpha1/proxy.pb.go

# Generate CRDs and open-api schema
cue-gen -paths=common-protos -f=./cue.yaml
cue-gen -paths=common-protos -f=./cue.yaml --crd=true -snake=jwksUri,apiKeys,apiSpecs,includedPaths,jwtHeaders,triggerRules,excludedPaths,mirrorPercent
1 change: 1 addition & 0 deletions github.com
1 change: 1 addition & 0 deletions gogoproto
1 change: 1 addition & 0 deletions google
1 change: 1 addition & 0 deletions istio.io
1 change: 1 addition & 0 deletions k8s.io
2 changes: 2 additions & 0 deletions mcp/v1alpha1/mcp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

syntax = "proto3";

// $mode: none

package istio.mcp.v1alpha1;

import "google/rpc/status.proto";
Expand Down
Loading

0 comments on commit 2bcca53

Please sign in to comment.