-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
172 lines (141 loc) · 6.68 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
##################################################
# Variables #
##################################################
SHELL = /bin/bash
TEST_CLUSTER_NAME ?= cluster
TF_AZURE_SUBSCRIPTION ?= subscription
TF_AZURE_RESOURCE_GROUP ?= resource_group
TF_GRAFANA_PROMETHEUS_URL ?= url
TF_GRAFANA_PROMETHEUS_USER ?= user
TF_GRAFANA_PROMETHEUS_PASSWORD ?= password
TF_GRAFANA_TOKEN ?= token
INJECT_FAULTS ?= 0
KEDA_DOCKER_TAG ?= main
KEDA_GITHUB_TAG ?= main
GRAFANA_PROMETHEUS_URL_PUSH ?= $(TF_GRAFANA_PROMETHEUS_URL)/api/prom/push
GRAFANA_PROMETHEUS_URL_QUERY ?= $(TF_GRAFANA_PROMETHEUS_URL)/api/prom
PROMETHEUS_NAMESPACE ?= prometheus-performance
K6_OPERATOR_NAMESPACE = k6-operator-system
REPO_URL ?= https://github.com/kedacore/keda-performance.git
REPO_BRANCH ?= main
TEST_CONFIG ?= config.json
TEST_FILE ?= tests/test-scaledobject.js
TEST_CASE ?= ScaledObject
NODE_POOL_SIZE ?= 1
##################################################
# Kubernetes context #
##################################################
az-login:
@az login --service-principal -u $(TF_AZURE_SP_APP_ID) -p "$(AZURE_SP_KEY)" --tenant $(TF_AZURE_SP_TENANT)
get-cluster-context: az-login ## Get Azure cluster context.
@az aks get-credentials \
--name $(TEST_CLUSTER_NAME) \
--subscription $(TF_AZURE_SUBSCRIPTION) \
--resource-group $(TF_AZURE_RESOURCE_GROUP)
.PHONY: scale-node-pool
scale-node-pool: az-login ## Scale nodepool.
@az aks scale \
--name $(TEST_CLUSTER_NAME) \
--subscription $(TF_AZURE_SUBSCRIPTION) \
--resource-group $(TF_AZURE_RESOURCE_GROUP) \
--node-count $(NODE_POOL_SIZE)
##################################################
# Deployments #
##################################################
deploy: deploy-otel-collector deploy-keda deploy-k6-operator deploy-prometheus
undeploy: clean-up-testing-namespaces undeploy-prometheus undeploy-k6-operator undeploy-keda undeploy-otel-collector
deploy-keda:
mkdir -p deps
git clone --branch $(KEDA_GITHUB_TAG) https://github.com/kedacore/keda deps/keda --depth 1
VERSION=$(KEDA_DOCKER_TAG) make -C deps/keda deploy
# update resources to 2CPU & 2Gi
kubectl patch deploy keda-operator -n keda --type json -p="[ \
{'op': 'replace', 'path': '/spec/template/spec/containers/0/resources/requests/memory', 'value':'2Gi'}, \
{'op': 'replace', 'path': '/spec/template/spec/containers/0/resources/limits/memory', 'value':'2Gi'}, \
{'op': 'replace', 'path': '/spec/template/spec/containers/0/resources/requests/cpu', 'value':'1'}, \
{'op': 'replace', 'path': '/spec/template/spec/containers/0/resources/limits/cpu', 'value':'1'}, \
]"
undeploy-keda:
make -C deps/keda undeploy
rm -rf deps/keda
deploy-prometheus:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
@helm upgrade --install prometheus \
prometheus-community/prometheus \
--set server.remoteWrite[0].url=$(GRAFANA_PROMETHEUS_URL_PUSH) \
--set server.remoteWrite[0].basic_auth.username=$(TF_GRAFANA_PROMETHEUS_USER) \
--set server.remoteWrite[0].basic_auth.password=$(TF_GRAFANA_PROMETHEUS_PASSWORD) \
--set server.remoteWrite[0].write_relabel_configs[0].replacement=$(KEDA_GITHUB_TAG) \
-f deps/prometheus/values.yaml \
--namespace $(PROMETHEUS_NAMESPACE) \
--create-namespace \
--wait
undeploy-prometheus:
helm uninstall prometheus -n $(PROMETHEUS_NAMESPACE)
kubectl delete ns $(PROMETHEUS_NAMESPACE)
deploy-otel-collector:
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
helm repo update
@helm upgrade --install opentelemetry-collector \
open-telemetry/opentelemetry-collector \
-f deps/otel-collector/values.yaml \
--wait
undeploy-otel-collector:
helm uninstall opentelemetry-collector
# we have to replace this with the helm chart when they release it
# https://github.com/grafana/k6-operator/pull/98
deploy-k6-operator:
mkdir -p deps
git clone https://github.com/grafana/k6-operator deps/k6-operator --depth 1
make -C deps/k6-operator deploy
kubectl create secret generic k6-operator-cloud-token --from-literal="token=$(TF_GRAFANA_TOKEN)" -n $(K6_OPERATOR_NAMESPACE)
kubectl label secret k6-operator-cloud-token -n $(K6_OPERATOR_NAMESPACE) "k6cloud=token"
kubectl annotate secret k6-operator-cloud-token -n $(K6_OPERATOR_NAMESPACE) "kubernetes.io/service-account.name=k6-operator-controller"
undeploy-k6-operator:
make -C deps/k6-operator delete
rm -rf deps/k6-operator
clean-up-testing-namespaces:
kubectl delete ns -l type=e2e
##################################################
# Grafana k6 #
##################################################
execute-k6: execute-k6-scaledobjects
execute-k6-scaledobjects:
@for file in $(shell find ./configs/scaledobjects -maxdepth 1 -not -type d); do \
make execute-k6-case TEST_FILE="tests/test-scaledobject.js" TEST_CASE="ScaledObject" TEST_CONFIG="$${file}" ; \
make print-logs-and-restart-keda ; \
done
execute-k6-case:
helm install k6-test \
chart \
-n $(K6_OPERATOR_NAMESPACE) \
--create-namespace \
--set test.file=$(TEST_FILE) \
--set test.config=$(TEST_CONFIG) \
--set repo.url=$(REPO_URL) \
--set repo.branch=$(REPO_BRANCH) \
--set test.extraConfig.PROMETHEUS_URL=$(GRAFANA_PROMETHEUS_URL_QUERY) \
--set test.extraConfig.PROMETHEUS_USER=$(TF_GRAFANA_PROMETHEUS_USER) \
--set test.extraConfig.PROMETHEUS_PASSWORD=$(TF_GRAFANA_PROMETHEUS_PASSWORD) \
--set test.extraConfig.INJECT_FAULTS=$(INJECT_FAULTS) \
--set test.extraConfig.K6_PROMETHEUS_RW_SERVER_URL=$(GRAFANA_PROMETHEUS_URL_PUSH) \
--set test.extraConfig.K6_PROMETHEUS_RW_USERNAME=$(TF_GRAFANA_PROMETHEUS_USER) \
--set test.extraConfig.K6_PROMETHEUS_RW_PASSWORD=$(TF_GRAFANA_PROMETHEUS_PASSWORD) \
--set test.extraConfig.K6_PROMETHEUS_RW_TREND_AS_NATIVE_HISTOGRAM=true \
--set test.extraArgs="--out cloud --out experimental-prometheus-rw --tag testCase=$(TEST_CASE) --tag testId=$(shell jq -r '.ext.loadimpact.name' '$(TEST_CONFIG)') --tag testRun=$(shell date -u +%FT%TZ) --tag kedaVersion=$(KEDA_GITHUB_TAG)"
./hack/wait-test-case.sh $(K6_OPERATOR_NAMESPACE)
helm uninstall k6-test -n $(K6_OPERATOR_NAMESPACE)
print-logs-and-restart-keda:
kubectl logs -n keda -l name=keda-operator --since=30m --tail=-1
kubectl rollout restart deployment keda-operator -n keda
kubectl rollout status deployment keda-operator -n keda
##################################################
# Linter #
##################################################
install-prettier:
npm install --save-dev --save-exact prettier
lint: install-prettier
npx prettier . --write
verify-lint: install-prettier
npx prettier . --check