diff --git a/stable/locust/Chart.yaml b/stable/locust/Chart.yaml index 15f8e126..68d07b72 100644 --- a/stable/locust/Chart.yaml +++ b/stable/locust/Chart.yaml @@ -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: @@ -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 + ``` diff --git a/stable/locust/README.md b/stable/locust/README.md index d4d3c3f5..6db4e18c 100644 --- a/stable/locust/README.md +++ b/stable/locust/README.md @@ -6,7 +6,11 @@ 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: @@ -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:** ## How to install this chart @@ -72,17 +98,17 @@ 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"` | | -| images.defaultLocustTag | string | `"2.32.2"` | | +| 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"` | | -| images.gitSync.tag | string | `"v4.1.0"` | | +| 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` | | -| images.master.tag | string | `nil` | | +| 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` | | -| images.worker.tag | string | `nil` | | +| 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` | | @@ -109,21 +135,21 @@ helm install my-release oci://ghcr.io/deliveryhero/helm-charts/locust -f values. | locustfiles.gitSync.containerLifecycleHooks | object | `{}` | | | locustfiles.gitSync.containerName | string | `"git-sync"` | | | locustfiles.gitSync.depth | int | `1` | | -| locustfiles.gitSync.enabled | bool | `false` | | +| locustfiles.gitSync.enabled | bool | `false` | Enable the Git Sync feature (mutually exclusive with loadtest.enabled) | | locustfiles.gitSync.env | list | `[]` | | -| locustfiles.gitSync.envFrom | string | `nil` | | +| locustfiles.gitSync.envFrom | string | `nil` | add variables from secret into gitSync containers, such proxy-config | | locustfiles.gitSync.extraVolumeMounts | list | `[]` | | -| locustfiles.gitSync.maxFailures | int | `0` | | +| locustfiles.gitSync.maxFailures | int | `0` | the number of consecutive failures allowed before aborting | | locustfiles.gitSync.period | string | `"5s"` | | -| locustfiles.gitSync.ref | string | `"main"` | | -| locustfiles.gitSync.repo | string | `nil` | | +| 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"` | | +| 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"` | | -| locustfiles.requirements | string | `nil` | | +| 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 | diff --git a/stable/locust/templates/_helpers.tpl b/stable/locust/templates/_helpers.tpl index a1474c2a..ebe8b62b 100644 --- a/stable/locust/templates/_helpers.tpl +++ b/stable/locust/templates/_helpers.tpl @@ -122,21 +122,38 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} {{- template "locust.legacy_image" -}} {{- else }} {{- $repository := .Values.images.master.repository | default .Values.images.defaultLocustRepository -}} - {{- $tag := .Values.images.master.tag | default .Values.defaultLocustTag -}} + {{- $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.defaultLocustTag -}} + {{- $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 }} @@ -182,7 +199,7 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} {{- end }} {{- end }} -{{- define "locust.locustfiles_mount" -}} +{{- define "locust.locustfiles_mount" }} - name: locustfiles mountPath: {{ .Values.locustfiles.mountPath }} readOnly: {{ .Values.locustfiles.gitSync.enabled | ternary "True" "False" }} diff --git a/stable/locust/templates/master-deployment.yaml b/stable/locust/templates/master-deployment.yaml index 68df370c..e4b4d577 100644 --- a/stable/locust/templates/master-deployment.yaml +++ b/stable/locust/templates/master-deployment.yaml @@ -45,16 +45,16 @@ spec: {{- end }} initContainers: {{- if .Values.locustfiles.gitSync.enabled }} - {{- include "git_sync_container" (dict "Values" .Values "is_init" "true" "Template" .Template) | nindent 8 }} + {{- 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 8 }} + {{- include "git_sync_container" . | nindent 6 }} {{- end }} - name: {{ .Chart.Name }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} - image: {{ template "locust.master_image" }} + image: {{ template "locust.master_image" . }} {{- with .Values.master.command }} command: {{- toYaml . | nindent 8 }} @@ -83,20 +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 12 }} + {{- include "locust.locustfiles_mount" . | nindent 10 }} {{- end }} - name: config mountPath: /config @@ -117,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 }} @@ -171,19 +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.dags.gitSync.enabled }} + {{- if .Values.locustfiles.gitSync.enabled }} - name: locustfiles - emptyDir: + emptyDir: {} {{- end }} - name: config configMap: diff --git a/stable/locust/templates/worker-deployment.yaml b/stable/locust/templates/worker-deployment.yaml index 41d6ebec..d0f1a5dc 100644 --- a/stable/locust/templates/worker-deployment.yaml +++ b/stable/locust/templates/worker-deployment.yaml @@ -51,12 +51,12 @@ spec: {{- end }} containers: {{- if .Values.locustfiles.gitSync.enabled }} - {{- include "git_sync_container" . | nindent 8 }} + {{- include "git_sync_container" . | nindent 6 }} {{- end }} - name: {{ .Chart.Name }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} - image: {{ template "locust.worker_image" }} + image: {{ template "locust.worker_image" . }} {{- with .Values.worker.command }} command: {{- toYaml . | nindent 8 }} @@ -66,20 +66,22 @@ spec: {{- if .Values.worker.args }} {{- toYaml .Values.worker.args | nindent 10 }} {{- end }} - imagePullPolicy: {{ .Values.image.pullPolicy }} + imagePullPolicy: {{ template "locust.worker_pull_policy" . }} resources: {{ toYaml .Values.worker.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 12 }} + {{- include "locust.locustfiles_mount" . | nindent 10 }} {{- end }} - name: config mountPath: /config @@ -104,7 +106,11 @@ spec: - name: LOCUST_LOGLEVEL value: "{{ .Values.worker.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.worker.environment }} - name: {{ $key }} @@ -133,19 +139,21 @@ spec: {{- end }} restartPolicy: {{ .Values.worker.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.dags.gitSync.enabled }} + {{- if .Values.locustfiles.gitSync.enabled }} - name: locustfiles - emptyDir: + emptyDir: {} {{- end }} - name: config configMap: diff --git a/stable/locust/values.yaml b/stable/locust/values.yaml index 5e61457b..0b1d7145 100644 --- a/stable/locust/values.yaml +++ b/stable/locust/values.yaml @@ -38,22 +38,27 @@ loadtest: locustCmd: "/opt/venv/bin/locust" locustfiles: + # locustfiles.mountPath -- the path of the locustfiles (without trailing backslash) mountPath: "/mnt/locust" + # locustfiles.requirements -- Path to a file containing requirements to install requirements: ~ gitSync: + # locustfiles.gitSync.enabled -- Enable the Git Sync feature (mutually exclusive with loadtest.enabled) enabled: false + # locustfiles.gitSync.repo -- Git repository to synchronize repo: ~ + # locustfiles.gitSync.ref -- Git reference to pull ref: main depth: 1 - # the number of consecutive failures allowed before aborting + # locustfiles.gitSync.maxFailures -- the number of consecutive failures allowed before aborting maxFailures: 0 - # subpath within the repo where locustfiles are located + # locustfiles.gitSync.subPath -- subpath within the repo where locustfiles are located, # should be "" if files are at repo root subPath: "locustfiles" - # interval between git sync attempts in seconds + # locustfiles.gitSync.period - interval between git sync attempts in seconds # Go-style duration string (e.g. "100ms" or "0.1s" = 100ms). period: 5s - # add variables from secret into gitSync containers, such proxy-config + # locustfiles.gitSync.envFrom -- add variables from secret into gitSync containers, such proxy-config envFrom: ~ # envFrom: | # - secretRef: @@ -104,21 +109,29 @@ image: pullPolicy: IfNotPresent images: + # images.defaultLocustRepository -- default image used by locust containers (master and workers) defaultLocustRepository: locustio/locust + # images.defaultLocustTag -- default tag used by locust containers (master and workers) defaultLocustTag: 2.32.2 master: + # images.master.repository -- image used by locust master container repository: ~ + # images.master.tag -- tag used by locust master container tag: ~ pullPolicy: IfNotPresent worker: + # images.worker.repository -- image used by locust worker containers repository: ~ + # images.worker.tag -- tag used by locust worker containers tag: ~ pullPolicy: IfNotPresent gitSync: + # images.gitSync.repository -- image used by gitSync container repository: registry.k8s.io/git-sync/git-sync + # images.gitSync.tag -- tag used by gitSync container tag: v4.1.0 pullPolicy: IfNotPresent