forked from TykTechnologies/tyk-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
238 lines (176 loc) · 8.11 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
# Default bundle image tag
BUNDLE_IMG ?= controller-bundle:$(VERSION)
# Options for 'bundle-build'
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
TYK_VERSION ?= v5.2
# Image URL to use all building/pushing image targets
IMG ?= tyk-operator:latest
TAG = $(lastword $(subst :, ,$(IMG)))
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
#The name of the kind cluster used for development
CLUSTER_NAME ?= kind
# 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 cover.out
# Run tests
# skip bdd when doing unit testing
UNIT_TEST=$(shell go list ./... | grep -v bdd)
test: generate fmt vet manifests
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
setup-envtest --arch=amd64 use
go test ${UNIT_TEST} -coverprofile test_coverage.out --timeout 30m
manager: generate fmt vet ## build manager binary
go build -o bin/manager main.go
run: generate fmt vet manifests ## Run against the configured Kubernetes cluster in ~/.kube/config
TYK_URL=${TYK_URL} TYK_MODE=${TYK_MODE} TYK_TLS_INSECURE_SKIP_VERIFY=${TYK_TLS_INSECURE_SKIP_VERIFY} TYK_AUTH=${TYK_AUTH} TYK_ORG=${TYK_ORG} ENABLE_WEBHOOKS=${ENABLE_WEBHOOKS} go run ./main.go
log: ## This will print logs of Tyk Operator pod.
$(eval POD=$(shell kubectl get pod -l control-plane=tyk-operator-controller-manager -n tyk-operator-system -o name))
kubectl logs -n tyk-operator-system ${POD} -c manager -f
install: manifests kustomize ## Install CRDs into a cluster
$(KUSTOMIZE) build config/crd | kubectl apply -f -
uninstall: manifests kustomize ## Uninstall CRDs from a cluster
$(KUSTOMIZE) build config/crd | kubectl delete -f -
deploy: manifests kustomize ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
helm: kustomize ## Update helm charts
$(KUSTOMIZE) version
$(KUSTOMIZE) build config/crd > ./helm/crds/crds.yaml
$(KUSTOMIZE) build config/helm |go run hack/helm/pre_helm.go > ./helm/templates/all.yaml
manifests: controller-gen ## Generate manifests
$(CONTROLLER_GEN) --version
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
fmt: ## Run go fmt against code
go fmt ./...
gofmt -s -w .
vet: ## Run go vet against code
go vet ./...
golangci-lint: ## Run golangci-lint linter
golangci-lint run
linters: fmt vet golangci-lint ## Run all linters once
generate: controller-gen ## Generate code
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
docker-build: test ## Build the docker image
docker build . -t ${IMG}
docker-build-notest: ## Build the docker image
docker build . -t ${IMG}
docker-push: ## Push the docker image
docker push ${IMG}
release: ## Make release
# fail if version is not specified
ifndef VERSION
$(error VERSION is not specified)
endif
git checkout master
yq eval -i '.version="${VERSION}"' helm/Chart.yaml
yq eval -i '.image.tag="v${VERSION}"' helm/values.yaml
git add helm/Chart.yaml helm/values.yaml
git commit -m "version to: v${VERSION}"
git push origin master && git tag v${VERSION} && git push --tags
##@ Build Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.4.1
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 -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
.PHONY: bundle
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
operator-sdk generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle
.PHONY: bundle-build
bundle-build: ## Build the bundle image.
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
.PHONY: cross-build-image
cross-build-image: ## Build docker image
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager.linux main.go
docker build -f cross.Dockerfile . -t ${IMG}
.PHONY: install-cert-manager
install-cert-manager: ## Install cert manager
@echo "===> installing cert-manager"
kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v1.0.4/cert-manager.yaml
kubectl rollout status deployment/cert-manager -n cert-manager
kubectl rollout status deployment/cert-manager-cainjector -n cert-manager
kubectl rollout status deployment/cert-manager-webhook -n cert-manager
.PHONY: install-operator-helm
install-operator-helm: cross-build-image manifests helm ## Install operator using helm
@echo "===> installing operator with helm"
go run hack/cluster/load_image.go -image ${IMG} -cluster=${CLUSTER_NAME}
helm install ci ./helm --values ./ci/helm_values.yaml --set image.tag=${TAG} -n tyk-operator-system --wait
.PHONY: scrap
scrap: generate manifests helm cross-build-image ## Re-install operator with helm
@echo "===> re installing operator with helm"
go run hack/cluster/load_image.go -image ${IMG} -cluster=${CLUSTER_NAME}
helm uninstall ci -n tyk-operator-system
kubectl apply -f ./helm/crds
helm install ci ./helm --values ./ci/helm_values.yaml -n tyk-operator-system --wait
.PHONY: setup-pro
setup-pro: ## Install Tyk Pro
helm repo add tyk-helm https://helm.tyk.io/public/helm/charts/
helm repo update
go run hack/bootstrap/create/main.go -debug -mode=pro -cluster=${CLUSTER_NAME} -tyk_version=$(TYK_VERSION)
.PHONY: setup-ce
setup-ce: ## Install Tyk CE
helm repo add tyk-helm https://helm.tyk.io/public/helm/charts/
helm repo update
go run hack/bootstrap/create/main.go -debug -mode=ce -cluster=${CLUSTER_NAME} -tyk_version=$(TYK_VERSION)
.PHONY: boot-pro
boot-pro: setup-pro install-operator-helm ## Install Tyk Pro and Operator
@echo "******** Successful boot strapped pro dev env ************"
.PHONY: boot-ce
boot-ce:setup-ce install-operator-helm ## Install Tyk CE and Operator
@echo "******** Successful boot strapped ce dev env ************"
.PHONY: bdd
bdd:
go test -timeout 400s -coverprofile bdd_coverage.out -v ./bdd
.PHONY: test-all
test-all: test bdd ## Run tests
.PHONY: create-kind-cluster
create-kind-cluster: ## Create kind cluster
kind create cluster --config hack/kind.yaml --name=${CLUSTER_NAME}
.PHONY: clean
clean: ## Delete kind cluster
kind delete cluster --name=${CLUSTER_NAME}
.PHONY: install-venom
install-venom:
ifeq (, $(venom version))
@echo "Installing venom"
sudo curl https://github.com/ovh/venom/releases/download/v1.0.1/venom.linux-amd64 -L -o /usr/local/bin/venom && sudo chmod +x /usr/local/bin/venom
else
@echo "Venom is already installed"
endif
.PHONY: run-venom-tests
run-venom-tests: install-venom ## Run Venom integration tests
cd venom-tests && IS_TTY=true venom run
help:
@fgrep -h "##" Makefile | fgrep -v fgrep |sed -e 's/\\$$//' |sed -e 's/:/-:/'| sed -e 's/:.*##//'