@@ -4,12 +4,13 @@ IMG ?= quay.io/open-cluster-management/cluster-permission:latest
4
4
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5
5
ENVTEST_K8S_VERSION = 1.26.0
6
6
7
- # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8
- ifeq (,$(shell go env GOBIN) )
9
- GOBIN =$(shell go env GOPATH) /bin
10
- else
11
- GOBIN =$(shell go env GOBIN)
12
- endif
7
+ TEST_TMP :=/tmp
8
+ export KUBEBUILDER_ASSETS ?=$(TEST_TMP ) /kubebuilder/bin
9
+ K8S_VERSION ?=1.19.2
10
+ GOHOSTOS ?=$(shell go env GOHOSTOS)
11
+ GOHOSTARCH ?= $(shell go env GOHOSTARCH)
12
+ KB_TOOLS_ARCHIVE_NAME :=kubebuilder-tools-$(K8S_VERSION ) -$(GOHOSTOS ) -$(GOHOSTARCH ) .tar.gz
13
+ KB_TOOLS_ARCHIVE_PATH := $(TEST_TMP ) /$(KB_TOOLS_ARCHIVE_NAME )
13
14
14
15
# Setting SHELL to bash allows bash commands to be executed by recipes.
15
16
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
@@ -54,14 +55,13 @@ fmt: ## Run go fmt against code.
54
55
vet : # # Run go vet against code.
55
56
go vet ./...
56
57
57
- .PHONY : test
58
- test : manifests generate fmt vet envtest # # Run tests.
59
- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test ./... -coverprofile cover.out
60
-
61
58
# #@ Build
62
59
60
+ .PHONY : pre-build
61
+ pre-build : manifests generate fmt vet
62
+
63
63
.PHONY : build
64
- build : manifests generate fmt vet # # Build manager binary.
64
+ build :
65
65
go build -o bin/cluster-permission main.go
66
66
67
67
.PHONY : run
@@ -152,10 +152,22 @@ $(CONTROLLER_GEN): $(LOCALBIN)
152
152
test -s $(LOCALBIN ) /controller-gen && $(LOCALBIN ) /controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION ) || \
153
153
GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
154
154
155
- .PHONY : envtest
156
- envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
157
- $(ENVTEST ) : $(LOCALBIN )
158
- test -s $(LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
155
+ .PHONY : test
156
+
157
+ # download the kubebuilder-tools to get kube-apiserver binaries from it
158
+ ensure-kubebuilder-tools :
159
+ ifeq "" "$(wildcard $(KUBEBUILDER_ASSETS ) ) "
160
+ $(info Downloading kube-apiserver into '$(KUBEBUILDER_ASSETS)')
161
+ mkdir -p '$(KUBEBUILDER_ASSETS)'
162
+ curl -s -f -L https://storage.googleapis.com/kubebuilder-tools/$(KB_TOOLS_ARCHIVE_NAME) -o '$(KB_TOOLS_ARCHIVE_PATH)'
163
+ tar -C '$(KUBEBUILDER_ASSETS)' --strip-components=2 -zvxf '$(KB_TOOLS_ARCHIVE_PATH)'
164
+ else
165
+ $(info Using existing kube-apiserver from "$(KUBEBUILDER_ASSETS)")
166
+ endif
167
+ .PHONY : ensure-kubebuilder-tools
168
+
169
+ test : ensure-kubebuilder-tools
170
+ go test -timeout 300s -v ./controllers/... -coverprofile=coverage.out
159
171
160
172
.PHONY : deploy-ocm
161
173
deploy-ocm :
0 commit comments