Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
214 lines (179 loc) · 9.07 KB
/
Copy pathMakefile
File metadata and controls
214 lines (179 loc) · 9.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Copyright (c) 2018 Dell Inc., or its subsidiaries. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
SHELL=/bin/bash -o pipefail
# Produce CRDs compatible with Kubernetes 1.16+ (using apiextensions.k8s.io/v1)
CRD_OPTIONS ?= "crd:crdVersions=v1,generateEmbeddedObjectMeta=true"
PROJECT_NAME=zookeeper-operator
EXPORTER_NAME=zookeeper-exporter
APP_NAME=zookeeper
REPO?=adobe/$(PROJECT_NAME)
TEST_REPO=testzkop/$(PROJECT_NAME)
APP_REPO?=adobe/$(APP_NAME)
# Go module path (still github.com/pravega/...), used for the -X ldflags.
# Kept separate from REPO, which is only the Docker image name.
MODULE=$(shell awk '/^module /{print $$2}' go.mod)
VERSION=$(shell git describe --always --tags --dirty | tr -d "v" | sed "s/\(.*\)-g`git rev-parse --short HEAD`/\1/")
GIT_SHA=$(shell git rev-parse --short HEAD)
# Single source of truth for the operator's builder image Go version: read the
# `go` directive from go.mod so it never drifts from what the module requires.
# Single source of truth for the operator's builder image Go version: read the
# `go` directive from go.mod so it never drifts from what the module requires.
# Trimmed to major.minor since Docker Hub's golang image only ships
# X.Y-alpineN (floating patch) tags, not go.mod's full X.Y.Z patch version.
GO_VERSION=$(shell awk '/^go /{print $$2}' go.mod | cut -d. -f1,2)
TEST_IMAGE=$(TEST_REPO)-testimages:$(VERSION)
DOCKER_TEST_PASS=testzkop@123
DOCKER_TEST_USER=testzkop
IMG?=$(REPO):$(VERSION)
.PHONY: all build check clean test
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# Install CRDs into a cluster
# Server-side apply: the CRD exceeds the 256KiB last-applied-configuration
# annotation limit of client-side apply.
install: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl apply --server-side -f -
# Uninstall CRDs from a cluster
uninstall: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl delete -f -
crds: ## Generate CRDs
- make controller-gen
- $(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./..." output:crd:artifacts:config=config/crd/bases
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image pravega/zookeeper-operator=$(TEST_IMAGE)
$(KUSTOMIZE) build config/default | kubectl apply --server-side -f -
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy-test: manifests kustomize
$(KUSTOMIZE) build config/test | kubectl apply --server-side -f -
# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config
undeploy-test: manifests kustomize
$(KUSTOMIZE) build config/test | kubectl delete --ignore-not-found -f -
# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config
undeploy:
$(KUSTOMIZE) build config/default | kubectl delete -f -
# Run go fmt against code
fmt:
go fmt ./...
# Run go vet against code
vet:
go vet ./...
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
## Tool Versions
# Upgraded to modern stable versions
KUSTOMIZE_VERSION ?= v5.8.3
CONTROLLER_TOOLS_VERSION ?= v0.23.0
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
.PHONY: controller-gen
controller-gen: $(LOCALBIN) ## Install controller-gen locally at the configured version.
test -x "$(CONTROLLER_GEN)" && \
test "$$("$(CONTROLLER_GEN)" --version)" = "Version: $(CONTROLLER_TOOLS_VERSION)" || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
all: generate check build
generate: controller-gen
$(CONTROLLER_GEN) object paths="./..."
make manifests
# sync crd generated to helm-chart
echo '{{- if .Values.crd.create }}' > charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml
cat config/crd/bases/zookeeper.pravega.io_zookeeperclusters.yaml >> charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml
echo '{{- end }}' >> charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml
build: test build-go build-image
build-go:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags "-X $(MODULE)/pkg/version.Version=$(VERSION) -X $(MODULE)/pkg/version.GitSHA=$(GIT_SHA)" \
-o bin/$(PROJECT_NAME)-linux-amd64 main.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags "-X $(MODULE)/pkg/version.Version=$(VERSION) -X $(MODULE)/pkg/version.GitSHA=$(GIT_SHA)" \
-o bin/$(EXPORTER_NAME)-linux-amd64 cmd/exporter/main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build \
-ldflags "-X $(MODULE)/pkg/version.Version=$(VERSION) -X $(MODULE)/pkg/version.GitSHA=$(GIT_SHA)" \
-o bin/$(PROJECT_NAME)-darwin-amd64 main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build \
-ldflags "-X $(MODULE)/pkg/version.Version=$(VERSION) -X $(MODULE)/pkg/version.GitSHA=$(GIT_SHA)" \
-o bin/$(EXPORTER_NAME)-darwin-amd64 cmd/exporter/main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build \
-ldflags "-X $(MODULE)/pkg/version.Version=$(VERSION) -X $(MODULE)/pkg/version.GitSHA=$(GIT_SHA)" \
-o bin/$(PROJECT_NAME)-windows-amd64.exe main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build \
-ldflags "-X $(MODULE)/pkg/version.Version=$(VERSION) -X $(MODULE)/pkg/version.GitSHA=$(GIT_SHA)" \
-o bin/$(EXPORTER_NAME)-windows-amd64.exe cmd/exporter/main.go
build-image:
docker build --build-arg VERSION=$(VERSION) --build-arg GIT_SHA=$(GIT_SHA) --build-arg GO_VERSION=$(GO_VERSION) -t $(REPO):$(VERSION) .
docker tag $(REPO):$(VERSION) $(REPO):latest
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
# - 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)
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
PLATFORMS ?= linux/arm64,linux/amd64
.PHONY: docker-buildx
docker-buildx: ## Build and push docker image for the manager for cross-platform support
# The Dockerfile cross-compiles natively using BUILDPLATFORM + TARGETOS/TARGETARCH, so it is built directly.
- docker buildx create --name zookeeper-builder
docker buildx use zookeeper-builder
docker buildx build --push --platform=$(PLATFORMS) --build-arg GO_VERSION=$(GO_VERSION) --tag $(IMG) .
- docker buildx rm zookeeper-builder
build-zk-image:
zk_version="$$(./scripts/zookeeper-version.sh)" && \
docker build --build-arg ZK_VERSION="$$zk_version" -t $(APP_REPO):$(VERSION)-apache ./docker/zookeeper-image
docker build --build-arg VERSION=$(VERSION) --build-arg DOCKER_REGISTRY=$(DOCKER_REGISTRY) --build-arg GIT_SHA=$(GIT_SHA) \
--build-arg BASE_IMAGE=$(APP_REPO):$(VERSION)-apache -t $(APP_REPO):$(VERSION) ./docker
docker tag $(APP_REPO):$(VERSION) $(APP_REPO):latest
build-zk-image-swarm:
docker build --build-arg VERSION=$(VERSION)-swarm --build-arg DOCKER_REGISTRY=$(DOCKER_REGISTRY) --build-arg GIT_SHA=$(GIT_SHA) \
-f ./docker/Dockerfile-swarm -t $(APP_REPO):$(VERSION)-swarm ./docker
test:
go test $$(go list ./... | grep -v /vendor/ | grep -v /test/e2e) -race -coverprofile=coverage.txt -covermode=atomic
test-e2e: test-e2e-remote
test-e2e-remote:
make test-login
docker build . -t $(TEST_IMAGE)
docker push $(TEST_IMAGE)
make deploy
RUN_LOCAL=false go test -v -timeout 2h ./test/e2e... -args -ginkgo.v
make undeploy
test-e2e-local:
make deploy-test
RUN_LOCAL=true go test -v -timeout 2h ./test/e2e... -args -ginkgo.v
make undeploy-test
run-local:
go run ./main.go
login:
@docker login -u "$(DOCKER_USER)" -p "$(DOCKER_PASS)"
test-login:
echo "$(DOCKER_TEST_PASS)" | docker login -u "$(DOCKER_TEST_USER)" --password-stdin
push: build-image build-zk-image login
docker push $(REPO):$(VERSION)
docker push $(REPO):latest
docker push $(APP_REPO):$(VERSION)
docker push $(APP_REPO):latest
clean:
rm -f bin/$(PROJECT_NAME)
check: check-format check-license
check-format:
./scripts/check_format.sh
check-license:
./scripts/check_license.sh