@@ -15,7 +15,6 @@ GOBIN=$(shell go env GOBIN)
15
15
endif
16
16
17
17
# Setting SHELL to bash allows bash commands to be executed by recipes.
18
- # This is a requirement for 'setup-envtest.sh' in the test target.
19
18
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
20
19
SHELL = /usr/bin/env bash -o pipefail
21
20
.SHELLFLAGS = -ec
58
57
tidy :
59
58
go mod tidy
60
59
60
+ GOLANGCI_LINT =$(shell pwd) /bin/golangci-lint
61
61
golangci-lint : # # Download golangci-lint
62
+ ifneq ($(shell test -f $(GOLANGCI_LINT ) ; echo $$? ) , 0)
63
+ @echo Getting golangci-lint...
62
64
@mkdir -p $(shell pwd)/bin
63
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell pwd) /bin v1.45.2
65
+ curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell pwd)/bin v1.46.2
66
+ endif
64
67
65
68
.PHONY : lint
66
69
lint : golangci-lint # # Run linter
67
- $(shell pwd) /bin/golangci-lint run
70
+ $(GOLANGCI_LINT ) run
68
71
69
72
.PHONY : goimports
70
73
goimports : # # run goimports updating files in place
71
74
goimports -w .
72
75
73
76
ENVTEST_ASSETS_DIR =$(shell pwd) /testbin
74
- test : manifests generate generate-mocks fmt vet test-setup # # Run tests.
75
- source ${ENVTEST_ASSETS_DIR} /setup-envtest.sh; setup_envtest_env $(ENVTEST_ASSETS_DIR ) ; go test ./... -coverprofile cover.out -covermode=atomic
77
+ KUBEBUILDER_ASSETS? ="$(shell $(ENVTEST ) use -i $(ENVTEST_KUBERNETES_VERSION ) --bin-dir=$(ENVTEST_ASSETS_DIR ) -p path) "
78
+ test : manifests generate generate-mocks fmt vet test-setup # # Run tests
79
+ KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS ) go test ./... -coverprofile cover.out -covermode=atomic
76
80
77
- test-setup : # # setup test environment
81
+ test-setup : setup-envtest # # Ensure test environment has been downloaded
82
+ ifneq ($(shell test -d $(ENVTEST_ASSETS_DIR ) ; echo $$? ) , 0)
83
+ @echo Setting up K8s test environment...
78
84
mkdir -p ${ENVTEST_ASSETS_DIR}
79
- test -f ${ENVTEST_ASSETS_DIR} /setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR} /setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh
80
- source ${ENVTEST_ASSETS_DIR} /setup-envtest.sh ; fetch_envtest_tools $( ENVTEST_ASSETS_DIR )
85
+ $(ENVTEST) use 1.24.x --bin-dir $(ENVTEST_ASSETS_DIR)
86
+ endif
81
87
82
88
kind-integration-suite : # # Provision and run integration tests with cleanup
83
89
make kind-integration-setup && \
84
90
make kind-integration-run && \
85
91
make kind-integration-cleanup
86
92
87
- kind-integration-setup : build kind test-setup # # Setup the integration test using kind clusters
93
+ kind-integration-setup : build kind # # Setup the integration test using kind clusters
88
94
@./integration/kind-test/scripts/setup-kind.sh
89
95
90
96
kind-integration-run : # # Run the integration test controller
@@ -98,7 +104,7 @@ eks-integration-suite: ## Provision and run EKS integration tests with cleanup
98
104
make eks-integration-run && \
99
105
make eks-integration-cleanup
100
106
101
- eks-integration-setup : build test-setup # # Setup the integration test using EKS clusters
107
+ eks-integration-setup : build # # Setup the integration test using EKS clusters
102
108
@./integration/eks-test/scripts/eks-setup.sh
103
109
104
110
eks-integration-run : # # Run the integration test controller
@@ -129,7 +135,8 @@ docker-push: ## Push docker image with the manager.
129
135
clean :
130
136
@echo Cleaning...
131
137
go clean
132
- rm -rf $(MOCKS_DESTINATION ) bin/ testbin/ cover.out
138
+ if test -d $( ENVTEST_ASSETS_DIR) ; then chmod -R +w $( ENVTEST_ASSETS_DIR) ; fi
139
+ rm -rf $(MOCKS_DESTINATION ) / bin/ $(ENVTEST_ASSETS_DIR ) / cover.out
133
140
134
141
# #@ Deployment
135
142
@@ -148,6 +155,8 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
148
155
149
156
MOCKS_DESTINATION =mocks
150
157
generate-mocks : mockgen
158
+ ifneq ($(shell test -d $(MOCKS_DESTINATION ) ; echo $$? ) , 0)
159
+ @echo Generating mocks...
151
160
$(MOCKGEN) --source pkg/cloudmap/client.go --destination $(MOCKS_DESTINATION)/pkg/cloudmap/client_mock.go --package cloudmap_mock
152
161
$(MOCKGEN) --source pkg/cloudmap/cache.go --destination $(MOCKS_DESTINATION)/pkg/cloudmap/cache_mock.go --package cloudmap_mock
153
162
$(MOCKGEN) --source pkg/cloudmap/operation_poller.go --destination $(MOCKS_DESTINATION)/pkg/cloudmap/operation_poller_mock.go --package cloudmap_mock
@@ -156,23 +165,27 @@ generate-mocks: mockgen
156
165
$(MOCKGEN) --source pkg/cloudmap/aws_facade.go --destination $(MOCKS_DESTINATION)/pkg/cloudmap/aws_facade_mock.go --package cloudmap_mock
157
166
$(MOCKGEN) --source integration/janitor/api.go --destination $(MOCKS_DESTINATION)/integration/janitor/api_mock.go --package janitor_mock
158
167
$(MOCKGEN) --source integration/janitor/aws_facade.go --destination $(MOCKS_DESTINATION)/integration/janitor/aws_facade_mock.go --package janitor_mock
159
-
168
+ endif
160
169
161
170
CONTROLLER_GEN = $(shell pwd) /bin/controller-gen
162
171
controller-gen : # # Download controller-gen locally if necessary.
163
- $(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0 )
172
+ $(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.2 )
164
173
165
174
KUSTOMIZE = $(shell pwd) /bin/kustomize
166
175
kustomize : # # Download kustomize locally if necessary.
167
- $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/[email protected] )
176
+ $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/[email protected] )
177
+
178
+ ENVTEST = $(shell pwd) /bin/setup-envtest
179
+ setup-envtest : # # Download setup-envtest
180
+ $(call go-get-tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
168
181
169
182
MOCKGEN = $(shell pwd) /bin/mockgen
170
183
mockgen : # # Download mockgen
171
184
$(call go-get-tool,$(MOCKGEN ) ,github.com/golang/mock/[email protected] )
172
185
173
186
KIND = $(shell pwd) /bin/kind
174
187
kind : # # Download kind
175
- $(call go-get-tool,$(KIND ) ,sigs.k8s.io/kind@v0.13 .0)
188
+ $(call go-get-tool,$(KIND ) ,sigs.k8s.io/kind@v0.14 .0)
176
189
177
190
# go-get-tool will 'go get' any package $2 and install it to $1.
178
191
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
0 commit comments