Skip to content

Commit

Permalink
Switch to gogo/protobuf for golang code generation in order to use go…
Browse files Browse the repository at this point in the history
…go extensions
  • Loading branch information
jessesuen committed Apr 24, 2018
1 parent 63dafa0 commit 36b3b2b
Show file tree
Hide file tree
Showing 15 changed files with 6,284 additions and 483 deletions.
3 changes: 2 additions & 1 deletion Gopkg.lock

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

1 change: 1 addition & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
required = [
"github.com/gogo/protobuf/protoc-gen-gofast",
"github.com/gogo/protobuf/protoc-gen-gogofast",
"golang.org/x/sync/errgroup",
"k8s.io/code-generator/cmd/go-to-protobuf",
]
Expand Down
9 changes: 6 additions & 3 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ func NewApplicationListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
// NewApplicationSyncCommand returns a new instance of an `argocd app sync` command
func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
var (
dryRun bool
revision string
dryRun bool
)
var command = &cobra.Command{
Use: "sync",
Expand All @@ -359,8 +360,9 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
defer util.Close(conn)
appName := args[0]
syncReq := application.ApplicationSyncRequest{
Name: appName,
DryRun: dryRun,
Name: appName,
DryRun: dryRun,
Revision: revision,
}
syncRes, err := appIf.Sync(context.Background(), &syncReq)
errors.CheckError(err)
Expand All @@ -374,6 +376,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
},
}
command.Flags().BoolVar(&dryRun, "dry-run", false, "Preview apply without affecting cluster")
command.Flags().StringVar(&revision, "revision", "", "Sync to a specific revision. Preserves parameter overrides")
return command
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/argocd/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewVersionCmd(clientOpts *argocdclient.ClientOptions) *cobra.Command {
defer util.Close(conn)
serverVers, err := versionIf.Version(context.Background(), &empty.Empty{})
errors.CheckError(err)
fmt.Printf("%s: %s\n", "argocd-server", version)
fmt.Printf("%s: %s\n", "argocd-server", serverVers.Version)
if !short {
fmt.Printf(" BuildDate: %s\n", serverVers.BuildDate)
fmt.Printf(" GitCommit: %s\n", serverVers.GitCommit)
Expand Down
18 changes: 13 additions & 5 deletions hack/generate-proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,26 @@ go-to-protobuf \
--apimachinery-packages=$(IFS=, ; echo "${APIMACHINERY_PKGS[*]}") \
--proto-import=./vendor

# protoc-gen-go or protoc-gen-gofast is used to build server/*/<service>.pb.go from .proto files
# NOTE: it is possible to use golang/protobuf or gogo/protobuf interchangeably
go build -i -o dist/protoc-gen-gofast ./vendor/github.com/gogo/protobuf/protoc-gen-gofast
# Either protoc-gen-go, protoc-gen-gofast, or protoc-gen-gogofast can be used to build
# server/*/<service>.pb.go from .proto files. golang/protobuf and gogo/protobuf can be used
# interchangeably. The difference in the options are:
# 1. protoc-gen-go - official golang/protobuf
#go build -i -o dist/protoc-gen-go ./vendor/github.com/golang/protobuf/protoc-gen-go
#GOPROTOBINARY=go
# 2. protoc-gen-gofast - fork of golang golang/protobuf. Faster code generation
#go build -i -o dist/protoc-gen-gofast ./vendor/github.com/gogo/protobuf/protoc-gen-gofast
#GOPROTOBINARY=gofast
# 3. protoc-gen-gogofast - faster code generation and gogo extensions and flexibility in controlling
# the generated go code (e.g. customizing field names, nullable fields)
go build -i -o dist/protoc-gen-gogofast ./vendor/github.com/gogo/protobuf/protoc-gen-gogofast
GOPROTOBINARY=gogofast

# protoc-gen-grpc-gateway is used to build <service>.pb.gw.go files from from .proto files
go build -i -o dist/protoc-gen-grpc-gateway ./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway

# Generate server/<service>/(<service>.pb.go|<service>.pb.gw.go)
PROTO_FILES=$(find $PROJECT_ROOT \( -name "*.proto" -and -path '*/server/*' -or -path '*/reposerver/*' -and -name "*.proto" \))
for i in ${PROTO_FILES}; do

# Path to the google API gateway annotations.proto will be different depending if we are
# building natively (e.g. from workspace) vs. part of a docker build.
if [ -f /.dockerenv ]; then
Expand All @@ -67,7 +75,7 @@ for i in ${PROTO_FILES}; do
-I$GOPATH/src \
-I${GOOGLE_PROTO_API_PATH} \
-I${GOGO_PROTOBUF_PATH} \
--go_out=plugins=grpc:$GOPATH/src \
--${GOPROTOBINARY}_out=plugins=grpc:$GOPATH/src \
--grpc-gateway_out=logtostderr=true:$GOPATH/src \
$i
done
58 changes: 29 additions & 29 deletions pkg/apis/application/v1alpha1/generated.pb.go

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

2 changes: 1 addition & 1 deletion pkg/apis/application/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type DeploymentInfo struct {
Revision string `json:"revision" protobuf:"bytes,2,opt,name=revision"`
ComponentParameterOverrides []ComponentParameter `json:"componentParameterOverrides,omitempty" protobuf:"bytes,3,opt,name=componentParameterOverrides"`
DeployedAt metav1.Time `json:"deployedAt" protobuf:"bytes,4,opt,name=deployedAt"`
Id int64 `json:"id" protobuf:"bytes,5,opt,name=id"`
ID int64 `json:"id" protobuf:"bytes,5,opt,name=id"`
}

// Application is a definition of Application resource.
Expand Down
Loading

0 comments on commit 36b3b2b

Please sign in to comment.