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

chore: migrate to the latest version of go-control-plane and use golang/protobuf instead of gogo/protobuf #419

Merged
merged 2 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
start/k8s start/kind start/control-plane/k8s \
deploy/example-app/k8s deploy/control-plane/k8s \
kind/load/control-plane kind/load/kuma-dp kind/load/kuma-injector \
generate protoc/pkg/config/app/kumactl/v1alpha1 generate/kumactl/install/control-plane \
generate protoc/pkg/config/app/kumactl/v1alpha1 protoc/pkg/test/apis/sample/v1alpha1 generate/kumactl/install/control-plane \
fmt fmt/go fmt/proto vet golangci-lint check test integration build run/k8s run/universal/memory run/universal/postgres \
images image/kuma-cp image/kuma-dp image/kumactl image/kuma-injector image/kuma-tcp-echo \
docker/build docker/build/kuma-cp docker/build/kuma-dp docker/build/kumactl docker/build/kuma-injector docker/build/kuma-tcp-echo \
Expand Down Expand Up @@ -106,7 +106,7 @@ endif

PROTOC_VERSION := 3.6.1
PROTOC_PGV_VERSION := v0.1.0
GOGO_PROTOBUF_VERSION := v1.2.1
GOLANG_PROTOBUF_VERSION := v1.3.2
GOLANGCI_LINT_VERSION := v1.21.0

CI_KUBEBUILDER_VERSION ?= 2.0.0
Expand All @@ -123,6 +123,7 @@ BUILD_KUMACTL_DIR := ${BUILD_ARTIFACTS_DIR}/kumactl
export PATH := $(BUILD_KUMACTL_DIR):$(CI_TOOLS_DIR):$(GOPATH_BIN_DIR):$(PATH)

PROTOC_PATH := $(CI_TOOLS_DIR)/protoc
PROTOBUF_WKT_DIR := $(CI_TOOLS_DIR)/protobuf.d
KUBEBUILDER_DIR := $(CI_TOOLS_DIR)/kubebuilder.d
KUBEBUILDER_PATH := $(CI_TOOLS_DIR)/kubebuilder
KUSTOMIZE_PATH := $(CI_TOOLS_DIR)/kustomize
Expand All @@ -136,17 +137,18 @@ GOLANGCI_LINT_DIR := $(CI_TOOLS_DIR)
PROTO_DIR := ./pkg/config

protoc_search_go_packages := \
github.com/gogo/protobuf@$(GOGO_PROTOBUF_VERSION)/protobuf \
github.com/golang/protobuf@$(GOLANG_PROTOBUF_VERSION) \
github.com/envoyproxy/protoc-gen-validate@$(PROTOC_PGV_VERSION) \

protoc_search_go_paths := $(foreach go_package,$(protoc_search_go_packages),--proto_path=$(GOPATH_DIR)/pkg/mod/$(go_package))

# Protobuf-specifc configuration
PROTOC_GO := protoc \
--proto_path=$(PROTOBUF_WKT_DIR)/include \
--proto_path=. \
$(protoc_search_go_paths) \
--gogofast_out=plugins=grpc:. \
--validate_out=lang=gogo:.
--go_out=plugins=grpc:. \
--validate_out=lang=go:.

PROTOC_OS=unknown
PROTOC_ARCH=$(shell uname -m)
Expand Down Expand Up @@ -217,11 +219,14 @@ clean/proto: ## Dev: Remove auto-generated Protobuf files
find $(PROTO_DIR) -name '*.pb.go' -delete
find $(PROTO_DIR) -name '*.pb.validate.go' -delete

generate: clean/proto protoc/pkg/config/app/kumactl/v1alpha1 ## Dev: Run code generators
generate: clean/proto protoc/pkg/config/app/kumactl/v1alpha1 protoc/pkg/test/apis/sample/v1alpha1 ## Dev: Run code generators

