-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathMakefile
231 lines (192 loc) · 6.75 KB
/
Makefile
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
PROJECT := arangodb_operator
SCRIPTDIR := $(shell pwd)
ROOTDIR := $(shell cd $(SCRIPTDIR) && pwd)
VERSION := $(shell cat $(ROOTDIR)/VERSION)
VERSION_MAJOR_MINOR_PATCH := $(shell echo $(VERSION) | cut -f 1 -d '+')
VERSION_MAJOR_MINOR := $(shell echo $(VERSION_MAJOR_MINOR_PATCH) | cut -f 1,2 -d '.')
VERSION_MAJOR := $(shell echo $(VERSION_MAJOR_MINOR) | cut -f 1 -d '.')
COMMIT := $(shell git rev-parse --short HEAD)
DOCKERCLI := $(shell which docker)
GOBUILDDIR := $(SCRIPTDIR)/.gobuild
SRCDIR := $(SCRIPTDIR)
BINDIR := $(ROOTDIR)/bin
VENDORDIR := $(ROOTDIR)/deps
ORGPATH := github.com/arangodb
ORGDIR := $(GOBUILDDIR)/src/$(ORGPATH)
REPONAME := k8s-operator
REPODIR := $(ORGDIR)/$(REPONAME)
REPOPATH := $(ORGPATH)/$(REPONAME)
GOPATH := $(GOBUILDDIR)
GOVERSION := 1.10.0-alpine
PULSAR := $(GOBUILDDIR)/bin/pulsar$(shell go env GOEXE)
ifndef DOCKERNAMESPACE
DOCKERNAMESPACE := arangodb
endif
DOCKERFILE := Dockerfile
DOCKERTESTFILE := Dockerfile.test
ifdef IMAGETAG
IMAGESUFFIX := ":$(IMAGETAG)"
endif
ifndef OPERATORIMAGE
OPERATORIMAGE := $(DOCKERNAMESPACE)/arangodb-operator$(IMAGESUFFIX)
endif
ifndef TESTIMAGE
TESTIMAGE := $(DOCKERNAMESPACE)/arangodb-operator-test$(IMAGESUFFIX)
endif
ifndef ENTERPRISEIMAGE
ENTERPRISEIMAGE := $(DEFAULTENTERPRISEIMAGE)
endif
BINNAME := $(PROJECT)
BIN := $(BINDIR)/$(BINNAME)
TESTBINNAME := $(PROJECT)_test
TESTBIN := $(BINDIR)/$(TESTBINNAME)
RELEASE := $(GOBUILDDIR)/bin/release
GHRELEASE := $(GOBUILDDIR)/bin/github-release
ifndef TESTNAMESPACE
TESTNAMESPACE := arangodb-operator-tests
endif
SOURCES := $(shell find $(SRCDIR) -name '*.go' -not -path './test/*')
.PHONY: all clean deps docker update-vendor update-generated verify-generated
all: verify-generated docker
#
# Tip: Run `eval $(minikube docker-env)` before calling make if you're developing on minikube.
#
build: docker
clean:
rm -Rf $(BIN) $(BINDIR) $(GOBUILDDIR)
deps:
@${MAKE} -B -s $(GOBUILDDIR)
$(GOBUILDDIR):
# Build pulsar from vendor
@mkdir -p $(GOBUILDDIR)
@ln -sf $(VENDORDIR) $(GOBUILDDIR)/src
@GOPATH=$(GOBUILDDIR) go install github.com/pulcy/pulsar
@rm -Rf $(GOBUILDDIR)/src
# Prepare .gobuild directory
@mkdir -p $(ORGDIR)
@rm -f $(REPODIR) && ln -sf ../../../.. $(REPODIR)
GOPATH=$(GOBUILDDIR) $(PULSAR) go flatten -V $(VENDORDIR)
update-vendor:
@mkdir -p $(GOBUILDDIR)
@GOPATH=$(GOBUILDDIR) go get github.com/pulcy/pulsar
@rm -Rf $(VENDORDIR)
@mkdir -p $(VENDORDIR)
@git clone https://github.com/kubernetes/code-generator.git $(VENDORDIR)/k8s.io/code-generator
@rm -Rf $(VENDORDIR)/k8s.io/code-generator/.git
@$(PULSAR) go vendor -V $(VENDORDIR) \
k8s.io/client-go/... \
k8s.io/gengo/args \
k8s.io/apiextensions-apiserver \
github.com/arangodb/go-driver \
github.com/cenkalti/backoff \
github.com/dchest/uniuri \
github.com/dgrijalva/jwt-go \
github.com/pkg/errors \
github.com/prometheus/client_golang/prometheus \
github.com/pulcy/pulsar \
github.com/rs/zerolog \
github.com/spf13/cobra
@$(PULSAR) go flatten -V $(VENDORDIR) $(VENDORDIR)
@${MAKE} -B -s clean
update-generated: $(GOBUILDDIR)
@docker build $(SRCDIR)/tools/codegen --build-arg GOVERSION=$(GOVERSION) -t k8s-codegen
docker run \
--rm \
-v $(SRCDIR):/usr/code \
-e GOPATH=/usr/code/.gobuild \
-e GOBIN=/usr/code/.gobuild/bin \
-w /usr/code/ \
k8s-codegen \
"./deps/k8s.io/code-generator/generate-groups.sh" \
"all" \
"github.com/arangodb/k8s-operator/pkg/generated" \
"github.com/arangodb/k8s-operator/pkg/apis" \
"arangodb:v1alpha" \
--go-header-file "./tools/codegen/boilerplate.go.txt" \
$(VERIFYARGS)
verify-generated:
@${MAKE} -B -s VERIFYARGS=--verify-only update-generated
$(BIN): $(GOBUILDDIR) $(SOURCES)
@mkdir -p $(BINDIR)
docker run \
--rm \
-v $(SRCDIR):/usr/code \
-e GOPATH=/usr/code/.gobuild \
-e GOOS=linux \
-e GOARCH=amd64 \
-e CGO_ENABLED=0 \
-w /usr/code/ \
golang:$(GOVERSION) \
go build -installsuffix cgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(BINNAME) $(REPOPATH)
docker: $(BIN)
docker build -f $(DOCKERFILE) -t $(OPERATORIMAGE) .
ifdef PUSHIMAGES
docker push $(OPERATORIMAGE)
endif
# Testing
$(TESTBIN): $(GOBUILDDIR) $(SOURCES)
@mkdir -p $(BINDIR)
docker run \
--rm \
-v $(SRCDIR):/usr/code \
-e GOPATH=/usr/code/.gobuild \
-e GOOS=linux \
-e GOARCH=amd64 \
-e CGO_ENABLED=0 \
-w /usr/code/ \
golang:$(GOVERSION) \
go test -c -installsuffix cgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(TESTBINNAME) $(REPOPATH)/tests
docker-test: $(TESTBIN)
docker build --quiet -f $(DOCKERTESTFILE) -t $(TESTIMAGE) .
run-tests: docker-test
ifdef PUSHIMAGES
docker push $(OPERATORIMAGE)
docker push $(TESTIMAGE)
endif
$(ROOTDIR)/scripts/kube_delete_namespace.sh $(TESTNAMESPACE)
kubectl create namespace $(TESTNAMESPACE)
$(ROOTDIR)/examples/setup-rbac.sh --namespace=$(TESTNAMESPACE)
$(ROOTDIR)/scripts/kube_create_operator.sh $(TESTNAMESPACE) $(OPERATORIMAGE)
kubectl --namespace $(TESTNAMESPACE) \
run arangodb-operator-test -i --rm --quiet --restart=Never \
--image=$(TESTIMAGE) \
--env="ENTERPRISEIMAGE=$(ENTERPRISEIMAGE)" \
--env="TEST_NAMESPACE=$(TESTNAMESPACE)" \
-- \
-test.v
kubectl delete namespace $(TESTNAMESPACE) --ignore-not-found --now
cleanup-tests:
kubectl delete namespace $(TESTNAMESPACE) --ignore-not-found --now
# Release building
docker-push: docker
ifneq ($(DOCKERNAMESPACE), arangodb)
docker tag $(OPERATORIMAGE) $(DOCKERNAMESPACE)/arangodb-operator
endif
docker push $(DOCKERNAMESPACE)/arangodb-operator
docker-push-version: docker
docker tag arangodb/arangodb-operator arangodb/arangodb-operator:$(VERSION)
docker tag arangodb/arangodb-operator arangodb/arangodb-operator:$(VERSION_MAJOR_MINOR)
docker tag arangodb/arangodb-operator arangodb/arangodb-operator:$(VERSION_MAJOR)
docker tag arangodb/arangodb-operator arangodb/arangodb-operator:latest
docker push arangodb/arangodb-operator:$(VERSION)
docker push arangodb/arangodb-operator:$(VERSION_MAJOR_MINOR)
docker push arangodb/arangodb-operator:$(VERSION_MAJOR)
docker push arangodb/arangodb-operator:latest
$(RELEASE): $(GOBUILDDIR) $(SOURCES) $(GHRELEASE)
GOPATH=$(GOBUILDDIR) go build -o $(RELEASE) $(REPOPATH)/tools/release
$(GHRELEASE): $(GOBUILDDIR)
GOPATH=$(GOBUILDDIR) go build -o $(GHRELEASE) github.com/aktau/github-release
release-patch: $(RELEASE)
GOPATH=$(GOBUILDDIR) $(RELEASE) -type=patch
release-minor: $(RELEASE)
GOPATH=$(GOBUILDDIR) $(RELEASE) -type=minor
release-major: $(RELEASE)
GOPATH=$(GOBUILDDIR) $(RELEASE) -type=major
## Kubernetes utilities
minikube-start:
minikube start --cpus=4 --memory=6144
delete-operator:
kubectl delete deployment arangodb-operator --ignore-not-found
redeploy-operator: delete-operator
$(ROOTDIR)/scripts/kube_create_operator.sh default $(OPERATORIMAGE)
kubectl get pods