Skip to content

Commit

Permalink
Merge pull request #173 from maykinmedia/fix/172-hpa-worker-nginx
Browse files Browse the repository at this point in the history
[#172] Update HPA
  • Loading branch information
SilviaAmAm authored Feb 11, 2025
2 parents c247839 + c122819 commit f04552b
Show file tree
Hide file tree
Showing 19 changed files with 269 additions and 10 deletions.
6 changes: 6 additions & 0 deletions charts/maykin-utils-lib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion charts/maykin-utils-lib/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion charts/maykin-utils-lib/templates/_celery-configmap.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- define "maykinhelmlib.celeryEnvConfigmap" -}}
{{- define "maykinUtilsLib.celeryEnvConfigmap" -}}
apiVersion: v1
kind: ConfigMap
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- define "maykinhelmlib.celeryLivenessConfigmap" -}}
{{- define "maykinUtilsLib.celeryLivenessConfigmap" -}}
apiVersion: v1
kind: ConfigMap
metadata:
Expand Down
52 changes: 52 additions & 0 deletions charts/maykin-utils-lib/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
38 changes: 38 additions & 0 deletions charts/maykin-utils-lib/templates/_nginx-hpa.tpl
Original file line number Diff line number Diff line change
@@ -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 -}}
38 changes: 38 additions & 0 deletions charts/maykin-utils-lib/templates/_webapp-hpa.tpl
Original file line number Diff line number Diff line change
@@ -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 -}}
38 changes: 38 additions & 0 deletions charts/maykin-utils-lib/templates/_worker-hpa.tpl
Original file line number Diff line number Diff line change
@@ -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 -}}
4 changes: 4 additions & 0 deletions charts/objecten/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
2 changes: 1 addition & 1 deletion charts/objecten/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion charts/objecten/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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` | |
Expand Down Expand Up @@ -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` | |
Expand Down
2 changes: 1 addition & 1 deletion charts/objecten/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
41 changes: 41 additions & 0 deletions charts/objecten/templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

2 changes: 2 additions & 0 deletions charts/objecten/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ autoscaling:
maxReplicas: 100
targetCPUUtilizationPercentage: 80
targetMemoryUtilizationPercentage: 80
behaviour: {}

pdb:
create: false
Expand Down Expand Up @@ -385,6 +386,7 @@ worker:
maxReplicas: 100
targetCPUUtilizationPercentage: 80
targetMemoryUtilizationPercentage: 80
behaviour: {}

flower:
enabled: true
Expand Down
7 changes: 6 additions & 1 deletion charts/openzaak/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion charts/openzaak/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion charts/openzaak/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion charts/openzaak/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
33 changes: 33 additions & 0 deletions charts/openzaak/templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

0 comments on commit f04552b

Please sign in to comment.