Skip to content

Commit b3ecad2

Browse files
committed
✨ [#172] Add templates for the HPAs for the webapp, the worker and nginx.
1 parent effeb9e commit b3ecad2

File tree

6 files changed

+173
-1
lines changed

6 files changed

+173
-1
lines changed

charts/maykin-utils-lib/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changelog
2+
3+
## 0.2.0 (2025-01-28)
4+
5+
- [#172] Add templates for the HPAs for the webapp, the worker and nginx.
6+
- Replace forgotten old library name `maykinhelmlib` with `maykinUtilsLib` in the celery config maps.

charts/maykin-utils-lib/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ name: maykin-utils-lib
33
description: A Library Helm chart containing code shared between Maykin helm charts
44

55
type: library
6-
version: 0.1.0
6+
version: 0.2.0
77

charts/maykin-utils-lib/templates/_helpers.tpl

+52
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,56 @@ If release name contains chart name it will be used as a full name.
2222
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
2323
{{- end }}
2424
{{- end }}
25+
{{- end }}
26+
27+
{{/*
28+
Selector labels
29+
*/}}
30+
{{- define "project.selectorLabels" -}}
31+
app.kubernetes.io/name: {{ include "project.name" . }}
32+
{{- end }}
33+
34+
{{/*
35+
Common labels
36+
*/}}
37+
{{- define "project.commonLabels" -}}
38+
helm.sh/chart: {{ include "project.chart" . }}
39+
app.kubernetes.io/instance: {{ .Release.Name }}
40+
{{- end }}
41+
42+
43+
{{/*
44+
Project labels
45+
*/}}
46+
{{- define "project.labels" -}}
47+
{{- if .Chart.AppVersion }}
48+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
49+
{{- end }}
50+
{{ include "project.commonLabels" . }}
51+
{{ include "project.selectorLabels" . }}
52+
{{- end }}
53+
54+
55+
{{/*
56+
Create a default fully qualified name for the worker.
57+
We truncate at 56 chars in order to provide space for the "-worker" suffix
58+
*/}}
59+
{{- define "project.workerFullname" -}}
60+
{{ include "project.fullname" . | trunc 56 | trimSuffix "-" }}-worker
61+
{{- end }}
62+
63+
64+
{{/*
65+
Create a default fully qualified name for NGINX.
66+
We truncate at 57 chars in order to provide space for the "-nginx" suffix
67+
*/}}
68+
{{- define "project.nginxFullname" -}}
69+
{{ include "project.fullname" . | trunc 57 | trimSuffix "-" }}-nginx
70+
{{- end }}
71+
72+
{{/*
73+
NGINX selector labels
74+
*/}}
75+
{{- define "project.nginxSelectorLabels" -}}
76+
app.kubernetes.io/name: {{ include "project.nginxFullname" . }}
2577
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{{- define "maykinUtilsLib.nginxHpa" -}}
2+
{{- if .Values.nginx.autoscaling.enabled }}
3+
apiVersion: autoscaling/v2
4+
kind: HorizontalPodAutoscaler
5+
metadata:
6+
name: {{ include "project.nginxFullname" . }}
7+
labels:
8+
{{- include "project.nginxSelectorLabels" . | nindent 4 }}
9+
spec:
10+
scaleTargetRef:
11+
apiVersion: apps/v1
12+
kind: Deployment
13+
name: {{ include "project.nginxFullname" . }}
14+
minReplicas: {{ .Values.nginx.autoscaling.minReplicas }}
15+
maxReplicas: {{ .Values.nginx.autoscaling.maxReplicas }}
16+
metrics:
17+
{{- if .Values.nginx.autoscaling.targetCPUUtilizationPercentage }}
18+
- type: Resource
19+
resource:
20+
name: cpu
21+
target:
22+
type: Utilization
23+
averageUtilization: {{ .Values.nginx.autoscaling.targetCPUUtilizationPercentage }}
24+
{{- end }}
25+
{{- if .Values.nginx.autoscaling.targetMemoryUtilizationPercentage }}
26+
- type: Resource
27+
resource:
28+
name: memory
29+
target:
30+
type: Utilization
31+
averageUtilization: {{ .Values.nginx.autoscaling.targetMemoryUtilizationPercentage }}
32+
{{- end }}
33+
{{- with .Values.nginx.autoscaling.behavior }}
34+
behavior:
35+
{{- toYaml . | nindent 4 }}
36+
{{- end }}
37+
{{- end }}
38+
{{- end -}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{{- define "maykinUtilsLib.webAppHpa" -}}
2+
{{- if .Values.autoscaling.enabled }}
3+
apiVersion: autoscaling/v2
4+
kind: HorizontalPodAutoscaler
5+
metadata:
6+
name: {{ include "project.fullname" . }}
7+
labels:
8+
{{- include "project.labels" . | nindent 4 }}
9+
spec:
10+
scaleTargetRef:
11+
apiVersion: apps/v1
12+
kind: Deployment
13+
name: {{ include "project.fullname" . }}
14+
minReplicas: {{ .Values.autoscaling.minReplicas }}
15+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
16+
metrics:
17+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
18+
- type: Resource
19+
resource:
20+
name: cpu
21+
target:
22+
type: Utilization
23+
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
24+
{{- end }}
25+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
26+
- type: Resource
27+
resource:
28+
name: memory
29+
target:
30+
type: Utilization
31+
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
32+
{{- end }}
33+
{{- with .Values.autoscaling.behavior }}
34+
behavior:
35+
{{- toYaml . | nindent 4 }}
36+
{{- end }}
37+
{{- end }}
38+
{{- end -}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{{- define "maykinUtilsLib.workerHpa" -}}
2+
{{- if .Values.worker.autoscaling.enabled }}
3+
apiVersion: autoscaling/v2
4+
kind: HorizontalPodAutoscaler
5+
metadata:
6+
name: {{ include "project.workerFullname" . }}
7+
labels:
8+
{{- include "project.workerSelectorLabels" . | nindent 4 }}
9+
spec:
10+
scaleTargetRef:
11+
apiVersion: apps/v1
12+
kind: Deployment
13+
name: {{ include "project.workerFullname" . }}
14+
minReplicas: {{ .Values.worker.autoscaling.minReplicas }}
15+
maxReplicas: {{ .Values.worker.autoscaling.maxReplicas }}
16+
metrics:
17+
{{- if .Values.worker.autoscaling.targetCPUUtilizationPercentage }}
18+
- type: Resource
19+
resource:
20+
name: cpu
21+
target:
22+
type: Utilization
23+
averageUtilization: {{ .Values.worker.autoscaling.targetCPUUtilizationPercentage }}
24+
{{- end }}
25+
{{- if .Values.worker.autoscaling.targetMemoryUtilizationPercentage }}
26+
- type: Resource
27+
resource:
28+
name: memory
29+
target:
30+
type: Utilization
31+
averageUtilization: {{ .Values.worker.autoscaling.targetMemoryUtilizationPercentage }}
32+
{{- end }}
33+
{{- with .Values.worker.autoscaling.behavior }}
34+
behavior:
35+
{{- toYaml . | nindent 4 }}
36+
{{- end }}
37+
{{- end }}
38+
{{- end -}}

0 commit comments

Comments
 (0)