protoc/pkg/config/app/kumactl/v1alpha1:
$(PROTOC_GO) pkg/config/app/kumactl/v1alpha1/*.proto

protoc/pkg/test/apis/sample/v1alpha1:
$(PROTOC_GO) pkg/test/apis/sample/v1alpha1/*.proto

# Notice that this command is not include into `make generate` by intention (since generated code differes between dev host and ci server)
generate/kumactl/install/control-plane:
go generate ./app/kumactl/pkg/install/k8s/control-plane/...
Expand Down
24 changes: 20 additions & 4 deletions Makefile.dev.mk
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
.PHONY: dev/tools dev/tools/all \
dev/install/protoc dev/install/protoc-gen-gogofast dev/install/protoc-gen-validate \
dev/install/protoc dev/install/protobuf-wellknown-types \
dev/install/protoc-gen-go dev/install/protoc-gen-validate \
dev/install/ginkgo \
dev/install/kubebuilder dev/install/kustomize \
dev/install/kubectl dev/install/kind dev/install/minikube \
dev/install/golangci-lint

dev/tools: dev/tools/all ## Bootstrap: Install all development tools

dev/tools/all: dev/install/protoc dev/install/protoc-gen-gogofast dev/install/protoc-gen-validate \
dev/tools/all: dev/install/protoc dev/install/protobuf-wellknown-types \
dev/install/protoc-gen-go dev/install/protoc-gen-validate \
dev/install/ginkgo \
dev/install/kubebuilder dev/install/kustomize \
dev/install/kubectl dev/install/kind dev/install/minikube \
Expand All @@ -27,8 +29,22 @@ dev/install/protoc: ## Bootstrap: Install Protoc (protobuf compiler)
&& set +x \
&& echo "Protoc $(PROTOC_VERSION) has been installed at $(PROTOC_PATH)" ; fi

dev/install/protoc-gen-gogofast: ## Bootstrap: Install Protoc Go Plugin (protobuf Go generator)
go get -u github.com/gogo/protobuf/protoc-gen-gogofast@$(GOGO_PROTOBUF_VERSION)
dev/install/protobuf-wellknown-types:: ## Bootstrap: Install Protobuf well-known types
@if [ -e $(PROTOBUF_WKT_DIR) ]; then echo "Protobuf well-known types are already installed at $(PROTOBUF_WKT_DIR)" ; fi
@if [ ! -e $(PROTOBUF_WKT_DIR) ]; then \
echo "Installing Protobuf well-known types $(PROTOC_VERSION) ..." \
&& set -x \
&& curl -Lo /tmp/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH).zip https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH).zip \
&& unzip /tmp/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH).zip 'include/*' -d /tmp/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH) \
&& mkdir -p $(PROTOBUF_WKT_DIR) \
&& cp -r /tmp/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH)/include $(PROTOBUF_WKT_DIR) \
&& rm -rf /tmp/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH) \
&& rm /tmp/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH).zip \
&& set +x \
&& echo "Protobuf well-known types $(PROTOC_VERSION) have been installed at $(PROTOBUF_WKT_DIR)" ; fi

dev/install/protoc-gen-go: ## Bootstrap: Install Protoc Go Plugin (protobuf Go generator)
go get -u github.com/golang/protobuf/protoc-gen-go@$(GOLANG_PROTOBUF_VERSION)

dev/install/protoc-gen-validate: ## Bootstrap: Install Protoc Gen Validate Plugin (protobuf validation code generator)
go get -u github.com/envoyproxy/protoc-gen-validate@$(PROTOC_PGV_VERSION)
Expand Down
49 changes: 32 additions & 17 deletions api/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: help clean generate build test check \
dev/tools install/protoc install/protoc-gen-gogofast install/protoc-gen-validate \
dev/tools install/protoc install/protobuf-wellknown-types install/protoc-gen-go install/protoc-gen-validate \
protoc protoc/discovery/v1alpha1 protoc/mesh/v1alpha1

TOOLS_DIR ?= $(HOME)/bin
Expand All @@ -8,38 +8,39 @@ GOPATH_BIN_DIR := $(GOPATH_DIR)/bin
export PATH := $(TOOLS_DIR):$(GOPATH_BIN_DIR):$(PATH)

PROTOC_PATH := $(TOOLS_DIR)/protoc
PROTOBUF_WKT_DIR := $(TOOLS_DIR)/protobuf.d

PROTOC_VERSION := 3.6.1
PROTOC_PGV_VERSION := v0.1.0
GOGO_PROTOBUF_VERSION := v1.2.1
GOLANG_PROTOBUF_VERSION := v1.3.2

protoc_search_go_packages := \
github.com/gogo/protobuf@$(GOGO_PROTOBUF_VERSION) \
github.com/gogo/protobuf@$(GOGO_PROTOBUF_VERSION)/protobuf \
github.com/golang/protobuf@$(GOLANG_PROTOBUF_VERSION) \
github.com/envoyproxy/protoc-gen-validate@$(PROTOC_PGV_VERSION) \

protoc_search_go_paths := $(foreach go_package,$(protoc_search_go_packages),--proto_path=$(GOPATH_DIR)/pkg/mod/$(go_package))

gogo_import_mapping_entries := \
google/protobuf/any.proto=github.com/gogo/protobuf/types \
google/protobuf/duration.proto=github.com/gogo/protobuf/types \
google/protobuf/struct.proto=github.com/gogo/protobuf/types \
google/protobuf/timestamp.proto=github.com/gogo/protobuf/types \
google/protobuf/wrappers.proto=github.com/gogo/protobuf/types \
go_import_mapping_entries := \
google/protobuf/any.proto=github.com/golang/protobuf/ptypes/any \
google/protobuf/duration.proto=github.com/golang/protobuf/ptypes/duration \
google/protobuf/struct.proto=github.com/golang/protobuf/ptypes/struct \
google/protobuf/timestamp.proto=github.com/golang/protobuf/ptypes/timestamp \
google/protobuf/wrappers.proto=github.com/golang/protobuf/ptypes/wrappers \

# see https://makefiletutorial.com/
comma := ,
empty:=
space := $(empty) $(empty)

gogo_mapping_with_spaces := $(foreach entry,$(gogo_import_mapping_entries),M$(entry),)
gogo_mapping := $(subst $(space),$(empty),$(gogo_mapping_with_spaces))
go_mapping_with_spaces := $(foreach entry,$(go_import_mapping_entries),M$(entry),)
go_mapping := $(subst $(space),$(empty),$(go_mapping_with_spaces))

PROTOC_GO := protoc \
--proto_path=$(PROTOBUF_WKT_DIR)/include \
--proto_path=. \
$(protoc_search_go_paths) \
--gogofast_out=plugins=grpc,$(gogo_mapping):. \
--validate_out=lang=gogo:.
--go_out=plugins=grpc,$(go_mapping):. \
--validate_out=lang=go:.

PROTOC_OS=unknown
PROTOC_ARCH=$(shell uname -m)
Expand All @@ -56,7 +57,7 @@ endif
help: ## Display this help screen
@grep -h -E '^[a-zA-Z_/-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

dev/tools: install/protoc install/protoc-gen-gogofast install/protoc-gen-validate ## Install development tools
dev/tools: install/protoc install/protobuf-wellknown-types install/protoc-gen-go install/protoc-gen-validate ## Install development tools

install/protoc:
@if [ -e $(PROTOC_PATH) ]; then echo "Protoc $$( $(PROTOC_PATH) --version ) is already installed at $(PROTOC_PATH)" ; fi
Expand All @@ -72,8 +73,22 @@ install/protoc:
&& set +x \
&& echo "Protoc $(PROTOC_VERSION) has been installed at $(PROTOC_PATH)" ; fi

install/protoc-gen-gogofast:
go get -u github.com/gogo/protobuf/protoc-gen-gogofast@$(GOGO_PROTOBUF_VERSION)
install/protobuf-wellknown-types:
@if [ -e $(PROTOBUF_WKT_DIR) ]; then echo "Protobuf well-known types are already installed at $(PROTOBUF_WKT_DIR)" ; fi
@if [ ! -e $(PROTOBUF_WKT_DIR) ]; then \
echo "Installing Protobuf well-known types $(PROTOC_VERSION) ..." \
&& set -x \
&& curl -Lo /tmp/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH).zip https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH).zip \
&& unzip /tmp/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH).zip 'include/*' -d /tmp/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH) \
&& mkdir -p $(PROTOBUF_WKT_DIR) \
&& cp -r /tmp/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH)/include $(PROTOBUF_WKT_DIR) \
&& rm -rf /tmp/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH) \
&& rm /tmp/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH).zip \
&& set +x \
&& echo "Protobuf well-known types $(PROTOC_VERSION) have been installed at $(PROTOBUF_WKT_DIR)" ; fi

install/protoc-gen-go:
go get -u github.com/golang/protobuf/protoc-gen-go@$(GOLANG_PROTOBUF_VERSION)

install/protoc-gen-validate:
go get -u github.com/envoyproxy/protoc-gen-validate@$(PROTOC_PGV_VERSION)
Expand Down
Loading