From 054f18701ad57b53c0cb45dbd8aa9483de72f3f8 Mon Sep 17 00:00:00 2001 From: Li Zhijian Date: Wed, 10 Feb 2021 14:06:00 +0800 Subject: [PATCH 1/4] Makefile/scripts: check and use GOBIN environment variable first 'go get/install' will install binaries into GOBIN when it's set which is not always same with GOPATH/bin Fix below error: $ hack/testExamplesAgainstKustomize.sh HEAD Installing kustomize HEAD On linux, and not on remote CI. Running expensive tests. make: Nothing to be done for '/home/lizj/gosrc/bin/helm'. Removing kustomize HEAD rm: cannot remove '/home/lizj/gosrc/bin/kustomize': No such file or directory Signed-off-by: Li Zhijian --- Makefile | 5 ++++- hack/testExamplesAgainstKustomize.sh | 8 +++++--- hack/testUnitKustomizePlugins.sh | 11 +++++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 5ba6f1f29..aea32d956 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,11 @@ # # Makefile for kustomize CLI and API. -MYGOBIN := $(shell go env GOPATH)/bin SHELL := /usr/bin/env bash +MYGOBIN = $(shell go env GOBIN) +ifeq ($(MYGOBIN),) +MYGOBIN = $(shell go env GOPATH)/bin +endif export PATH := $(MYGOBIN):$(PATH) MODULES := '"cmd/config" "api/" "kustomize/" "kyaml/"' diff --git a/hack/testExamplesAgainstKustomize.sh b/hack/testExamplesAgainstKustomize.sh index f94466995..b211612ac 100755 --- a/hack/testExamplesAgainstKustomize.sh +++ b/hack/testExamplesAgainstKustomize.sh @@ -14,9 +14,11 @@ version=$1 echo "Installing kustomize ${version}" +MYGOBIN=$(go env GOBIN) +MYGOBIN="${MYGOBIN:-$(go env GOPATH)/bin}" # Always rebuild, never assume the installed verion is # the right one to test. -rm -f $(go env GOPATH)/bin/kustomize +rm -f $MYGOBIN/kustomize if [ "$version" == "HEAD" ]; then (cd kustomize; go install .) else @@ -35,7 +37,7 @@ if onLinuxAndNotOnRemoteCI; then echo "On linux, and not on remote CI. Running expensive tests." # Requires helm. - make $(go env GOPATH)/bin/helm + make $MYGOBIN/helm mdrip --mode test --label helmtest examples/chart.md fi @@ -43,6 +45,6 @@ fi # rely on whatever this script just did. Tests should # be order independent. echo "Removing kustomize ${version}" -rm $(go env GOPATH)/bin/kustomize +rm $MYGOBIN/kustomize echo "Example tests passed against ${version}." diff --git a/hack/testUnitKustomizePlugins.sh b/hack/testUnitKustomizePlugins.sh index bd1d67e85..527264060 100755 --- a/hack/testUnitKustomizePlugins.sh +++ b/hack/testUnitKustomizePlugins.sh @@ -14,6 +14,9 @@ set -o pipefail rcAccumulator=0 +MYGOBIN=$(go env GOBIN) +MYGOBIN="${MYGOBIN:-$(go env GOPATH)/bin}" + # All hack scripts should run from top level. . hack/shellHelpers.sh @@ -49,10 +52,10 @@ function scanDir { if onLinuxAndNotOnRemoteCI; then # Some of these tests have special deps. - make $(go env GOPATH)/bin/helmV2 - make $(go env GOPATH)/bin/helmV3 - make $(go env GOPATH)/bin/helm - make $(go env GOPATH)/bin/kubeval + make $MYGOBIN/helmV2 + make $MYGOBIN/helmV3 + make $MYGOBIN/helm + make $MYGOBIN/kubeval fi for goMod in $(find ./plugin -name 'go.mod' -not -path "./plugin/untested/*"); do From abae65d8f1cac3a5ceefbb3601ba7610a2ae52e6 Mon Sep 17 00:00:00 2001 From: Li Zhijian Date: Wed, 10 Feb 2021 14:06:29 +0800 Subject: [PATCH 2/4] cmd: set proper GOBIN Signed-off-by: Li Zhijian --- cmd/config/Makefile | 5 ++++- cmd/gorepomod/Makefile | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/config/Makefile b/cmd/config/Makefile index 9a8b01d07..4c40e8b85 100644 --- a/cmd/config/Makefile +++ b/cmd/config/Makefile @@ -3,7 +3,10 @@ .PHONY: generate license fix vet fmt test build tidy clean -GOBIN := $(shell go env GOPATH)/bin +GOBIN = $(shell go env GOBIN) +ifeq ($(GOBIN),) +GOBIN = $(shell go env GOPATH)/bin +endif $(GOBIN)/addlicense: go get github.com/google/addlicense diff --git a/cmd/gorepomod/Makefile b/cmd/gorepomod/Makefile index c85352386..49dad0752 100644 --- a/cmd/gorepomod/Makefile +++ b/cmd/gorepomod/Makefile @@ -1,4 +1,7 @@ -MYGOBIN := $(shell go env GOPATH)/bin +MYGOBIN = $(shell go env GOBIN) +ifeq ($(MYGOBIN),) +MYGOBIN = $(shell go env GOPATH)/bin +endif $(MYGOBIN)/gorepomod: usage.go go install . From ec0e42709a6ddc8f94892c46d48ed244e08cbdea Mon Sep 17 00:00:00 2001 From: Li Zhijian Date: Wed, 10 Feb 2021 14:07:14 +0800 Subject: [PATCH 3/4] functions/examples: set proper GOBIN Signed-off-by: Li Zhijian --- functions/examples/application-cr/Makefile | 5 ++++- functions/examples/injection-tshirt-sizes/Makefile | 5 ++++- functions/examples/template-go-nginx/Makefile | 5 ++++- functions/examples/template-heredoc-cockroachdb/Makefile | 5 ++++- functions/examples/validator-kubeval/Makefile | 5 ++++- functions/examples/validator-resource-requests/Makefile | 5 ++++- 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/functions/examples/application-cr/Makefile b/functions/examples/application-cr/Makefile index 9b057cec2..670a475ab 100644 --- a/functions/examples/application-cr/Makefile +++ b/functions/examples/application-cr/Makefile @@ -3,7 +3,10 @@ .PHONY: generate license fix vet fmt test build tidy image -GOBIN := $(shell go env GOPATH)/bin +GOBIN = $(shell go env GOBIN) +ifeq ($(GOBIN),) +GOBIN = $(shell go env GOPATH)/bin +endif build: (cd image && go build -v -o $(GOBIN)/config-function .) diff --git a/functions/examples/injection-tshirt-sizes/Makefile b/functions/examples/injection-tshirt-sizes/Makefile index 9cf21bc2a..e52c7d18d 100644 --- a/functions/examples/injection-tshirt-sizes/Makefile +++ b/functions/examples/injection-tshirt-sizes/Makefile @@ -3,7 +3,10 @@ .PHONY: generate license fix vet fmt test build tidy image -GOBIN := $(shell go env GOPATH)/bin +GOBIN = $(shell go env GOBIN) +ifeq ($(GOBIN),) +GOBIN = $(shell go env GOPATH)/bin +endif build: (cd image && go build -v -o $(GOBIN)/config-function .) diff --git a/functions/examples/template-go-nginx/Makefile b/functions/examples/template-go-nginx/Makefile index ab76261e9..f17ce5ecb 100644 --- a/functions/examples/template-go-nginx/Makefile +++ b/functions/examples/template-go-nginx/Makefile @@ -3,7 +3,10 @@ .PHONY: generate license fix vet fmt test build tidy image -GOBIN := $(shell go env GOPATH)/bin +GOBIN = $(shell go env GOBIN) +ifeq ($(GOBIN),) +GOBIN = $(shell go env GOPATH)/bin +endif build: (cd image && go build -v -o $(GOBIN)/config-function .) diff --git a/functions/examples/template-heredoc-cockroachdb/Makefile b/functions/examples/template-heredoc-cockroachdb/Makefile index d218aca00..469ab5cc4 100644 --- a/functions/examples/template-heredoc-cockroachdb/Makefile +++ b/functions/examples/template-heredoc-cockroachdb/Makefile @@ -3,7 +3,10 @@ .PHONY: license image -GOBIN := $(shell go env GOPATH)/bin +GOBIN = $(shell go env GOBIN) +ifeq ($(GOBIN),) +GOBIN = $(shell go env GOPATH)/bin +endif license: (which $(GOBIN)/addlicense || go get github.com/google/addlicense) diff --git a/functions/examples/validator-kubeval/Makefile b/functions/examples/validator-kubeval/Makefile index 08a214c41..47aff3eb2 100644 --- a/functions/examples/validator-kubeval/Makefile +++ b/functions/examples/validator-kubeval/Makefile @@ -3,7 +3,10 @@ .PHONY: generate license fix vet fmt test build tidy image -GOBIN := $(shell go env GOPATH)/bin +GOBIN = $(shell go env GOBIN) +ifeq ($(GOBIN),) +GOBIN = $(shell go env GOPATH)/bin +endif build: (cd image && go build -v -o $(GOBIN)/config-function .) diff --git a/functions/examples/validator-resource-requests/Makefile b/functions/examples/validator-resource-requests/Makefile index f3d362626..8bfa4d177 100644 --- a/functions/examples/validator-resource-requests/Makefile +++ b/functions/examples/validator-resource-requests/Makefile @@ -3,7 +3,10 @@ .PHONY: generate license fix vet fmt test build tidy image -GOBIN := $(shell go env GOPATH)/bin +GOBIN = $(shell go env GOBIN) +ifeq ($(GOBIN),) +GOBIN = $(shell go env GOPATH)/bin +endif build: (cd image && go build -v -o $(GOBIN)/config-function .) From d203c2328a619ad1ecf52b52ae0f6a10947952dd Mon Sep 17 00:00:00 2001 From: Li Zhijian Date: Wed, 10 Feb 2021 14:07:45 +0800 Subject: [PATCH 4/4] kyaml: set proper GOBIN Signed-off-by: Li Zhijian --- kyaml/Makefile | 5 ++++- kyaml/openapi/Makefile | 5 ++++- kyaml/openapi/scripts/fetchSchemaFromCluster.sh | 3 ++- kyaml/openapi/scripts/generateSwaggerDotGo.sh | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/kyaml/Makefile b/kyaml/Makefile index c0caeafc8..61d3d0d13 100644 --- a/kyaml/Makefile +++ b/kyaml/Makefile @@ -1,7 +1,10 @@ # Copyright 2019 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 -MYGOBIN := $(shell go env GOPATH)/bin +MYGOBIN = $(shell go env GOBIN) +ifeq ($(MYGOBIN),) +MYGOBIN = $(shell go env GOPATH)/bin +endif export PATH := $(MYGOBIN):$(PATH) .PHONY: generate license fix vet fmt test lint tidy clean diff --git a/kyaml/openapi/Makefile b/kyaml/openapi/Makefile index f5cd8dc67..945f1aa52 100644 --- a/kyaml/openapi/Makefile +++ b/kyaml/openapi/Makefile @@ -1,7 +1,10 @@ # Copyright 2020 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 -MYGOBIN := $(shell go env GOPATH)/bin +MYGOBIN = $(shell go env GOBIN) +ifeq ($(MYGOBIN),) +MYGOBIN = $(shell go env GOPATH)/bin +endif API_VERSION := "v1.19.1" .PHONY: all diff --git a/kyaml/openapi/scripts/fetchSchemaFromCluster.sh b/kyaml/openapi/scripts/fetchSchemaFromCluster.sh index b2d3d64ef..1126d035c 100755 --- a/kyaml/openapi/scripts/fetchSchemaFromCluster.sh +++ b/kyaml/openapi/scripts/fetchSchemaFromCluster.sh @@ -2,7 +2,8 @@ # Copyright 2020 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 -MYGOBIN=$(go env GOPATH)/bin +MYGOBIN=$(go env GOBIN) +MYGOBIN="${MYGOBIN:-$(go env GOPATH)/bin}" VERSION=$1 cp $HOME/.kube/config /tmp/kubeconfig.txt | true diff --git a/kyaml/openapi/scripts/generateSwaggerDotGo.sh b/kyaml/openapi/scripts/generateSwaggerDotGo.sh index 1c01f8630..e055c0727 100755 --- a/kyaml/openapi/scripts/generateSwaggerDotGo.sh +++ b/kyaml/openapi/scripts/generateSwaggerDotGo.sh @@ -2,7 +2,8 @@ # Copyright 2020 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 -MYGOBIN=$(go env GOPATH)/bin +MYGOBIN=$(go env GOBIN) +MYGOBIN="${MYGOBIN:-$(go env GOPATH)/bin}" VERSION=$1 $MYGOBIN/go-bindata \