-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile.utils
202 lines (159 loc) · 6.43 KB
/
Makefile.utils
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
OPERATOR_VERSION=$(VERSION)
OPERATOR_HELM_VERSION=0.4.2
CHECKER_HELM_VERSION=0.1.0
TEST_K8S_VER="v1.18.2"
TEST_ETCD_VER="v3.4.3"
ENVTEST_GOPATH="$(shell pwd)/testbin/build_gopath"
install-envtest:
# Can only use `sh`.
GOPATH="$(ENVTEST_GOPATH)" sh scripts/setup_envtest_bins.sh $(TEST_K8S_VER) $(TEST_ETCD_VER)
build: build-image build-helm
echo "build done"
build-image:
echo "building $(IMG)"
$(MAKE) docker-build
$(MAKE) docker-push
build-helm:
helm package helm/undermoon-operator
helm package helm/undermoon-cluster
helm package helm/undermoon-scheduler
install-helm-package:
$(MAKE) build-helm
helm install \
--set "image.operatorImage=$(IMG_NAME)" \
--set "image.operatorImageTag=$(OPERATOR_VERSION)" \
--set "image.operatorImagePullPolicy=Always" \
--set "broker_api_version=v3" \
example-operator "undermoon-operator-$(OPERATOR_HELM_VERSION).tgz"
helm install \
--set "image.undermoonImage=$(UNDERMOON_IMG_NAME)" \
--set "image.undermoonImageTag=$(UNDERMOON_IMG_VERSION)" \
--set "image.undermoonImagePullPolicy=IfNotPresent" \
--set "cluster.disableFailover=false" \
example-undermoon "undermoon-cluster-$(OPERATOR_HELM_VERSION).tgz"
upgrade-helm-package:
$(MAKE) build-helm
helm upgrade \
--set "image.undermoonImage=$(UNDERMOON_IMG_NAME)" \
--set "image.undermoonImageTag=$(UNDERMOON_IMG_VERSION)" \
example-undermoon "undermoon-cluster-$(OPERATOR_HELM_VERSION).tgz"
uninstall-helm-package:
helm uninstall example-undermoon || true
helm uninstall example-operator || true
helm uninstall example-scheduler || true
install-undermoon-scheduler:
$(MAKE) build-helm
helm install \
--set "image.schedulerImage=$(SCHEDULER_IMG_NAME)" \
--set "image.schedulerImageTag=$(SCHEDULER_IMG_VERSION)" \
--set "image.schedulerImagePullPolicy=Always" \
example-scheduler "undermoon-scheduler-$(OPERATOR_HELM_VERSION).tgz"
lint:
$(MAKE) fmt
$(MAKE) vet
golint ./controllers...
golint ./api/v1alpha1...
golint ./scheduler...
golangci-lint run
# Helm Charts development:
helm lint helm/undermoon-operator --strict
helm lint helm/undermoon-cluster --strict
helm lint chaostest/undermoon-checker --strict
# Need to install https://github.com/helm/chart-testing-action
ct lint --charts ./helm/undermoon-operator
ct lint --charts ./helm/undermoon-cluster
ct lint --charts ./chaostest/undermoon-checker
cd checker && $(MAKE) lint
unittest:
go test ./... -run '^(TestUnit)'
lint-chaostest-script:
# pip install -r chaostest/ctrl_requirements.txt
black chaostest
pylint --errors-only chaostest
HELM_CHARTS_CRD_FILE=helm/undermoon-operator/templates/undermoon.operator.api_undermoons_crd.yaml
HELM_CHARTS_RBAC_FILE=helm/undermoon-operator/templates/operator-rbac.yaml
HELM_CHART_OPERATOR_FILE=helm/undermoon-operator/templates/operator.yaml
HELM_CHART_RBAC_FILE=helm/undermoon-operator/templates/operator-rbac.yaml
HELM_CHART_CRD_FILE=helm/undermoon-operator/templates/undermoon.doyoubi.mydomain_undermoons.yaml
HELM_CHART_UNDERMOON_FILE=helm/undermoon-cluster/templates/undermoon.yaml
update-types: kustomize
$(MAKE) generate
$(MAKE) manifests
# Update crd file in Helm Charts
# Remove the "'" to support non-string type.
$(KUSTOMIZE) build config/rbac/overlays/helm | sed "s/\'{{/{{/g" | sed "s/}}\'/}}/g" > $(HELM_CHART_RBAC_FILE)
$(KUSTOMIZE) build config/manager/overlays/helm | sed "s/\'{{/{{/g" | sed "s/}}\'/}}/g" > $(HELM_CHART_OPERATOR_FILE)
$(KUSTOMIZE) build config/crd | sed "s/\'{{/{{/g" | sed "s/}}\'/}}/g" > $(HELM_CHART_CRD_FILE)
$(KUSTOMIZE) build config/cr/overlays/helm | sed "s/\'{{/{{/g" | sed "s/}}\'/}}/g" > $(HELM_CHART_UNDERMOON_FILE)
kind-env-start:
# Run kind with image registry instead of:
# kind create cluster
# See https://kind.sigs.k8s.io/docs/user/local-registry/
# When using image built locally, we need to run `docker run push localhost:5000/docker_image_name`.
scripts/kind-with-registry.sh
kind-env-stop:
./scripts/stop-kind.sh
list-images:
curl http://localhost:5000/v2/_catalog
debug-build:
$(MAKE) docker-build UM_OP_DEBUG=1
$(MAKE) docker-push UM_OP_DEBUG=1
debug-install:
$(MAKE) install-helm-package UM_OP_DEBUG=1
debug-install-scheduler:
$(MAKE) install-undermoon-scheduler UM_OP_DEBUG=1
debug-upgrade:
$(MAKE) upgrade-helm-package UM_OP_DEBUG=1
debug-run:
$(MAKE) install UM_OP_DEBUG=1
$(MAKE) deploy UM_OP_DEBUG=1
debug-logs:
./scripts/operator_logs.sh
debug-start:
$(KUSTOMIZE) build config/cr/overlays/test | kubectl apply -f -
debug-stop:
kubectl delete undermoon --all || true
kubectl delete deployments,service -l control-plane=undermoon-operator || true
kubectl delete role,rolebinding --all || true
$(MAKE) uninstall
debug-edit:
kubectl edit undermoon/example-undermoon
run-busybox:
kubectl run -i --tty --rm debug-busybox --image=busybox --restart=Never -- sh
run-jq-curl:
kubectl run -i --tty --rm debug-jq-curl --image=dwdraju/alpine-curl-jq --restart=Never -- sh
run-redis-cli:
kubectl run -i --tty --rm debug-redis-cli --image=redis --restart=Never -- bash
# TODO: Need to upgrade.
# e2e-test:
# kubectl create namespace e2etest || true
# operator-sdk test local --debug --operator-namespace e2etest ./test/e2e --go-test-flags "-v"
# cleanup-e2e-test:
# kubectl delete namespace e2etest || true
docker-build-scheduler-image:
docker image build -f scheduler/Dockerfile -t undermoon-scheduler .
docker tag undermoon-scheduler localhost:5000/undermoon-scheduler
docker push localhost:5000/undermoon-scheduler
docker-build-checker-image:
docker image build -f chaostest/Dockerfile -t undermoon_checker .
docker tag undermoon_checker localhost:5000/undermoon_checker
docker push localhost:5000/undermoon_checker
docker-build-go-checker-image:
docker image build -f checker/Dockerfile -t undermoon_checker .
docker tag undermoon_checker localhost:5000/undermoon_checker
docker push localhost:5000/undermoon_checker
install-undermoon-checker:
helm package chaostest/undermoon-checker
helm install example-checker "undermoon-checker-$(CHECKER_HELM_VERSION).tgz"
install-undermoon-chaos-checker:
helm package chaostest/undermoon-checker
helm install --set chaos=true example-checker "undermoon-checker-$(CHECKER_HELM_VERSION).tgz"
uninstall-undermoon-checker:
helm uninstall example-checker
checker-logs:
./scripts/checker_logs.sh
test-ctrl:
python chaostest/test_controller.py example-undermoon disable-killing
test-chaos-ctrl:
python chaostest/test_controller.py example-undermoon enable-killing
.PHONY: build test lint update-types minikube-env debug-run debug-start debug-stop