Skip to content

Commit

Permalink
Set GOBIN so Makefile don't modify $PATH on go install
Browse files Browse the repository at this point in the history
Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
  • Loading branch information
kaovilai committed Jan 24, 2024
1 parent 1034d6a commit b0e615e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ platform_temp = $(subst -, ,$(ARCH))
GOOS = $(word 1, $(platform_temp))
GOARCH = $(word 2, $(platform_temp))
GOPROXY ?= https://proxy.golang.org
GOBIN=$$(pwd)/.go/bin

# If you want to build all binaries, see the 'all-build' rule.
# If you want to build all containers, see the 'all-containers' rule.
Expand All @@ -129,6 +130,7 @@ local: build-dirs
# Add DEBUG=1 to enable debug locally
GOOS=$(GOOS) \
GOARCH=$(GOARCH) \
GOBIN=$(GOBIN) \
VERSION=$(VERSION) \
REGISTRY=$(REGISTRY) \
PKG=$(PKG) \
Expand Down
4 changes: 4 additions & 0 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ if [[ -z "${GOOS}" ]]; then
echo "GOOS must be set"
exit 1
fi
if [[ -z "${GOBIN}" ]]; then
echo "GOBIN must be set"
exit 1
fi
if [[ -z "${GOARCH}" ]]; then
echo "GOARCH must be set"
exit 1
Expand Down
13 changes: 9 additions & 4 deletions test/e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ help: ## Display this help

TOOLS_DIR := $(REPO_ROOT)/hack/tools
BIN_DIR := bin
# Try to not modify PATH if possible
GOBIN := $(REPO_ROOT)/.go/bin
TOOLS_BIN_DIR := $(TOOLS_DIR)/$(BIN_DIR)
GINKGO := $(shell go env GOPATH)/bin/ginkgo
GINKGO := $(GOBIN)/ginkgo
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
OUTPUT_DIR := _output/$(GOOS)/$(GOARCH)/bin
GINKGO_FOCUS ?=
Expand Down Expand Up @@ -106,10 +108,13 @@ SNAPSHOT_MOVE_DATA ?= false
DATA_MOVER_PLUGIN ?=
DISABLE_INFORMER_CACHE ?= false


# Make sure ginkgo is in $GOBIN
.PHONY:ginkgo
ginkgo: # Make sure ginkgo is in $GOPATH/bin
go install github.com/onsi/ginkgo/ginkgo@v1.16.5
ginkgo: ${GOBIN}/ginkgo

# This target does not run if ginkgo is already in $GOBIN
${GOBIN}/ginkgo:
GOBIN=${GOBIN} go install github.com/onsi/ginkgo/ginkgo@v1.16.5

.PHONY: run
run: ginkgo
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,18 @@ Below is a mapping between `make` variables to E2E configuration flags.
Basic examples:

1. Run Velero tests in a kind cluster with AWS (or Minio) as the storage provider:

Start kind cluster
```bash
kind create cluster
```
```bash
BSL_PREFIX=<PREFIX_UNDER_BUCKET> BSL_BUCKET=<BUCKET_FOR_E2E_TEST_BACKUP> CREDS_FILE=/path/to/aws-creds CLOUD_PROVIDER=kind OBJECT_STORE_PROVIDER=aws make test-e2e
```
Stop kind cluster
```bash
kind delete cluster
```
1. Run Velero tests in an AWS cluster:
```bash
BSL_PREFIX=<PREFIX_UNDER_BUCKET> BSL_BUCKET=<BUCKET_FOR_E2E_TEST_BACKUP> CREDS_FILE=/path/to/aws-creds CLOUD_PROVIDER=aws make test-e2e
Expand Down
12 changes: 9 additions & 3 deletions test/perf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ help: ## Display this help

TOOLS_DIR := $(REPO_ROOT)/hack/tools
BIN_DIR := bin
# Try to not modify PATH if possible
GOBIN := $(REPO_ROOT)/.go/bin
TOOLS_BIN_DIR := $(TOOLS_DIR)/$(BIN_DIR)
GINKGO := $(GOPATH)/bin/ginkgo
GINKGO := $(GOBIN)/ginkgo
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
OUTPUT_DIR := _output/$(GOOS)/$(GOARCH)/bin
GINKGO_FOCUS ?=
Expand Down Expand Up @@ -88,9 +90,13 @@ VELERO_POD_CPU_REQUEST ?= 2
VELERO_POD_MEM_REQUEST ?= 2Gi
POD_VOLUME_OPERATION_TIMEOUT ?= 6h

# Make sure ginkgo is in $GOBIN
.PHONY:ginkgo
ginkgo: # Make sure ginkgo is in $GOPATH/bin
go install github.com/onsi/ginkgo/ginkgo@v1.16.5
ginkgo: ${GOBIN}/ginkgo

# This target does not run if ginkgo is already in $GOBIN
${GOBIN}/ginkgo:
GOBIN=${GOBIN} go install github.com/onsi/ginkgo/ginkgo@v1.16.5

.PHONY: run
run: ginkgo
Expand Down
2 changes: 1 addition & 1 deletion test/util/velero/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func VeleroInstall(ctx context.Context, veleroCfg *VeleroConfig, isStandbyCluste
veleroCfg.CloudProvider = veleroCfg.StandbyClusterCloudProvider
}
if veleroCfg.CloudProvider != "kind" {
fmt.Printf("For cloud platforms, object store plugin provider will be set as cloud provider")
fmt.Println("For cloud platforms, object store plugin provider will be set as cloud provider")
// If ObjectStoreProvider is not provided, then using the value same as CloudProvider
if veleroCfg.ObjectStoreProvider == "" {
veleroCfg.ObjectStoreProvider = veleroCfg.CloudProvider
Expand Down
10 changes: 9 additions & 1 deletion test/util/velero/velero_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"net/http"
"os"
"os/exec"
"os/user"
"path/filepath"
"reflect"
"regexp"
Expand Down Expand Up @@ -177,7 +178,14 @@ func getProviderVeleroInstallOptions(veleroCfg *VeleroConfig,
if veleroCfg.CloudCredentialsFile == "" {
return nil, errors.Errorf("No credentials were supplied to use for E2E tests")
}

// Expand home directory if it is specified. https://stackoverflow.com/a/17617721
if strings.HasPrefix(veleroCfg.CloudCredentialsFile, "~/") {
usr, _ := user.Current()
dir := usr.HomeDir
// Use strings.HasPrefix so we don't match paths like
// "/something/~/something/"
veleroCfg.CloudCredentialsFile = filepath.Join(dir, veleroCfg.CloudCredentialsFile[2:])
}
realPath, err := filepath.Abs(veleroCfg.CloudCredentialsFile)
if err != nil {
return nil, err
Expand Down

0 comments on commit b0e615e

Please sign in to comment.