Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable/locust] Add support for git sync #641

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions stable/locust/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
name: locust
version: "0.32.2"
version: "0.33.0"
appVersion: 2.32.2
home: https://github.com/locustio/locust
icon: https://locust.io/static/img/logo.png
Expand All @@ -12,7 +12,11 @@ description: |

This chart will setup everything required to run a full distributed locust environment with any amount of workers.

This chart will also create configmaps for storing the locust files in Kubernetes, this way there is no need to build custom docker images.
Locust requires locust files to execute load testing, and this chart provides different ways to populate locust files.

## Kubernetes ConfigMap

This chart can create configmaps for storing the locust files in Kubernetes, this way there is no need to build custom docker images.

By default it will install using an example locustfile and lib from [stable/locust/locustfiles/example](https://github.com/deliveryhero/helm-charts/tree/master/stable/locust/locustfiles/example). When you want to provide your own locustfile, you will need to create 2 configmaps using the structure from that example:

Expand All @@ -29,3 +33,25 @@ description: |
--set loadtest.locust_locustfile_configmap=my-loadtest-locustfile \
--set loadtest.locust_lib_configmap=my-loadtest-lib
```

## Git Sync

Another way to fetch locust files in the pods is to continously track a git repository containing the files.

While activating this feature, you also have to disable the default ConfigMap-based provisioning, through a custom `values.yaml` file:

```yaml
loadtest:
enabled = false
locustfiles:
gitSync:
enabled = true
```

Then configure the gitSync process to fetch the right repository and the right files:

```yaml
locustfiles:
gitSync:
repo: https://github.com/username/reponame.git
```
62 changes: 59 additions & 3 deletions stable/locust/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# locust

![Version: 0.32.2](https://img.shields.io/badge/Version-0.32.2-informational?style=flat-square) ![AppVersion: 2.32.2](https://img.shields.io/badge/AppVersion-2.32.2-informational?style=flat-square)
![Version: 0.33.0](https://img.shields.io/badge/Version-0.33.0-informational?style=flat-square) ![AppVersion: 2.32.2](https://img.shields.io/badge/AppVersion-2.32.2-informational?style=flat-square)

A chart to install Locust, a scalable load testing tool written in Python.

This chart will setup everything required to run a full distributed locust environment with any amount of workers.

This chart will also create configmaps for storing the locust files in Kubernetes, this way there is no need to build custom docker images.
Locust requires locust files to execute load testing, and this chart provides different ways to populate locust files.

## Kubernetes ConfigMap

This chart can create configmaps for storing the locust files in Kubernetes, this way there is no need to build custom docker images.

By default it will install using an example locustfile and lib from [stable/locust/locustfiles/example](https://github.com/deliveryhero/helm-charts/tree/master/stable/locust/locustfiles/example). When you want to provide your own locustfile, you will need to create 2 configmaps using the structure from that example:

Expand All @@ -24,6 +28,28 @@ helm install locust oci://ghcr.io/deliveryhero/helm-charts/locust \
--set loadtest.locust_lib_configmap=my-loadtest-lib
```

## Git Sync

Another way to fetch locust files in the pods is to continously track a git repository containing the files.

While activating this feature, you also have to disable the default ConfigMap-based provisioning, through a custom `values.yaml` file:

```yaml
loadtest:
enabled = false
locustfiles:
gitSync:
enabled = true
```

Then configure the gitSync process to fetch the right repository and the right files:

```yaml
locustfiles:
gitSync:
repo: https://github.com/username/reponame.git
```

**Homepage:** <https://github.com/locustio/locust>

## How to install this chart
Expand All @@ -37,7 +63,7 @@ helm install --generate-name oci://ghcr.io/deliveryhero/helm-charts/locust
To install a specific version of this chart:

```console
helm install --generate-name oci://ghcr.io/deliveryhero/helm-charts/locust --version 0.32.2
helm install --generate-name oci://ghcr.io/deliveryhero/helm-charts/locust --version 0.33.0
```

To install the chart with the release name `my-release`:
Expand Down Expand Up @@ -72,13 +98,25 @@ helm install my-release oci://ghcr.io/deliveryhero/helm-charts/locust -f values.
| image.repository | string | `"locustio/locust"` | |
| image.tag | string | `"2.32.2"` | |
| imagePullSecrets | list | `[]` | |
| images.defaultLocustRepository | string | `"locustio/locust"` | default image used by locust containers (master and workers) |
| images.defaultLocustTag | string | `"2.32.2"` | default tag used by locust containers (master and workers) |
| images.gitSync.pullPolicy | string | `"IfNotPresent"` | |
| images.gitSync.repository | string | `"registry.k8s.io/git-sync/git-sync"` | image used by gitSync container |
| images.gitSync.tag | string | `"v4.1.0"` | tag used by gitSync container |
| images.master.pullPolicy | string | `"IfNotPresent"` | |
| images.master.repository | string | `nil` | image used by locust master container |
| images.master.tag | string | `nil` | tag used by locust master container |
| images.worker.pullPolicy | string | `"IfNotPresent"` | |
| images.worker.repository | string | `nil` | image used by locust worker containers |
| images.worker.tag | string | `nil` | tag used by locust worker containers |
| ingress.annotations | object | `{}` | |
| ingress.className | string | `""` | |
| ingress.enabled | bool | `false` | |
| ingress.hosts[0].host | string | `"chart-example.local"` | |
| ingress.hosts[0].path | string | `"/"` | |
| ingress.hosts[0].pathType | string | `"ImplementationSpecific"` | |
| ingress.tls | list | `[]` | |
| loadtest.enabled | bool | `true` | |
| loadtest.environment | object | `{}` | environment variables used in the load test for both master and workers |
| loadtest.environment_external_secret | object | `{}` | environment variables used in the load test for both master and workers, stored in secrets created outside this chart. Each secret contains a list of values in it. Usage: `secret_name: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY]` |
| loadtest.environment_secret | object | `{}` | environment variables used in the load test for both master and workers, stored as secrets |
Expand All @@ -94,6 +132,24 @@ helm install my-release oci://ghcr.io/deliveryhero/helm-charts/locust -f values.
| loadtest.name | string | `"example"` | a name used for resources and settings in this load test |
| loadtest.pip_packages | list | `[]` | a list of extra python pip packages to install |
| loadtest.tags | string | `""` | whether to run locust with `--tags [TAG [TAG ...]]` options, so only tasks with any matching tags will be executed |
| locustfiles.gitSync.containerLifecycleHooks | object | `{}` | |
| locustfiles.gitSync.containerName | string | `"git-sync"` | |
| locustfiles.gitSync.depth | int | `1` | |
| locustfiles.gitSync.enabled | bool | `false` | Enable the Git Sync feature (mutually exclusive with loadtest.enabled) |
| locustfiles.gitSync.env | list | `[]` | |
| locustfiles.gitSync.envFrom | string | `nil` | add variables from secret into gitSync containers, such proxy-config |
| locustfiles.gitSync.extraVolumeMounts | list | `[]` | |
| locustfiles.gitSync.maxFailures | int | `0` | the number of consecutive failures allowed before aborting |
| locustfiles.gitSync.period | string | `"5s"` | |
| locustfiles.gitSync.ref | string | `"main"` | Git reference to pull |
| locustfiles.gitSync.repo | string | `nil` | Git repository to synchronize |
| locustfiles.gitSync.resources | object | `{}` | |
| locustfiles.gitSync.securityContext | object | `{}` | |
| locustfiles.gitSync.securityContexts.container | object | `{}` | |
| locustfiles.gitSync.subPath | string | `"locustfiles"` | subpath within the repo where locustfiles are located, should be "" if files are at repo root |
| locustfiles.gitSync.uid | int | `65533` | |
| locustfiles.mountPath | string | `"/mnt/locust"` | the path of the locustfiles (without trailing backslash) |
| locustfiles.requirements | string | `nil` | Path to a file containing requirements to install |
| master.affinity | object | `{}` | Overwrites affinity from global |
| master.args | list | `[]` | Any extra command args for the master |
| master.auth.enabled | bool | `false` | When enabled using image tag 2.21.0 or later you do not need username or pass word. Older image tags you are required to |
Expand Down
92 changes: 92 additions & 0 deletions stable/locust/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,95 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
mountPath: {{ .Values.loadtest.mount_external_secret.mountPath }}
readOnly: true
{{- end -}}

{{- define "locust.legacy_image" -}}
"{{ if .Values.master.image }}{{ .Values.master.image }}{{ else }}{{ .Values.image.repository }}:{{ .Values.image.tag }}{{ end }}"
{{- end }}

{{- define "locust.master_image" -}}
{{- if .Values.image }}
{{- template "locust.legacy_image" -}}
{{- else }}
{{- $repository := .Values.images.master.repository | default .Values.images.defaultLocustRepository -}}
{{- $tag := .Values.images.master.tag | default .Values.images.defaultLocustTag -}}
{{- printf "%s:%s" $repository $tag -}}
{{- end }}
{{- end }}

{{- define "locust.master_pull_policy" -}}
{{- if .Values.image }}
{{- .Values.image.pullPolicy -}}
{{- else }}
{{- .Values.images.master.pullPolicy -}}
{{- end }}
{{- end }}

{{- define "locust.worker_image" -}}
{{- if .Values.image }}
{{- template "locust.legacy_image" -}}
{{- else }}
{{- $repository := .Values.images.worker.repository | default .Values.images.defaultLocustRepository -}}
{{- $tag := .Values.images.worker.tag | default .Values.images.defaultLocustTag -}}
{{- printf "%s:%s" $repository $tag -}}
{{- end }}
{{- end }}

{{- define "locust.worker_pull_policy" -}}
{{- if .Values.image }}
{{- .Values.image.pullPolicy -}}
{{- else }}
{{- .Values.images.worker.pullPolicy -}}
{{- end }}
{{- end }}


{{- define "git_sync_image" -}}
{{- printf "%s:%s" .Values.images.gitSync.repository .Values.images.gitSync.tag }}
{{- end }}

{{/* Git sync container */}}
{{- define "git_sync_container" }}
- name: {{ .Values.locustfiles.gitSync.containerName }}{{ if .is_init }}-init{{ end }}
image: {{ template "git_sync_image" . }}
imagePullPolicy: {{ .Values.images.gitSync.pullPolicy }}
env:
- name: GITSYNC_REF
value: {{ .Values.locustfiles.gitSync.ref | quote }}
- name: GITSYNC_REPO
value: {{ .Values.locustfiles.gitSync.repo | quote }}
- name: GITSYNC_DEPTH
value: {{ .Values.locustfiles.gitSync.depth | quote }}
- name: GITSYNC_ROOT
value: "/git"
- name: GITSYNC_LINK
value: "repo"
- name: GITSYNC_ADD_USER
value: "true"
- name: GITSYNC_PERIOD
value: {{ .Values.locustfiles.gitSync.period | quote }}
- name: GITSYNC_MAX_FAILURES
value: {{ .Values.locustfiles.gitSync.maxFailures | quote }}
{{- if .is_init }}
- name: GITSYNC_ONE_TIME
value: "true"
{{- end }}
{{- with .Values.locustfiles.gitSync.env }}
{{- toYaml . | nindent 4 }}
{{- end }}
resources: {{ toYaml .Values.locustfiles.gitSync.resources | nindent 4 }}
volumeMounts:
- name: locustfiles
mountPath: /git
{{- if .Values.locustfiles.gitSync.extraVolumeMounts }}
{{- tpl (toYaml .Values.locustfiles.gitSync.extraVolumeMounts) . | nindent 2 }}
{{- end }}
{{- if and .Values.locustfiles.gitSync.containerLifecycleHooks (not .is_init) }}
lifecycle: {{- tpl (toYaml .Values.locustfiles.gitSync.containerLifecycleHooks) . | nindent 4 }}
{{- end }}
{{- end }}

{{- define "locust.locustfiles_mount" }}
- name: locustfiles
mountPath: {{ .Values.locustfiles.mountPath }}
readOnly: {{ .Values.locustfiles.gitSync.enabled | ternary "True" "False" }}
{{- end }}
5 changes: 4 additions & 1 deletion stable/locust/templates/configmap-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ data:

set -eu

{{- if .Values.loadtest.pip_packages }}
{{- if and .Values.loadtest.enabled .Values.loadtest.pip_packages }}
pip install {{ range .Values.loadtest.pip_packages }}{{ . }} {{ end }}
{{- end }}
{{- if .Values.locustfiles.requirements }}
pip install -r {{ .Values.locustfiles.requirements }}
{{- end }}

exec {{ .Values.loadtest.locustCmd }} $@
2 changes: 2 additions & 0 deletions stable/locust/templates/configmap-locust-lib.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.loadtest.enabled }}
{{- if eq .Values.loadtest.locust_lib_configmap "example-lib" }}
apiVersion: v1
kind: ConfigMap
Expand All @@ -8,3 +9,4 @@ metadata:
data:
{{ ($.Files.Glob (printf "locustfiles/%s/lib/*" .Values.loadtest.name)).AsConfig | indent 2 }}
{{- end }}
{{- end }}
4 changes: 3 additions & 1 deletion stable/locust/templates/configmap-locust-locustfile.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.loadtest.enabled }}
{{- if eq .Values.loadtest.locust_locustfile_configmap "example-locustfile" }}
apiVersion: v1
kind: ConfigMap
Expand All @@ -6,5 +7,6 @@ metadata:
labels:
{{ include "locust.labels" . | indent 4 }}
data:
{{ (.Files.Glob (printf "locustfiles/%s/%s" .Values.loadtest.name .Values.loadtest.locust_locustfile)).AsConfig | indent 2 }}
{{ ($.Files.Glob (printf "locustfiles/%s/%s" .Values.loadtest.name .Values.loadtest.locust_locustfile)).AsConfig | indent 2 }}
{{- end }}
{{- end }}
38 changes: 30 additions & 8 deletions stable/locust/templates/master-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ spec:
{{- if .Values.hostAliases }}
hostAliases: {{- .Values.hostAliases | toYaml | nindent 8 }}
{{- end }}
initContainers:
{{- if .Values.locustfiles.gitSync.enabled }}
{{- include "git_sync_container" (dict "Values" .Values "is_init" "true" "Template" .Template) | nindent 6 }}
{{- end }}
containers:
{{- if .Values.locustfiles.gitSync.enabled }}
{{- include "git_sync_container" . | nindent 6 }}
{{- end }}
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ if .Values.master.image }}{{ .Values.master.image }}{{ else }}{{ .Values.image.repository }}:{{ .Values.image.tag }}{{ end }}"
image: {{ template "locust.master_image" . }}
{{- with .Values.master.command }}
command:
{{- toYaml . | nindent 8 }}
Expand Down Expand Up @@ -76,17 +83,22 @@ spec:
{{- if .Values.loadtest.excludeTags }}
- --exclude-tags {{ .Values.loadtest.excludeTags }}
{{- end }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
imagePullPolicy: {{ template "locust.master_pull_policy" . }}
resources:
{{ toYaml .Values.master.resources | indent 10 }}
volumeMounts:
{{- if .Values.loadtest.locust_locustfile_configmap}}
{{- if .Values.loadtest.enabled }}
{{- if .Values.loadtest.locust_locustfile_configmap}}
- name: locustfile
mountPath: "{{ .Values.loadtest.locust_locustfile_path }}"
{{- end }}
{{- if .Values.loadtest.locust_lib_configmap }}
{{- end }}
{{- if .Values.loadtest.locust_lib_configmap }}
- name: lib
mountPath: "{{ .Values.loadtest.locust_locustfile_path }}/lib"
{{- end }}
{{- end }}
{{- if .Values.locustfiles.gitSync.enabled }}
{{- include "locust.locustfiles_mount" . | nindent 10 }}
{{- end }}
- name: config
mountPath: /config
Expand All @@ -107,7 +119,11 @@ spec:
- name: LOCUST_LOGLEVEL
value: "{{ .Values.master.logLevel }}"
- name: LOCUST_LOCUSTFILE
{{- if .Values.loadtest.enabled }}
value: "{{ .Values.loadtest.locust_locustfile_path }}/{{ .Values.loadtest.locust_locustfile }}"
{{- else if .Values.locustfiles.gitSync.enabled }}
value: "{{ .Values.locustfiles.mountPath }}/repo/{{ .Values.locustfiles.gitSync.subPath }}/"
{{- end }}
{{- end }}
{{- range $key, $value := .Values.loadtest.environment }}
- name: {{ $key }}
Expand Down Expand Up @@ -161,15 +177,21 @@ spec:
{{- end }}
restartPolicy: {{ .Values.master.restartPolicy }}
volumes:
{{- if .Values.loadtest.locust_lib_configmap }}
{{- if .Values.loadtest.enabled }}
{{- if .Values.loadtest.locust_lib_configmap }}
- name: lib
configMap:
name: {{ .Values.loadtest.locust_lib_configmap }}
{{- end }}
{{- if .Values.loadtest.locust_locustfile_configmap }}
{{- end }}
{{- if .Values.loadtest.locust_locustfile_configmap }}
- name: locustfile
configMap:
name: {{ .Values.loadtest.locust_locustfile_configmap }}
{{- end }}
{{- end }}
{{- if .Values.locustfiles.gitSync.enabled }}
- name: locustfiles
emptyDir: {}
{{- end }}
- name: config
configMap:
Expand Down
Loading