Created
December 19, 2022 06:18
-
-
Save itudoben/3538e3d0020fb8a525756163aa02b0d1 to your computer and use it in GitHub Desktop.
gke client-2.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: batch/v1 | |
kind: Job | |
metadata: | |
name: benchmark-0 | |
labels: | |
app: benchmark | |
role: main | |
tier: backend | |
mode: base | |
namespace: {{.Env.NAMESPACE}} | |
spec: | |
backoffLimit: 0 | |
template: | |
metadata: | |
labels: | |
app: benchmark | |
role: main | |
tier: backend | |
spec: | |
restartPolicy: Never | |
tolerations: | |
- key: "benchmark.siren.io/job" | |
operator: "Equal" | |
value: "client-2.0" | |
effect: "NoSchedule" | |
affinity: | |
nodeAffinity: | |
requiredDuringSchedulingIgnoredDuringExecution: | |
nodeSelectorTerms: | |
- matchExpressions: | |
{{.Env.NODE_SELECTOR}} | |
podAntiAffinity: | |
requiredDuringSchedulingIgnoredDuringExecution: | |
- labelSelector: | |
matchExpressions: | |
- key: role | |
operator: In | |
values: | |
- data | |
- master | |
- monitor | |
topologyKey: "kubernetes.io/hostname" | |
initContainers: | |
- name: sysctl | |
image: alpine:3.12 | |
resources: | |
limits: | |
memory: 2Gi | |
cpu: 1 | |
securityContext: | |
privileged: true | |
command: | |
- sh | |
- -c | |
- | | |
apk --update add curl | |
# An expired access token may fail the creation of the pod in case the first one fails | |
# https://sirensolutions.atlassian.net/browse/FEDE-5591 | |
script_path="{{ .Env.CONTAINER_DIR_BENCHMARK_SOURCE }}/src/main/bash/benchmark-cluster.sh" | |
if [[ -f "$script_path" ]]; then | |
echo 'Benchmark bundle {{ .Env.BENCHMARK_BUNDLE_NAME }} is already installed in directory {{ .Env.CONTAINER_DIR_BENCHMARK_SOURCE }}.' | |
else | |
echo 'Download benchmark bundle {{ .Env.BENCHMARK_BUNDLE_NAME }}.' | |
curl -X GET -H "Authorization: Bearer $(cat /gcloud-dir/accesstoken)" "https://storage.googleapis.com/tmp-benchmark-bundles/{{ .Env.BENCHMARK_BUNDLE_NAME }}" -o /tmp/benchmark.tar.bz2 | |
if [[ "$?" -gt '0' ]]; then | |
>&2 echo $(date -u "+%c") 'Cannot download the benchmark bundle benchmark-bundles/{{ .Env.BENCHMARK_BUNDLE_NAME }} from Google Cloud Storage. Access token may have expired.' | |
>&2 echo "FAILURE cannot initialize container 'sysctl' of Pod '$(hostname)'" | |
exit 100 | |
fi | |
# Create the benchmark directory | |
echo 'Install benchmark bundle {{ .Env.BENCHMARK_BUNDLE_NAME }} into directory {{ .Env.CONTAINER_DIR_BENCHMARK_SOURCE }}' | |
mkdir -p {{ .Env.CONTAINER_DIR_BENCHMARK_SOURCE }} | |
tar -xvj -f /tmp/benchmark.tar.bz2 -C {{ .Env.CONTAINER_DIR_BENCHMARK_SOURCE }} 2>&1 > /dev/null | |
fi | |
# Check and wait for Federate cluster to be operational through the es-discovery service | |
max_tries=5 # 5 minutes | |
tries=$max_tries | |
es_discovery_ready='false' | |
while [[ $tries -gt 0 ]]; do | |
echo "Check $((max_tries - tries + 1))/$max_tries for es-discovery to be up" | |
if [[ $(curl -kw '%{response_code}' http://es-discovery:9200/_cluster/health -o /dev/null) -eq 200 ]]; then | |
echo "es-discovery service is ready" | |
es_discovery_ready='true' | |
break | |
else | |
sleep 30 | |
fi | |
tries=$((tries - 1)) | |
done | |
if [[ "$es_discovery_ready" == 'false' ]]; then | |
>&2 echo $(date -u "+%c") 'Timeout: failed to check es-discovery is up!' | |
>&2 echo "FAILURE cannot initialize container 'sysctl' of Pod '$(hostname)'" | |
exit 101 | |
fi | |
# Good to go! | |
echo $(date -u "+%c") Init container 'sysctl' of Pod '$(hostname)' initialized | |
volumeMounts: | |
- name: benchmark-vol | |
mountPath: {{ .Env.CONTAINER_DIR_BUILD }} | |
- name: vol-benchmark-secrets | |
mountPath: /gcloud-dir | |
readOnly: true | |
containers: | |
- name: jmeter | |
image: gradle:7.4.2-jdk11@sha256:d2d6c2e424b334f916745e8f74a56c0c2e7ee92c62ad50bc17e5a7adedef237b | |
imagePullPolicy: IfNotPresent | |
resources: | |
limits: | |
memory: 4Gi | |
cpu: 1.5 | |
command: | |
- /bin/bash | |
- -c | |
- | | |
apt update | |
apt install -y unzip zip git | |
curl -s "https://get.sdkman.io" | bash | |
source "/root/.sdkman/bin/sdkman-init.sh" | |
sdk install groovy | |
# TODO: Leverage .netrc https://sirensolutions.atlassian.net/browse/FEDE-5495 | |
export GITHUB_CREDENTIALS="$(cat /benchmark-secrets-dir/github_credentials)" | |
export ARTIFACTORY_API_KEY="$(cat /benchmark-secrets-dir/artifactory_api_key)" | |
export METRICS_FEDERATE_PASSWORD="$(cat /benchmark-secrets-dir/metrics_federate_password)" | |
# TODO: set ~/.m2/settings.xml https://sirensolutions.atlassian.net/browse/FEDE-5606 | |
# TODO: Leverage .netrc https://sirensolutions.atlassian.net/browse/FEDE-5495 | |
cp "/benchmark-secrets-dir/netrc" $HOME/.netrc | |
chmod 600 $HOME/.netrc | |
echo Listing contents of {{ .Env.CONTAINER_DIR_BENCHMARK_SOURCE }} from benchmarks bundle {{ .Env.BENCHMARK_BUNDLE_NAME }} | |
ls -l {{ .Env.CONTAINER_DIR_BENCHMARK_SOURCE }} | |
cmd="{{ .Env.CONTAINER_DIR_BENCHMARK_SOURCE }}/src/main/bash/benchmark-cluster.sh \ | |
{{ .Env.GRADLE_TASKS_ARGUMENTS }} {{ .Env.GRADLE_TASKS }} | tee -a \"{{ .Env.FILE_LOG_BENCHMARK }}\"" | |
echo "Running: $cmd" | |
eval $cmd | |
echo $(date -u "+%c") benchmark results in {{ .Env.CONTAINER_DIR_RESULTS }} | |
echo $(date -u "+%c") JMeter container finished | |
volumeMounts: | |
- name: benchmark-vol | |
mountPath: {{.Env.CONTAINER_DIR_BUILD}} | |
- name: vol-benchmark-secrets-sec | |
mountPath: /benchmark-secrets-dir | |
readOnly: true | |
volumes: | |
- name: benchmark-vol | |
emptyDir: {} | |
- name: vol-benchmark-secrets | |
secret: | |
secretName: {{.Env.SECRET_NAME}} | |
- name: vol-benchmark-secrets-sec | |
secret: | |
secretName: benchmark-secrets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment