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 python binding #26

Merged
merged 5 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
.PHONY: compile
PROTOC_GEN_GO := $(GOPATH)/bin/protoc-gen-go
PROTOC := $(shell which protoc)
# If protoc isn't on the path, set it to a target that's never up to date, so
MOCKGEN := $(shell which mockgen)

# Make it always try to install the packages,
# since pip checks if the package is installed
PY_GRPC_TOOLS := must-install

# If protoc isn't on the path, set it to a target that's never up-to-date, so
# the install command always runs.
ifeq ($(PROTOC),)
PROTOC = must-rebuild
endif

# Same as PROTOC
ifeq ($(MOCKGEN),)
MOCKGEN = must-rebuild
endif

# Figure out which machine we're running on.
UNAME := $(shell uname)

Expand All @@ -26,11 +37,22 @@ endif
$(PROTOC_GEN_GO):
go get -u github.com/golang/protobuf/protoc-gen-go

generate: protos | $(PROTOC_GEN_GO) $(PROTOC)
protoc --proto_path=protos --go_out=pbgo --go_opt=paths=source_relative \
--go-grpc_out=pbgo --go-grpc_opt=paths=source_relative \
protos/*.proto
$(MOCKGEN):
go get -u github.com/golang/mock/mockgen

$(PY_GRPC_TOOLS):
pip3 install grpcio grpcio-tools

generate: protos | $(PROTOC_GEN_GO) $(PROTOC) $(PY_GRPC_TOOLS)
protoc --proto_path=protos --go_out=tks_pb --go_opt=paths=source_relative \
--go-grpc_out=tks_pb --go-grpc_opt=paths=source_relative protos/*.proto
python3 -m grpc_tools.protoc -I./protos --python_out=./tks_pb_python --grpc_python_out=./tks_pb_python protos/*.proto

generate-mock: $(MOCKGEN)
mockgen -source=tks_pb/cluster_lcm_grpc.pb.go > tks_pb/mock/mock_cluster_lcm_grpc.pb.go
mockgen -source=tks_pb/contract_grpc.pb.go > tks_pb/mock/mock_contract_grpc.pb.go
mockgen -source=tks_pb/info_grpc.pb.go > tks_pb/mock/mock_info_grpc.pb.go

ktkfree marked this conversation as resolved.
Show resolved Hide resolved
# This is a "phony" target - an alias for the above command, so "make build"
# still works.
build: generate
build: generate generate-mock
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
# TKS-proto
TKS-proto contains `.pb.go` files and protocol buffers for TKS services.
TKS-proto contains protocol buffer definition and gRPC output files for TKS services.

## Getting Started
### Add new .proto
`.proto` files are located under `protos/` directory.
Please make and write new `.proto` file following the [Style Guide](https://developers.google.com/protocol-buffers/docs/style).

### Generate .pb.go files
You can easily generate `.pb.go` files using `make build` command.
If there are no errors, `.pb.go` files would be generated in `pbgo/` directory.
### Generate gRPC output files
You can easily generate output files for golang and python by running `make build` command.
```console
$ make build
go get -u github.com/golang/protobuf/protoc-gen-go
protoc --proto_path=protos --go_out=pbgo --go_opt=paths=source_relative protos/*.proto
protoc --proto_path=protos --go_out=tks_pb --go_opt=paths=source_relative \
--go-grpc_out=tks_pb --go-grpc_opt=paths=source_relative protos/*.proto
python3 -m grpc_tools.protoc -I./protos --python_out=./tks_pb_python --grpc_python_out=./tks_pb_python protos/*.proto
mockgen -source=tks_pb/cluster_lcm_grpc.pb.go > tks_pb/mock/mock_cluster_lcm_grpc.pb.go
mockgen -source=tks_pb/contract_grpc.pb.go > tks_pb/mock/mock_contract_grpc.pb.go
mockgen -source=tks_pb/info_grpc.pb.go > tks_pb/mock/mock_info_grpc.pb.go

$ ls pbgo
common.pb.go contract.pb.go
$ ls tks_pb
cluster_lcm.pb.go common.pb.go contract_grpc.pb.go info_grpc.pb.go
cluster_lcm_grpc.pb.go contract.pb.go info.pb.go mock

$ ls tks_pb_python
cluster_lcm_pb2.py common_pb2.py contract_pb2.py info_pb2.py
cluster_lcm_pb2_grpc.py common_pb2_grpc.py contract_pb2_grpc.py info_pb2_grpc.py
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ require (
github.com/golang/protobuf v1.5.2
google.golang.org/grpc v1.38.0 // indirect
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 // indirect
google.golang.org/protobuf v1.27.1
google.golang.org/protobuf v1.26.0
)
13 changes: 2 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.5.0 h1:jlYHihg//f7RRwuPfptm04yp4s7O6Kw8EZiVYIGcH0g=
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -45,16 +43,14 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -63,27 +59,24 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand All @@ -99,8 +92,6 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.38.0 h1:/9BgsAsa5nWe26HqOlvlgJnqBuktYOLCgjCPqsa56W0=
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 h1:M1YKkFIboKNieVO5DLUEVzQfGwJD30Nv2jfUgzb5UcE=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
4 changes: 2 additions & 2 deletions protos/cluster_lcm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
*/

syntax = "proto3";
package pbgo;
package tks_pb;

import "common.proto";

option go_package = "github.com/openinfradev/tks-proto/pbgo";
option go_package = "github.com/openinfradev/tks-proto/tks_pb";

// ClusterLcmService is a service to manage cluster's document.
service ClusterLcmService {
Expand Down
4 changes: 2 additions & 2 deletions protos/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
when communicating between TKS services.
*/
syntax = "proto3";
package pbgo;
package tks_pb;

import "google/protobuf/timestamp.proto";

option go_package = "github.com/openinfradev/tks-proto/pbgo";
option go_package = "github.com/openinfradev/tks-proto/tks_pb";

// Code is a response code for gRpc request.
enum Code {
Expand Down
4 changes: 2 additions & 2 deletions protos/contract.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
*/

syntax = "proto3";
package pbgo;
package tks_pb;

import "common.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/openinfradev/tks-proto/pbgo";
option go_package = "github.com/openinfradev/tks-proto/tks_pb";

// ContractService is a service to manage contract's document.
service ContractService {
Expand Down
6 changes: 3 additions & 3 deletions protos/info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
*/

syntax = "proto3";
package pbgo;
package tks_pb;

import "common.proto";
import "google/protobuf/empty.proto";

option go_package = "github.com/openinfradev/tks-proto/pbgo";
option go_package = "github.com/openinfradev/tks-proto/tks_pb";

// ClusterInfoService is a service to manage cluster info document.
service ClusterInfoService {
Expand Down Expand Up @@ -211,7 +211,7 @@ message UpdateAppGroupStatusRequest {
AppGroupStatus status = 2;
}

// UpdateAppRequest updates an information of application such as endpoints.
// UpdateAppRequest updates information of application such as endpoints.
message UpdateAppRequest {
// app_group_id is the application group id.
string app_group_id = 1;
Expand Down
Loading