diff --git a/.circleci/config.yml b/.circleci/config.yml index 43b04e70f23d..a076ca5551cc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,11 +3,11 @@ version: 2.1 # Adds support for executors, parameterized jobs, etc reusable: constants: - - &go_version "1.12.12" + - &go_version "1.14.2" docker_images: - - &golang_image "golang:1.12.12" - - &circleci_golang_image "circleci/golang:1.12" + - &golang_image "golang:1.14.2" + - &circleci_golang_image "circleci/golang:1.14.2" vm_images: - &ubuntu_vm_image "ubuntu-1604:201903-01" diff --git a/Makefile b/Makefile index 7bb89e44217f..43d25fabc297 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ print/kubebuilder/test_assets \ run/kuma-dp -PKG_LIST := ./... ./api/... ./pkg/plugins/resources/k8s/native/... +PKG_LIST := ./... BUILD_INFO_GIT_TAG ?= $(shell git describe --tags 2>/dev/null || echo unknown) BUILD_INFO_GIT_COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo unknown) @@ -29,9 +29,10 @@ build_info_ld_flags := $(foreach entry,$(build_info_fields), -X github.com/Kong/ LD_FLAGS := -ldflags="-s -w $(build_info_ld_flags)" GOOS := $(shell go env GOOS) GOARCH := $(shell go env GOARCH) -GO_BUILD := GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -v $(LD_FLAGS) +GOFLAGS := -mod=mod +GO_BUILD := GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -v $(GOFLAGS) $(LD_FLAGS) GO_RUN := CGO_ENABLED=0 go run $(LD_FLAGS) -GO_TEST := go test $(LD_FLAGS) +GO_TEST := go test $(GOFLAGS) $(LD_FLAGS) BUILD_DIR ?= build BUILD_ARTIFACTS_DIR ?= $(BUILD_DIR)/artifacts-${GOOS}-${GOARCH} @@ -103,14 +104,14 @@ else endif PROTOC_VERSION := 3.6.1 -PROTOC_PGV_VERSION := v0.3.0-java +PROTOC_PGV_VERSION := v0.3.0-java.0.20200311152155-ab56c3dd1cf9 GOLANG_PROTOBUF_VERSION := v1.3.2 GOLANGCI_LINT_VERSION := v1.21.0 CI_KUBEBUILDER_VERSION ?= 2.0.0 CI_MINIKUBE_VERSION ?= v1.4.0 CI_KUBECTL_VERSION ?= v1.14.0 -CI_TOOLS_IMAGE ?= circleci/golang:1.12.12 +CI_TOOLS_IMAGE ?= circleci/golang:1.14.2 CI_TOOLS_DIR ?= $(HOME)/bin GOPATH_DIR := $(shell go env GOPATH | awk -F: '{print $$1}') @@ -213,7 +214,7 @@ generate/gui: ## Generate go files with GUI static files to embed it into binary fmt: fmt/go fmt/proto ## Dev: Run various format tools fmt/go: ## Dev: Run go fmt - go fmt ./... + go fmt $(GOFLAGS) ./... @# apparently, it's not possible to simply use `go fmt ./pkg/plugins/resources/k8s/native/...` make fmt -C pkg/plugins/resources/k8s/native @@ -221,7 +222,7 @@ fmt/proto: ## Dev: Run clang-format on .proto files which $(CLANG_FORMAT_PATH) && find . -name '*.proto' | xargs -L 1 $(CLANG_FORMAT_PATH) -i || true vet: ## Dev: Run go vet - go vet ./... + go vet $(GOFLAGS) ./... @# for consistency with `fmt` make vet -C pkg/plugins/resources/k8s/native @@ -235,24 +236,45 @@ check: generate fmt vet docs golangci-lint imports ## Dev: Run code checks (go f make generate manifests -C pkg/plugins/resources/k8s/native git diff --quiet || test $$(git diff --name-only | grep -v -e 'go.mod$$' -e 'go.sum$$' | wc -l) -eq 0 || ( echo "The following changes (result of code generators and code checks) have been detected:" && git --no-pager diff && false ) # fail if Git working tree is dirty -test: ## Dev: Run tests +test: ${COVERAGE_PROFILE} test/api test/k8s test/kuma coverage ## Dev: Run tests for all modules + +${COVERAGE_PROFILE}: mkdir -p "$(shell dirname "$(COVERAGE_PROFILE)")" + +coverage: ${COVERAGE_PROFILE} + GOFLAGS='${GOFLAGS}' go tool cover -html="$(COVERAGE_PROFILE)" -o "$(COVERAGE_REPORT_HTML)" + +test/kuma: # Dev: Run tests for the module github.com/Kong/kuma $(GO_TEST) $(GO_TEST_OPTS) -race -covermode=atomic -coverpkg=./... -coverprofile="$(COVERAGE_PROFILE)" $(PKG_LIST) - go tool cover -html="$(COVERAGE_PROFILE)" -o "$(COVERAGE_REPORT_HTML)" + +test/api: \ + MODULE=./api \ + COVERAGE_PROFILE=../$(BUILD_COVERAGE_DIR)/coverage-api.out +test/api: test/module + +test/k8s: \ + MODULE=./pkg/plugins/resources/k8s/native \ + COVERAGE_PROFILE=../../../../../$(BUILD_COVERAGE_DIR)/coverage-k8s.out +test/k8s: test/module + +test/module: + GO_TEST='${GO_TEST}' GO_TEST_OPTS='${GO_TEST_OPTS}' COVERAGE_PROFILE='${COVERAGE_PROFILE}' make test -C ${MODULE} test/kuma-cp: PKG_LIST=./app/kuma-cp/... ./pkg/config/app/kuma-cp/... -test/kuma-cp: test ## Dev: Run `kuma-cp` tests only +test/kuma-cp: test/kuma ## Dev: Run `kuma-cp` tests only test/kuma-dp: PKG_LIST=./app/kuma-dp/... ./pkg/config/app/kuma-dp/... -test/kuma-dp: test ## Dev: Run `kuma-dp` tests only +test/kuma-dp: test/kuma ## Dev: Run `kuma-dp` tests only test/kumactl: PKG_LIST=./app/kumactl/... ./pkg/config/app/kumactl/... -test/kumactl: test ## Dev: Run `kumactl` tests only +test/kumactl: test/kuma ## Dev: Run `kumactl` tests only -integration: ## Dev: Run integration tests +${COVERAGE_INTEGRATION_PROFILE}: mkdir -p "$(shell dirname "$(COVERAGE_INTEGRATION_PROFILE)")" + +integration: ${COVERAGE_INTEGRATION_PROFILE} ## Dev: Run integration tests tools/test/run-integration-tests.sh '$(GO_TEST) -race -covermode=atomic -tags=integration -count=1 -coverpkg=./... -coverprofile=$(COVERAGE_INTEGRATION_PROFILE) $(PKG_LIST)' - go tool cover -html="$(COVERAGE_INTEGRATION_PROFILE)" -o "$(COVERAGE_INTEGRATION_REPORT_HTML)" + GOFLAGS='${GOFLAGS}' go tool cover -html="$(COVERAGE_INTEGRATION_PROFILE)" -o "$(COVERAGE_INTEGRATION_REPORT_HTML)" build: build/kuma-cp build/kuma-dp build/kumactl build/kuma-prometheus-sd ## Dev: Build all binaries @@ -453,4 +475,4 @@ run/kuma-dp: ## Dev: Run `kuma-dp` locally include Makefile.kind.mk include Makefile.dev.mk -include Makefile.e2e.mk +include Makefile.e2e.mk \ No newline at end of file diff --git a/Makefile.dev.mk b/Makefile.dev.mk index 67a798e74cf4..7fdc0c5fb9ce 100644 --- a/Makefile.dev.mk +++ b/Makefile.dev.mk @@ -45,10 +45,10 @@ dev/install/protobuf-wellknown-types:: ## Bootstrap: Install Protobuf well-known && 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) + go get 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) + go get github.com/envoyproxy/protoc-gen-validate@$(PROTOC_PGV_VERSION) dev/install/ginkgo: ## Bootstrap: Install Ginkgo (BDD testing framework) # see https://github.com/onsi/ginkgo#set-me-up @@ -131,4 +131,4 @@ dev/install/golangci-lint: ## Bootstrap: Install golangci-lint curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOLANGCI_LINT_DIR) $(GOLANGCI_LINT_VERSION) dev/install/goimports: ## Bootstrap: Install goimports - go get -u golang.org/x/tools/cmd/goimports + go get golang.org/x/tools/cmd/goimports diff --git a/api/Makefile b/api/Makefile index 0776da6f19ae..1bdb9f290449 100644 --- a/api/Makefile +++ b/api/Makefile @@ -107,15 +107,15 @@ install/protobuf-wellknown-types: && 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) + go get 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) + go get github.com/envoyproxy/protoc-gen-validate@$(PROTOC_PGV_VERSION) install/data-plane-api: - go get -u github.com/envoyproxy/data-plane-api@$(DATAPLANE_API_LATEST_VERSION) - go get -u github.com/cncf/udpa@$(UDPA_LATEST_VERSION) - go get -u github.com/googleapis/googleapis@$(GOOGLEAPIS_LATEST_VERSION) + go get github.com/envoyproxy/data-plane-api@$(DATAPLANE_API_LATEST_VERSION) + go get github.com/cncf/udpa@$(UDPA_LATEST_VERSION) + go get github.com/googleapis/googleapis@$(GOOGLEAPIS_LATEST_VERSION) clean: ## Remove generated files find . -name '*.pb.go' -delete @@ -135,8 +135,11 @@ protoc/system/v1alpha1: build: ## Build generated files go build ./... +GO_TEST ?= go test +GO_TEST_OPTS ?= + test: ## Run tests - go test ./... + $(GO_TEST) $(GO_TEST_OPTS) -race -covermode=atomic -coverpkg=./... -coverprofile="$(COVERAGE_PROFILE)" ./... check: generate build test ## Verify that auto-generated code is up-to-date git diff --quiet || test $$(git diff --name-only | grep -v -e 'go.mod$$' -e 'go.sum$$' | wc -l) -eq 0 || ( echo "The following changes (result of code generators) have been detected:" && git --no-pager diff && false ) # fail if Git working tree is dirty diff --git a/api/go.mod b/api/go.mod index 70b298d92a68..7c526080919e 100644 --- a/api/go.mod +++ b/api/go.mod @@ -1,6 +1,6 @@ module github.com/Kong/kuma/api -go 1.12 +go 1.14 require ( cloud.google.com/go v0.26.0 // indirect diff --git a/api/mesh/v1alpha1/proxy_template.pb.go b/api/mesh/v1alpha1/proxy_template.pb.go index b83ddd811ff2..fbdee36eef1c 100644 --- a/api/mesh/v1alpha1/proxy_template.pb.go +++ b/api/mesh/v1alpha1/proxy_template.pb.go @@ -373,7 +373,9 @@ func init() { proto.RegisterType((*ProxyTemplateRawResource)(nil), "kuma.mesh.v1alpha1.ProxyTemplateRawResource") } -func init() { proto.RegisterFile("mesh/v1alpha1/proxy_template.proto", fileDescriptor_129e53d675ac14f4) } +func init() { + proto.RegisterFile("mesh/v1alpha1/proxy_template.proto", fileDescriptor_129e53d675ac14f4) +} var fileDescriptor_129e53d675ac14f4 = []byte{ // 392 bytes of a gzipped FileDescriptorProto diff --git a/go.mod b/go.mod index c88cf30d4da6..f5a9520081de 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/Kong/kuma -go 1.12 +go 1.14 require ( github.com/Kong/kuma/api v0.0.0-00010101000000-000000000000 diff --git a/pkg/plugins/resources/k8s/native/Dockerfile b/pkg/plugins/resources/k8s/native/Dockerfile index 9e390c09a3a1..15d56f8a680c 100644 --- a/pkg/plugins/resources/k8s/native/Dockerfile +++ b/pkg/plugins/resources/k8s/native/Dockerfile @@ -1,5 +1,5 @@ # Build the manager binary -FROM golang:1.12.12 as builder +FROM golang:1.14.2 as builder WORKDIR /workspace # Copy the Go Modules manifests diff --git a/pkg/plugins/resources/k8s/native/Makefile b/pkg/plugins/resources/k8s/native/Makefile index 135873b54f30..a9aea0b0f89e 100644 --- a/pkg/plugins/resources/k8s/native/Makefile +++ b/pkg/plugins/resources/k8s/native/Makefile @@ -24,9 +24,13 @@ export TEST_ASSET_KUBECTL=$(KUBECTL_PATH) all: manager +GO_TEST ?= go test +GO_TEST_OPTS ?= +COVERAGE_PROFILE ?= cover.out + # Run tests test: generate fmt vet manifests - go test ./api/... ./controllers/... -coverprofile cover.out + $(GO_TEST) $(GO_TEST_OPTS) -race -covermode=atomic -coverpkg=./... -coverprofile="$(COVERAGE_PROFILE)" ./api/... ./controllers/... # Build manager binary manager: generate fmt vet diff --git a/pkg/plugins/resources/k8s/native/go.mod b/pkg/plugins/resources/k8s/native/go.mod index 4e5e00a379c4..d486875c396d 100644 --- a/pkg/plugins/resources/k8s/native/go.mod +++ b/pkg/plugins/resources/k8s/native/go.mod @@ -1,6 +1,6 @@ module github.com/Kong/kuma/pkg/plugins/resources/k8s/native -go 1.12 +go 1.14 require ( github.com/Kong/kuma/api v0.0.0-00010101000000-000000000000