From 42351d3737bb8be78b3504784e9c89e509b29ac8 Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Thu, 9 Jan 2020 13:48:43 -0300 Subject: [PATCH] Add script to check go version and fix output directory permissions (#4907) --- Makefile | 30 +++++++++++++++------------ build/run-in-docker.sh | 3 +++ hack/check-go-version.sh | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 13 deletions(-) create mode 100755 hack/check-go-version.sh diff --git a/Makefile b/Makefile index 4f421f5e1c..b669f03125 100644 --- a/Makefile +++ b/Makefile @@ -154,11 +154,11 @@ push: .push-$(ARCH) ## Publish image for a particular arch. $(DOCKER) push $(MULTI_ARCH_IMAGE):$(TAG) .PHONY: build -build: ## Build ingress controller, debug tool and pre-stop hook. +build: check-go-version ## Build ingress controller, debug tool and pre-stop hook. ifeq ($(USE_DOCKER), true) @build/run-in-docker.sh \ PKG=$(PKG) \ - ARCH=$(PKG) \ + ARCH=$(ARCH) \ GIT_COMMIT=$(GIT_COMMIT) \ REPO_INFO=$(REPO_INFO) \ TAG=$(TAG) \ @@ -169,11 +169,11 @@ else endif .PHONY: build-plugin -build-plugin: ## Build ingress-nginx krew plugin. +build-plugin: check-go-version ## Build ingress-nginx krew plugin. ifeq ($(USE_DOCKER), true) @build/run-in-docker.sh \ PKG=$(PKG) \ - ARCH=$(PKG) \ + ARCH=$(ARCH) \ GIT_COMMIT=$(GIT_COMMIT) \ REPO_INFO=$(REPO_INFO) \ TAG=$(TAG) \ @@ -197,11 +197,11 @@ else endif .PHONY: test -test: ## Run go unit tests. +test: check-go-version ## Run go unit tests. ifeq ($(USE_DOCKER), true) @build/run-in-docker.sh \ PKG=$(PKG) \ - ARCH=$(PKG) \ + ARCH=$(ARCH) \ GIT_COMMIT=$(GIT_COMMIT) \ REPO_INFO=$(REPO_INFO) \ TAG=$(TAG) \ @@ -222,7 +222,7 @@ else endif .PHONY: e2e-test -e2e-test: ## Run e2e tests (expects access to a working Kubernetes cluster). +e2e-test: check-go-version ## Run e2e tests (expects access to a working Kubernetes cluster). @build/run-e2e-suite.sh .PHONY: e2e-test-image @@ -230,7 +230,7 @@ e2e-test-image: e2e-test-binary ## Build image for e2e tests. @make -C test/e2e-image .PHONY: e2e-test-binary -e2e-test-binary: ## Build ginkgo binary for e2e tests. +e2e-test-binary: check-go-version ## Build ginkgo binary for e2e tests. ifeq ($(USE_DOCKER), true) @build/run-in-docker.sh \ ginkgo build ./test/e2e @@ -239,7 +239,7 @@ else endif .PHONY: cover -cover: ## Run go coverage unit tests. +cover: check-go-version ## Run go coverage unit tests. @build/cover.sh echo "Uploading coverage results..." @curl -s https://codecov.io/bash | bash @@ -260,13 +260,13 @@ check_dead_links: ## Check if the documentation contains dead links. --allow-redirect $(shell find $$PWD -mindepth 1 -name "*.md" -printf '%P\n' | grep -v vendor | grep -v Changelog.md) .PHONY: dep-ensure -dep-ensure: ## Update and vendo go dependencies. +dep-ensure: check-go-version ## Update and vendo go dependencies. go mod tidy -v find vendor -name '*_test.go' -delete go mod vendor .PHONY: dev-env -dev-env: ## Starts a local Kubernetes cluster using minikube, building and deploying the ingress controller. +dev-env: check-go-version ## Starts a local Kubernetes cluster using minikube, building and deploying the ingress controller. @USE_DOCKER=false build/dev-env.sh .PHONY: live-docs @@ -280,7 +280,7 @@ build-docs: ## Build documentation (output in ./site directory). @docker run --rm -v ${PWD}:/docs ingress-nginx/mkdocs build .PHONY: misspell -misspell: ## Check for spelling errors. +misspell: check-go-version ## Check for spelling errors. @go get github.com/client9/misspell/cmd/misspell misspell \ -locale US \ @@ -288,9 +288,13 @@ misspell: ## Check for spelling errors. cmd/* internal/* deploy/* docs/* design/* test/* README.md .PHONY: kind-e2e-test -kind-e2e-test: ## Run e2e tests using kind. +kind-e2e-test: check-go-version ## Run e2e tests using kind. @test/e2e/run.sh .PHONY: run-ingress-controller run-ingress-controller: ## Run the ingress controller locally using a kubectl proxy connection. @build/run-ingress-controller.sh + +.PHONY: check-go-version +check-go-version: + @hack/check-go-version.sh diff --git a/build/run-in-docker.sh b/build/run-in-docker.sh index 3016905ddd..b155f2835a 100755 --- a/build/run-in-docker.sh +++ b/build/run-in-docker.sh @@ -48,6 +48,9 @@ if [ ! -d "${MINIKUBE_PATH}" ]; then MINIKUBE_VOLUME="" fi +# create output directory as current user to avoid problem with docker. +mkdir -p "${KUBE_ROOT}/bin" "${KUBE_ROOT}/bin/${ARCH}" + docker run \ --tty \ --rm \ diff --git a/hack/check-go-version.sh b/hack/check-go-version.sh new file mode 100755 index 0000000000..8f02641970 --- /dev/null +++ b/hack/check-go-version.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Copyright 2020 The Kubernetes 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. + +if [ -n "$DEBUG" ]; then + set -x +fi + +set -o errexit +set -o nounset +set -o pipefail + +MINIMUM_GO_VERSION=go1.13 + +if [[ -z "$(command -v go)" ]]; then + echo " +Can't find 'go' in PATH, please fix and retry. +See http://golang.org/doc/install for installation instructions. +" + exit 1 +fi + +IFS=" " read -ra go_version <<< "$(go version)" + +if [[ "${MINIMUM_GO_VERSION}" != $(echo -e "${MINIMUM_GO_VERSION}\n${go_version[2]}" | sort -s -t. -k 1,1 -k 2,2n -k 3,3n | head -n1) && "${go_version[2]}" != "devel" ]]; then + echo " +Detected go version: ${go_version[*]}. +ingress-nginx requires ${MINIMUM_GO_VERSION} or greater. + +Please install ${MINIMUM_GO_VERSION} or later. +" + exit 1 +fi