-
Notifications
You must be signed in to change notification settings - Fork 69
/
Makefile
299 lines (231 loc) · 8.23 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# Image URL to use all building/pushing image targets
IMG ?= oamdev/terraform-controller:0.2.8
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
TIME_SHORT = `date +%H:%M:%S`
TIME = $(TIME_SHORT)
GREEN := $(shell printf "\033[32m")
CNone := $(shell printf "\033[0m")
OK = echo ${TIME} ${GREEN}[ OK ]${CNone}
# 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
all: manager
# Run tests
test: generate fmt vet manifests
go test -coverprofile=ut-coverage1.xml ./controllers/...
# Build manager binary
manager: generate fmt vet
go build -o bin/manager main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests
go run ./main.go
# Install CRDs into a cluster
install: manifests
kubectl apply -f chart/crds
# Uninstall CRDs from a cluster
uninstall: manifests
kustomize build chart/crds | kubectl delete -f -
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests
cd config/manager && kustomize edit set image controller=${IMG}
kustomize build config/default | kubectl apply -f -
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) webhook paths="./..." output:crd:artifacts:config=chart/crds
# Run go fmt against code
fmt: goimports
go fmt ./...
# Run go vet against code
vet:
go vet ./...
# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Build the docker image
docker-build: test
docker build . -t ${IMG}
# Push the docker image
docker-push:
docker push ${IMG}
# Make helm chart
chart: docker-build docker-push
helm package chart --destination .
# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go install sigs.k8s.io/controller-tools/cmd/[email protected] ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
GOLANGCILINT_VERSION ?= v1.50.1
HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
HOSTARCH := $(shell uname -m)
ifeq ($(HOSTARCH),x86_64)
HOSTARCH := amd64
endif
golangci:
ifneq ($(shell which golangci-lint),)
@$(OK) golangci-lint is already installed
GOLANGCILINT=$(shell which golangci-lint)
else ifeq (, $(shell which $(GOBIN)/golangci-lint))
@{ \
set -e ;\
echo 'installing golangci-lint-$(GOLANGCILINT_VERSION)' ;\
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) $(GOLANGCILINT_VERSION) ;\
echo 'Successfully installed' ;\
}
GOLANGCILINT=$(GOBIN)/golangci-lint
else
@$(OK) golangci-lint is already installed
GOLANGCILINT=$(GOBIN)/golangci-lint
endif
lint: golangci
$(GOLANGCILINT) run ./...
reviewable: manifests fmt vet lint
go mod tidy
# Execute auto-gen code commands and ensure branch is clean.
check-diff: reviewable
git --no-pager diff
git diff --quiet || ($(ERR) please run 'make reviewable' to include all changes && false)
@$(OK) branch is clean
.PHONY: goimports
goimports:
ifeq (, $(shell which goimports))
@{ \
set -e ;\
GO111MODULE=off go get -u golang.org/x/tools/cmd/goimports ;\
}
GOIMPORTS=$(GOBIN)/goimports
else
GOIMPORTS=$(shell which goimports)
endif
install-chart:
helm lint ./chart
helm upgrade --install --create-namespace --namespace terraform terraform-controller ./chart
helm test -n terraform terraform-controller --timeout 5m
kubectl get pod -n terraform -l "app=terraform-controller"
# load docker image to the kind cluster
kind-load:
docker build -t oamdev/terraform-controller:e2e .
kind load docker-image oamdev/terraform-controller:e2e
alibaba-credentials:
ifeq (, $(ALICLOUD_ACCESS_KEY))
@echo "Environment variable ALICLOUD_ACCESS_KEY is not set"
exit 1
endif
ifeq (, $(ALICLOUD_SECRET_KEY))
@echo "Environment variable ALICLOUD_SECRET_KEY is not set"
exit 1
endif
echo "accessKeyID: ${ALICLOUD_ACCESS_KEY}\naccessKeySecret: ${ALICLOUD_SECRET_KEY}\nsecurityToken: ${ALICLOUD_SECURITY_TOKEN}" > alibaba-credentials.conf
kubectl create secret generic alibaba-account-creds -n vela-system --from-file=credentials=alibaba-credentials.conf
rm -f alibaba-credentials.conf
kubectl get secret -n vela-system alibaba-account-creds
alibaba-provider:
kubectl apply -f examples/alibaba/provider.yaml
alibaba: alibaba-credentials alibaba-provider
aws-credentials:
ifeq (, $(AWS_ACCESS_KEY_ID))
@echo "Environment variable AWS_ACCESS_KEY_ID is not set"
exit 1
endif
ifeq (, $(AWS_SECRET_ACCESS_KEY))
@echo "Environment variable AWS_SECRET_ACCESS_KEY is not set"
exit 1
endif
# refer to https://registry.terraform.io/providers/hashicorp/aws/latest/docs
echo "awsAccessKeyID: ${AWS_ACCESS_KEY_ID}\nawsSecretAccessKey: ${AWS_SECRET_ACCESS_KEY}\nawsSessionToken: ${AWS_SESSION_TOKEN}" > aws-credentials.conf
kubectl create secret generic aws-account-creds -n vela-system --from-file=credentials=aws-credentials.conf
rm -f aws-credentials.conf
aws-provider:
kubectl apply -f examples/aws/provider.yaml
aws: aws-credentials aws-provider
azure-credentials:
ifeq (, $(ARM_CLIENT_ID))
@echo "Environment variable ARM_CLIENT_ID is not set"
exit 1
endif
ifeq (, $(ARM_CLIENT_SECRET))
@echo "Environment variable ARM_CLIENT_SECRET is not set"
exit 1
endif
ifeq (, $(ARM_SUBSCRIPTION_ID))
@echo "Environment variable ARM_SUBSCRIPTION_ID is not set"
exit 1
endif
ifeq (, $(ARM_TENANT_ID))
@echo "Environment variable ARM_TENANT_ID is not set"
exit 1
endif
echo "armClientID: ${ARM_CLIENT_ID}\narmClientSecret: ${ARM_CLIENT_SECRET}\narmSubscriptionID: ${ARM_SUBSCRIPTION_ID}\narmTenantID: ${ARM_TENANT_ID}" > azure-credentials.conf
kubectl create secret generic azure-account-creds -n vela-system --from-file=credentials=azure-credentials.conf
rm -f azure-credentials.conf
azure-provider:
kubectl apply -f examples/azure/provider.yaml
azure: azure-credentials azure-provider
ucloud-credentials:
ifeq (, $(UCLOUD_PRIVATE_KEY))
@echo "Environment variable UCLOUD_PRIVATE_KEY is not set"
exit 1
endif
ifeq (, $(UCLOUD_PUBLIC_KEY))
@echo "Environment variable UCLOUD_PUBLIC_KEY is not set"
exit 1
endif
ifeq (, $(UCLOUD_PROJECT_ID))
@echo "Environment variable UCLOUD_PROJECT_ID is not set"
exit 1
endif
ifeq (, $(UCLOUD_REGION))
@echo "Environment variable UCLOUD_REGION is not set"
exit 1
endif
echo "publicKey: ${UCLOUD_PUBLIC_KEY}\nprivateKey: ${UCLOUD_PRIVATE_KEY}\nregion: ${UCLOUD_REGION}\nprojectID: ${UCLOUD_PROJECT_ID}" > ucloud-credentials.conf
kubectl create secret generic ucloud-account-creds -n vela-system --from-file=credentials=ucloud-credentials.conf
rm -f ucloud-credentials.conf
ucloud-provider:
kubectl apply -f examples/ucloud/provider.yaml
ucloud: ucloud-credentials ucloud-provider
custom-credentials:
echo "Token: mytoken" > custom-credentials.conf
kubectl create secret generic custom-account-creds -n vela-system --from-file=credentials=custom-credentials.conf
rm -f custom-credentials.conf
custom-provider:
kubectl apply -f examples/custom/provider.yaml
custom: custom-credentials custom-provider
configuration:
go test -coverprofile=e2e-coverage1.xml -v $(shell go list ./e2e/...|grep -v controllernamespace) -count=1
go test -v ./e2e/controllernamespace/...
e2e-setup: install-chart alibaba
e2e: e2e-setup configuration
e2e-gitee:
go test -coverprofile=e2e-gitee-coverage1.xml -v ./gitee/...
tencent-credentials:
ifeq (, $(TENCENTCLOUD_SECRET_ID))
@echo "Environment variable TENCENTCLOUD_SECRET_ID is not set"
exit 1
endif
ifeq (, $(TENCENTCLOUD_SECRET_KEY))
@echo "Environment variable TENCENTCLOUD_SECRET_KEY is not set"
exit 1
endif
echo "secretID: ${TENCENTCLOUD_SECRET_ID}\nsecretKey: ${TENCENTCLOUD_SECRET_KEY}" > tencent-credentials.conf
kubectl create secret generic tencent-account-creds -n vela-system --from-file=credentials=tencent-credentials.conf
rm -f tencent-credentials.conf
kubectl get secret -n vela-system tencent-account-creds
tencent-provider:
kubectl apply -f examples/tencent/provider.yaml
tencent: tencent-credentials tencent-provider