From 9926580427740c00a0fb031dcb076a97f53c03bc Mon Sep 17 00:00:00 2001 From: SilviaAmAm Date: Tue, 28 Jan 2025 16:55:05 +0100 Subject: [PATCH 1/4] :sparkles: [#172] Add HPA for objecten --- charts/objecten/CHANGELOG.md | 4 +++ charts/objecten/Chart.yaml | 2 +- charts/objecten/README.md | 4 ++- charts/objecten/templates/deployment.yaml | 2 +- charts/objecten/templates/hpa.yaml | 41 +++++++++++++++++++++++ charts/objecten/values.yaml | 2 ++ 6 files changed, 52 insertions(+), 3 deletions(-) diff --git a/charts/objecten/CHANGELOG.md b/charts/objecten/CHANGELOG.md index f5993a9..c34c3d6 100644 --- a/charts/objecten/CHANGELOG.md +++ b/charts/objecten/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.7.1 (2025-02-11) + +- [#172] Add Horizontal Pod Autoscaler for the worker. Fix the deployment to look for the `.Values.worker.autoscaling.enabled` value instead of the `.Values.autoscaling.enabled` when setting the replicas of the worker. + ## 2.7.0 (2025-01-31) diff --git a/charts/objecten/Chart.yaml b/charts/objecten/Chart.yaml index ecd0a81..1efc506 100644 --- a/charts/objecten/Chart.yaml +++ b/charts/objecten/Chart.yaml @@ -3,7 +3,7 @@ name: objecten description: API om objecten te beheren die behoren bij een bepaald objecttype type: application -version: 2.7.0 +version: 2.7.1 appVersion: 3.0.0 dependencies: diff --git a/charts/objecten/README.md b/charts/objecten/README.md index f2a7f0c..c4f6609 100644 --- a/charts/objecten/README.md +++ b/charts/objecten/README.md @@ -1,6 +1,6 @@ # objecten -![Version: 2.7.0](https://img.shields.io/badge/Version-2.7.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 3.0.0](https://img.shields.io/badge/AppVersion-3.0.0-informational?style=flat-square) +![Version: 2.7.1](https://img.shields.io/badge/Version-2.7.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 3.0.0](https://img.shields.io/badge/AppVersion-3.0.0-informational?style=flat-square) API om objecten te beheren die behoren bij een bepaald objecttype @@ -15,6 +15,7 @@ API om objecten te beheren die behoren bij een bepaald objecttype | Key | Type | Default | Description | |-----|------|---------|-------------| | affinity | object | `{}` | | +| autoscaling.behaviour | object | `{}` | | | autoscaling.enabled | bool | `false` | | | autoscaling.maxReplicas | int | `100` | | | autoscaling.minReplicas | int | `1` | | @@ -151,6 +152,7 @@ API om objecten te beheren die behoren bij een bepaald objecttype | settings.uwsgi.threads | string | `""` | | | tags.redis | bool | `true` | | | tolerations | list | `[]` | | +| worker.autoscaling.behaviour | object | `{}` | | | worker.autoscaling.enabled | bool | `false` | | | worker.autoscaling.maxReplicas | int | `100` | | | worker.autoscaling.minReplicas | int | `1` | | diff --git a/charts/objecten/templates/deployment.yaml b/charts/objecten/templates/deployment.yaml index f7460b0..a78219f 100644 --- a/charts/objecten/templates/deployment.yaml +++ b/charts/objecten/templates/deployment.yaml @@ -141,7 +141,7 @@ metadata: labels: {{- include "objecten.workerLabels" . | nindent 4 }} spec: - {{- if not .Values.autoscaling.enabled }} + {{- if not .Values.worker.autoscaling.enabled }} replicas: {{ .Values.worker.replicaCount }} {{- end }} selector: diff --git a/charts/objecten/templates/hpa.yaml b/charts/objecten/templates/hpa.yaml index e2e090d..ecbf68c 100644 --- a/charts/objecten/templates/hpa.yaml +++ b/charts/objecten/templates/hpa.yaml @@ -29,5 +29,46 @@ spec: type: Utilization averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} {{- end }} + {{- with .Values.autoscaling.behavior }} + behavior: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} +--- +{{- if .Values.worker.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "objecten.workerFullname" . }} + labels: + {{- include "objecten.workerSelectorLabels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "objecten.workerFullname" . }} + minReplicas: {{ .Values.worker.autoscaling.minReplicas }} + maxReplicas: {{ .Values.worker.autoscaling.maxReplicas }} + metrics: + {{- if .Values.worker.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.worker.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.worker.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.worker.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} + {{- with .Values.worker.autoscaling.behavior }} + behavior: + {{- toYaml . | nindent 4 }} + {{- end }} {{- end }} diff --git a/charts/objecten/values.yaml b/charts/objecten/values.yaml index 425ba49..85bfc0c 100644 --- a/charts/objecten/values.yaml +++ b/charts/objecten/values.yaml @@ -228,6 +228,7 @@ autoscaling: maxReplicas: 100 targetCPUUtilizationPercentage: 80 targetMemoryUtilizationPercentage: 80 + behaviour: {} pdb: create: false @@ -385,6 +386,7 @@ worker: maxReplicas: 100 targetCPUUtilizationPercentage: 80 targetMemoryUtilizationPercentage: 80 + behaviour: {} flower: enabled: true From effeb9ec2aae0a4f2041a75927411b49d529be35 Mon Sep 17 00:00:00 2001 From: SilviaAmAm Date: Tue, 28 Jan 2025 17:05:26 +0100 Subject: [PATCH 2/4] :sparkles: [#172] Add HPA for nginx in openzaak. --- charts/openzaak/CHANGELOG.md | 7 ++++- charts/openzaak/Chart.yaml | 2 +- charts/openzaak/README.md | 2 +- charts/openzaak/templates/deployment.yaml | 2 +- charts/openzaak/templates/hpa.yaml | 33 +++++++++++++++++++++++ 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/charts/openzaak/CHANGELOG.md b/charts/openzaak/CHANGELOG.md index e65d989..c7d2f71 100644 --- a/charts/openzaak/CHANGELOG.md +++ b/charts/openzaak/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog -## 1.7.0-beta.0 (2025-10-01) +## 1.8.0-beta.0 (2025-01-28) + +- [#172] Add Horizontal Pod Autoscaler for nginx. Fix the deployment to look for the `.Values.worker.autoscaling.enabled` value instead of the `.Values.autoscaling.enabled` when setting the replicas of the worker. + + +## 1.7.0-beta.0 (2025-01-10) - [#148] Replace the worker liveness probe with the `celery inspect active` command. This should detect when a worker is down and should not interrupt long running tasks. - [#119] Update the syntax of the worker liveness probe. The worker probes now can be enabled/disabled with: diff --git a/charts/openzaak/Chart.yaml b/charts/openzaak/Chart.yaml index e54f5e6..68c246d 100644 --- a/charts/openzaak/Chart.yaml +++ b/charts/openzaak/Chart.yaml @@ -3,7 +3,7 @@ name: openzaak description: Productiewaardige API's voor Zaakgericht Werken type: application -version: 1.7.0-beta.0 +version: 1.8.0-beta.0 appVersion: latest dependencies: diff --git a/charts/openzaak/README.md b/charts/openzaak/README.md index bc1e25f..e900c31 100644 --- a/charts/openzaak/README.md +++ b/charts/openzaak/README.md @@ -1,6 +1,6 @@ # openzaak -![Version: 1.7.0-beta.0](https://img.shields.io/badge/Version-1.7.0--beta.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational?style=flat-square) +![Version: 1.8.0-beta.0](https://img.shields.io/badge/Version-1.8.0--beta.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational?style=flat-square) Productiewaardige API's voor Zaakgericht Werken diff --git a/charts/openzaak/templates/deployment.yaml b/charts/openzaak/templates/deployment.yaml index 5df9e3d..af9260d 100644 --- a/charts/openzaak/templates/deployment.yaml +++ b/charts/openzaak/templates/deployment.yaml @@ -231,7 +231,7 @@ metadata: labels: {{- include "openzaak.workerLabels" . | nindent 4 }} spec: - {{- if not .Values.autoscaling.enabled }} + {{- if not .Values.worker.autoscaling.enabled }} replicas: {{ .Values.worker.replicaCount }} {{- end }} selector: diff --git a/charts/openzaak/templates/hpa.yaml b/charts/openzaak/templates/hpa.yaml index 8384c2e..312c6bc 100644 --- a/charts/openzaak/templates/hpa.yaml +++ b/charts/openzaak/templates/hpa.yaml @@ -63,3 +63,36 @@ spec: averageUtilization: {{ .Values.worker.autoscaling.targetMemoryUtilizationPercentage }} {{- end }} {{- end }} +--- +{{- if .Values.nginx.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "openzaak.nginxFullname" . }} + labels: + {{- include "openzaak.nginxSelectorLabels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "openzaak.nginxFullname" . }} + minReplicas: {{ .Values.nginx.autoscaling.minReplicas }} + maxReplicas: {{ .Values.nginx.autoscaling.maxReplicas }} + metrics: + {{- if .Values.nginx.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.nginx.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.nginx.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.nginx.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} \ No newline at end of file From b3ecad25f3bfc96f6a212a1af9a4cdfbaed38d82 Mon Sep 17 00:00:00 2001 From: SilviaAmAm Date: Tue, 28 Jan 2025 17:26:04 +0100 Subject: [PATCH 3/4] :sparkles: [#172] Add templates for the HPAs for the webapp, the worker and nginx. --- charts/maykin-utils-lib/CHANGELOG.md | 6 +++ charts/maykin-utils-lib/Chart.yaml | 2 +- .../maykin-utils-lib/templates/_helpers.tpl | 52 +++++++++++++++++++ .../maykin-utils-lib/templates/_nginx-hpa.tpl | 38 ++++++++++++++ .../templates/_webapp-hpa.tpl | 38 ++++++++++++++ .../templates/_worker-hpa.tpl | 38 ++++++++++++++ 6 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 charts/maykin-utils-lib/CHANGELOG.md create mode 100644 charts/maykin-utils-lib/templates/_nginx-hpa.tpl create mode 100644 charts/maykin-utils-lib/templates/_webapp-hpa.tpl create mode 100644 charts/maykin-utils-lib/templates/_worker-hpa.tpl diff --git a/charts/maykin-utils-lib/CHANGELOG.md b/charts/maykin-utils-lib/CHANGELOG.md new file mode 100644 index 0000000..dbb53b3 --- /dev/null +++ b/charts/maykin-utils-lib/CHANGELOG.md @@ -0,0 +1,6 @@ +# Changelog + +## 0.2.0 (2025-01-28) + +- [#172] Add templates for the HPAs for the webapp, the worker and nginx. +- Replace forgotten old library name `maykinhelmlib` with `maykinUtilsLib` in the celery config maps. \ No newline at end of file diff --git a/charts/maykin-utils-lib/Chart.yaml b/charts/maykin-utils-lib/Chart.yaml index 97eaf15..bd273a8 100644 --- a/charts/maykin-utils-lib/Chart.yaml +++ b/charts/maykin-utils-lib/Chart.yaml @@ -3,5 +3,5 @@ name: maykin-utils-lib description: A Library Helm chart containing code shared between Maykin helm charts type: library -version: 0.1.0 +version: 0.2.0 diff --git a/charts/maykin-utils-lib/templates/_helpers.tpl b/charts/maykin-utils-lib/templates/_helpers.tpl index 34232fd..1a52372 100644 --- a/charts/maykin-utils-lib/templates/_helpers.tpl +++ b/charts/maykin-utils-lib/templates/_helpers.tpl @@ -22,4 +22,56 @@ If release name contains chart name it will be used as a full name. {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} {{- end }} {{- end }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "project.selectorLabels" -}} +app.kubernetes.io/name: {{ include "project.name" . }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "project.commonLabels" -}} +helm.sh/chart: {{ include "project.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + + +{{/* +Project labels +*/}} +{{- define "project.labels" -}} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +{{ include "project.commonLabels" . }} +{{ include "project.selectorLabels" . }} +{{- end }} + + +{{/* +Create a default fully qualified name for the worker. +We truncate at 56 chars in order to provide space for the "-worker" suffix +*/}} +{{- define "project.workerFullname" -}} +{{ include "project.fullname" . | trunc 56 | trimSuffix "-" }}-worker +{{- end }} + + +{{/* +Create a default fully qualified name for NGINX. +We truncate at 57 chars in order to provide space for the "-nginx" suffix +*/}} +{{- define "project.nginxFullname" -}} +{{ include "project.fullname" . | trunc 57 | trimSuffix "-" }}-nginx +{{- end }} + +{{/* +NGINX selector labels +*/}} +{{- define "project.nginxSelectorLabels" -}} +app.kubernetes.io/name: {{ include "project.nginxFullname" . }} {{- end }} \ No newline at end of file diff --git a/charts/maykin-utils-lib/templates/_nginx-hpa.tpl b/charts/maykin-utils-lib/templates/_nginx-hpa.tpl new file mode 100644 index 0000000..4cae15e --- /dev/null +++ b/charts/maykin-utils-lib/templates/_nginx-hpa.tpl @@ -0,0 +1,38 @@ +{{- define "maykinUtilsLib.nginxHpa" -}} +{{- if .Values.nginx.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "project.nginxFullname" . }} + labels: + {{- include "project.nginxSelectorLabels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "project.nginxFullname" . }} + minReplicas: {{ .Values.nginx.autoscaling.minReplicas }} + maxReplicas: {{ .Values.nginx.autoscaling.maxReplicas }} + metrics: + {{- if .Values.nginx.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.nginx.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.nginx.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.nginx.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} + {{- with .Values.nginx.autoscaling.behavior }} + behavior: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} +{{- end -}} \ No newline at end of file diff --git a/charts/maykin-utils-lib/templates/_webapp-hpa.tpl b/charts/maykin-utils-lib/templates/_webapp-hpa.tpl new file mode 100644 index 0000000..92fc9af --- /dev/null +++ b/charts/maykin-utils-lib/templates/_webapp-hpa.tpl @@ -0,0 +1,38 @@ +{{- define "maykinUtilsLib.webAppHpa" -}} +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "project.fullname" . }} + labels: + {{- include "project.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "project.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} + {{- with .Values.autoscaling.behavior }} + behavior: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} +{{- end -}} \ No newline at end of file diff --git a/charts/maykin-utils-lib/templates/_worker-hpa.tpl b/charts/maykin-utils-lib/templates/_worker-hpa.tpl new file mode 100644 index 0000000..581537c --- /dev/null +++ b/charts/maykin-utils-lib/templates/_worker-hpa.tpl @@ -0,0 +1,38 @@ +{{- define "maykinUtilsLib.workerHpa" -}} +{{- if .Values.worker.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "project.workerFullname" . }} + labels: + {{- include "project.workerSelectorLabels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "project.workerFullname" . }} + minReplicas: {{ .Values.worker.autoscaling.minReplicas }} + maxReplicas: {{ .Values.worker.autoscaling.maxReplicas }} + metrics: + {{- if .Values.worker.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.worker.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.worker.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.worker.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} + {{- with .Values.worker.autoscaling.behavior }} + behavior: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} +{{- end -}} \ No newline at end of file From c122819a286e31f558014a7fd94646bd0c7e3ebb Mon Sep 17 00:00:00 2001 From: SilviaAmAm Date: Tue, 28 Jan 2025 17:26:40 +0100 Subject: [PATCH 4/4] :truck: Replace old library name with new name --- charts/maykin-utils-lib/templates/_celery-configmap.tpl | 2 +- .../maykin-utils-lib/templates/_celery-liveness-configmap.tpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/maykin-utils-lib/templates/_celery-configmap.tpl b/charts/maykin-utils-lib/templates/_celery-configmap.tpl index 7762214..e42f6bf 100644 --- a/charts/maykin-utils-lib/templates/_celery-configmap.tpl +++ b/charts/maykin-utils-lib/templates/_celery-configmap.tpl @@ -1,4 +1,4 @@ -{{- define "maykinhelmlib.celeryEnvConfigmap" -}} +{{- define "maykinUtilsLib.celeryEnvConfigmap" -}} apiVersion: v1 kind: ConfigMap metadata: diff --git a/charts/maykin-utils-lib/templates/_celery-liveness-configmap.tpl b/charts/maykin-utils-lib/templates/_celery-liveness-configmap.tpl index 8d96294..d3c9497 100644 --- a/charts/maykin-utils-lib/templates/_celery-liveness-configmap.tpl +++ b/charts/maykin-utils-lib/templates/_celery-liveness-configmap.tpl @@ -1,4 +1,4 @@ -{{- define "maykinhelmlib.celeryLivenessConfigmap" -}} +{{- define "maykinUtilsLib.celeryLivenessConfigmap" -}} apiVersion: v1 kind: ConfigMap metadata: