1
-
2
1
# Image URL to use all building/pushing image targets
3
- IMG ?= ghcr.io/mercari/tortoise:v0.9 .0
2
+ IMG ?= ghcr.io/mercari/tortoise:v0.11 .0
4
3
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5
- ENVTEST_K8S_VERSION = 1.27.1
4
+ ENVTEST_K8S_VERSION = 1.31.0
6
5
7
6
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8
7
ifeq (,$(shell go env GOBIN) )
11
10
GOBIN =$(shell go env GOBIN)
12
11
endif
13
12
13
+ # CONTAINER_TOOL defines the container tool to be used for building images.
14
+ # Be aware that the target commands are only tested with Docker which is
15
+ # scaffolded by default. However, you might want to replace it to use other
16
+ # tools. (i.e. podman)
17
+ CONTAINER_TOOL ?= docker
18
+
14
19
# Setting SHELL to bash allows bash commands to be executed by recipes.
15
20
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
16
21
SHELL = /usr/bin/env bash -o pipefail
@@ -23,7 +28,7 @@ all: build
23
28
24
29
# The help target prints out all targets with their descriptions organized
25
30
# beneath their categories. The categories are represented by '##@' and the
26
- # target descriptions by '##'. The awk commands is responsible for reading the
31
+ # target descriptions by '##'. The awk command is responsible for reading the
27
32
# entire set of makefiles included in this invocation, looking for lines of the
28
33
# file as xyz: ## something, and then pretty-format the target and help. Then,
29
34
# if there's a line with ##@ something, that gets pretty-printed as a category.
@@ -39,11 +44,8 @@ help: ## Display this help.
39
44
# #@ Development
40
45
41
46
.PHONY : manifests
42
- manifests : kustomize controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
47
+ manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
43
48
$(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
44
- cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
45
- $(KUSTOMIZE ) build config/default -o manifests/default
46
- $(KUSTOMIZE ) build config/crd -o manifests/crd
47
49
48
50
.PHONY : generate
49
51
generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
@@ -57,39 +59,79 @@ fmt: ## Run go fmt against code.
57
59
vet : # # Run go vet against code.
58
60
go vet ./...
59
61
60
- test : manifests generate fmt vet envtest ginkgo # # Run tests.
61
- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " $(GINKGO ) -r --cover --coverprofile cover.out
62
-
63
- .PHONY : test-debug
64
- test-debug : envtest ginkgo
65
- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " DEBUG=true $(GINKGO ) -r --fail-fast -v --progress
66
-
67
- .PHONY : test-update
68
- test-update : envtest ginkgo
69
- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " UPDATE_TESTCASES=true $(GINKGO ) -r --fail-fast
62
+ .PHONY : test
63
+ test : manifests generate fmt vet envtest # # Run tests.
64
+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test $$(go list ./... | grep -v /e2e ) -coverprofile cover.out
65
+
66
+ # TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
67
+ # The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
68
+ # Prometheus and CertManager are installed by default; skip with:
69
+ # - PROMETHEUS_INSTALL_SKIP=true
70
+ # - CERT_MANAGER_INSTALL_SKIP=true
71
+ .PHONY : test-e2e
72
+ test-e2e : manifests generate fmt vet # # Run the e2e tests. Expected an isolated environment using Kind.
73
+ @command -v kind > /dev/null 2>&1 || { \
74
+ echo " Kind is not installed. Please install Kind manually." ; \
75
+ exit 1; \
76
+ }
77
+ @kind get clusters | grep -q ' kind' || { \
78
+ echo " No Kind cluster is running. Please start a Kind cluster before running the e2e tests." ; \
79
+ exit 1; \
80
+ }
81
+ go test ./test/e2e/ -v -ginkgo.v
70
82
71
- .PHONY : test-tortoisectl
72
- test-tortoisectl : envtest
73
- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test -timeout 30s -v -run Test_TortoiseCtlStop ./cmd/tortoisectl/test/...
74
-
75
- GINKGO ?= $(LOCALBIN ) /ginkgo
76
- GINKGO_VERSION ?= v2.1.4
83
+ .PHONY : lint
84
+ lint :
85
+ golangci-lint run --timeout=10m ./...
77
86
78
- .PHONY : ginkgo
79
- ginkgo : $( GINKGO ) # # Download controller-gen locally if necessary.
80
- $( GINKGO ) : $( LOCALBIN )
81
- test -s $( LOCALBIN ) /ginkgo || GOBIN= $( LOCALBIN ) go install github.com/onsi/ginkgo/v2/ginkgo@ $( GINKGO_VERSION )
87
+ .PHONY : lint-fix
88
+ lint-fix : golangci-lint # # Run golangci-lint linter and perform fixes
89
+ find . -name " *.go " | xargs gci write --section Standard --section Default --section " Prefix(github.com/mercari/tortoise) " --section blank --section dot
90
+ @make lint args= ' --fix -v --timeout=10m ' cons_args= ' -v '
82
91
83
92
# #@ Build
84
93
85
94
.PHONY : build
86
- build : generate fmt vet # # Build manager binary.
87
- go build -o bin/manager main.go
88
- go build -o bin/tortoisectl cmd/tortoisectl/main.go
95
+ build : manifests generate fmt vet # # Build manager binary.
96
+ go build -o bin/manager cmd/main.go
89
97
90
98
.PHONY : run
91
99
run : manifests generate fmt vet # # Run a controller from your host.
92
- go run ./main.go
100
+ go run ./cmd/main.go
101
+
102
+ # If you wish to build the manager image targeting other platforms you can use the --platform flag.
103
+ # (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
104
+ # More info: https://docs.docker.com/develop/develop-images/build_enhancements/
105
+ .PHONY : docker-build
106
+ docker-build : # # Build docker image with the manager.
107
+ $(CONTAINER_TOOL ) build -t ${IMG} .
108
+
109
+ .PHONY : docker-push
110
+ docker-push : # # Push docker image with the manager.
111
+ $(CONTAINER_TOOL ) push ${IMG}
112
+
113
+ # PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
114
+ # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
115
+ # - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
116
+ # - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
117
+ # - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
118
+ # To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
119
+ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
120
+ .PHONY : docker-buildx
121
+ docker-buildx : # # Build and push docker image for the manager for cross-platform support
122
+ # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
123
+ sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
124
+ - $(CONTAINER_TOOL ) buildx create --name project-v4-builder
125
+ $(CONTAINER_TOOL ) buildx use project-v4-builder
126
+ - $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
127
+ - $(CONTAINER_TOOL ) buildx rm project-v4-builder
128
+ rm Dockerfile.cross
129
+
130
+ .PHONY : build-installer
131
+ build-installer : manifests generate kustomize # # Generate a consolidated YAML with CRDs and deployment.
132
+ mkdir -p dist
133
+ cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
134
+ $(KUSTOMIZE ) build config/default > dist/install.yaml
93
135
94
136
# #@ Deployment
95
137
@@ -99,63 +141,77 @@ endif
99
141
100
142
.PHONY : install
101
143
install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
102
- $(KUSTOMIZE ) build config/crd | kubectl apply -f -
144
+ $(KUSTOMIZE ) build config/crd | $( KUBECTL ) apply -f -
103
145
104
146
.PHONY : uninstall
105
147
uninstall : manifests kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
106
- $(KUSTOMIZE ) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
148
+ $(KUSTOMIZE ) build config/crd | $( KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
107
149
108
150
.PHONY : deploy
109
151
deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
110
- $(KUSTOMIZE ) build config/default | kubectl apply -f -
152
+ cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
153
+ $(KUSTOMIZE ) build config/default | $(KUBECTL ) apply -f -
111
154
112
155
.PHONY : undeploy
113
- undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
114
- $(KUSTOMIZE ) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
156
+ undeploy : kustomize # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
157
+ $(KUSTOMIZE ) build config/default | $( KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
115
158
116
- # #@ Build Dependencies
159
+ # #@ Dependencies
117
160
118
161
# # Location to install dependencies to
119
162
LOCALBIN ?= $(shell pwd) /bin
120
163
$(LOCALBIN ) :
121
164
mkdir -p $(LOCALBIN )
122
165
123
166
# # Tool Binaries
167
+ KUBECTL ?= kubectl
124
168
KUSTOMIZE ?= $(LOCALBIN ) /kustomize
125
169
CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
126
170
ENVTEST ?= $(LOCALBIN ) /setup-envtest
171
+ GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint
127
172
128
173
# # Tool Versions
129
- KUSTOMIZE_VERSION ?= v3.8.7
130
- CONTROLLER_TOOLS_VERSION ?= v0.13.0
174
+ KUSTOMIZE_VERSION ?= v5.4.3
175
+ CONTROLLER_TOOLS_VERSION ?= v0.16.1
176
+ ENVTEST_VERSION ?= release-0.19
177
+ GOLANGCI_LINT_VERSION ?= v1.59.1
131
178
132
- KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
133
179
.PHONY : kustomize
134
180
kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
135
181
$(KUSTOMIZE ) : $(LOCALBIN )
136
- test -s $( LOCALBIN ) /kustomize || { curl -s $( KUSTOMIZE_INSTALL_SCRIPT ) | bash -s -- $( subst v, ,$( KUSTOMIZE_VERSION) ) $( LOCALBIN ) ; }
182
+ $( call go-install-tool, $( KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v5 ,$(KUSTOMIZE_VERSION ) )
137
183
138
184
.PHONY : controller-gen
139
185
controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
140
186
$(CONTROLLER_GEN ) : $(LOCALBIN )
141
- test -s $( LOCALBIN ) /controller-gen || GOBIN= $( LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@ $(CONTROLLER_TOOLS_VERSION )
187
+ $( call go-install-tool, $( CONTROLLER_GEN ) , sigs.k8s.io/controller-tools/cmd/controller-gen, $(CONTROLLER_TOOLS_VERSION ) )
142
188
143
189
.PHONY : envtest
144
- envtest : $(ENVTEST ) # # Download envtest- setup locally if necessary.
190
+ envtest : $(ENVTEST ) # # Download setup-envtest locally if necessary.
145
191
$(ENVTEST ) : $(LOCALBIN )
146
- test -s $(LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
192
+ $(call go-install-tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION ) )
193
+
194
+ .PHONY : golangci-lint
195
+ golangci-lint : $(GOLANGCI_LINT ) # # Download golangci-lint locally if necessary.
196
+ $(GOLANGCI_LINT ) : $(LOCALBIN )
197
+ $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
147
198
148
- # # Install tools
149
199
.PHONY : dependencies
150
200
dependencies :
151
201
@./scripts/dependencies.sh
152
202
153
- .PHONY : lint
154
- lint :
155
- golangci-lint run $(args ) ./...
156
-
157
- .PHONY : lint-fix
158
- lint-fix :
159
- # Note: gci's autofix on golangci-lint was disabled. We can remove this if that is enabled again.
160
- find . -name " *.go" | xargs gci write --section Standard --section Default --section " Prefix(github.com/mercari/tortoise)" --section blank --section dot
161
- @make lint args=' --fix -v' cons_args=' -v'
203
+ # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
204
+ # $1 - target path with name of binary
205
+ # $2 - package url which can be installed
206
+ # $3 - specific version of package
207
+ define go-install-tool
208
+ @[ -f "$(1 ) -$(3 ) " ] || { \
209
+ set -e; \
210
+ package=$(2 ) @$(3 ) ;\
211
+ echo "Downloading $${package}" ;\
212
+ rm -f $(1 ) || true ;\
213
+ GOBIN=$(LOCALBIN ) go install $${package} ;\
214
+ mv $(1 ) $(1 ) -$(3 ) ;\
215
+ } ;\
216
+ ln -sf $(1 ) -$(3 ) $(1 )
217
+ endef
0 commit comments