Skip to content

Commit

Permalink
Tell Go runtime about the CPU & memory limits.
Browse files Browse the repository at this point in the history
Signed-off-by: Gabi Davar <grizzly.nyo@gmail.com>
  • Loading branch information
mindw committed Jun 24, 2024
1 parent fc955f7 commit 72c623b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ jobs:
--set reloader.deployment.resources.limits.cpu=150m \
--set reloader.deployment.resources.limits.memory=512Mi \
--set reloader.deployment.resources.requests.cpu=10m \
--set reloader.deployment.resources.requests.memory=128Mi > deployments/kubernetes/reloader.yaml
--set reloader.deployment.resources.requests.memory=512Mi > deployments/kubernetes/reloader.yaml
helm template reloader deployments/kubernetes/chart/reloader/ --output-dir deployments/kubernetes/manifests && mv deployments/kubernetes/manifests/reloader/templates/* deployments/kubernetes/manifests/ && rm -r deployments/kubernetes/manifests/reloader
Expand Down
20 changes: 20 additions & 0 deletions deployments/kubernetes/chart/reloader/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,23 @@ Create the annotations to support helm3
meta.helm.sh/release-namespace: {{ .Release.Namespace | quote }}
meta.helm.sh/release-name: {{ .Release.Name | quote }}
{{- end -}}

{{- define "reloader-convertCpuResourceToCores" -}}
{{- $coresf := . -}}
{{- if hasSuffix "m" . -}}
{{- $milicores := trimSuffix "m" . -}}
{{- $coresf = divf $milicores 1000.0 -}}
{{- end -}}
{{- ceil $coresf -}}
{{- end -}}

{{- define "reloader-convertMemResourceToMi" -}}
{{- $mibis := trimSuffix "Mi" . -}}
{{- if hasSuffix "Ki" . -}}
{{- $kilobytes := trimSuffix "Ki" . -}}
{{- $mibis = divf $kilobytes 1024.0 | ceil -}}
{{- else if hasSuffix "Gi" . -}}
{{- $mibis = trimSuffix "Gi" . | mulf 1024.0 | ceil -}}
{{- end -}}
{{- $mibis -}}Mi
{{- end -}}
12 changes: 10 additions & 2 deletions deployments/kubernetes/chart/reloader/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,17 @@ spec:
- image: "{{ .Values.reloader.deployment.image.name }}:{{ .Values.reloader.deployment.image.tag }}"
imagePullPolicy: {{ .Values.reloader.deployment.image.pullPolicy }}
name: {{ template "reloader-fullname" . }}
{{- if or (.Values.reloader.deployment.env.open) (.Values.reloader.deployment.env.secret) (.Values.reloader.deployment.env.field) (.Values.reloader.deployment.env.existing) (eq .Values.reloader.watchGlobally false) (.Values.reloader.enableHA) (.Values.reloader.enableMetricsByNamespace)}}
env:
{{- with .Values.reloader.deployment.resources.limits }}
{{- with .cpu }}
- name: GOMAXPROCS
value: {{ include "reloader-convertCpuResourceToCores" . | quote }}
{{- end }}
{{- with .memory }}
- name: GOMEMLIMIT
value: {{ include "reloader-convertMemResourceToMi" . }}B
{{- end }}
{{- end }}
{{- range $name, $value := .Values.reloader.deployment.env.open }}
{{- if not (empty $value) }}
- name: {{ $name | quote }}
Expand Down Expand Up @@ -112,7 +121,6 @@ spec:
fieldRef:
fieldPath: {{ $value | quote}}
{{- end }}
{{- end }}
{{- if eq .Values.reloader.watchGlobally false }}
- name: KUBERNETES_NAMESPACE
valueFrom:
Expand Down

0 comments on commit 72c623b

Please sign in to comment.