From 12b9a197a4715f109aacc59f094189a1f1e66f0f Mon Sep 17 00:00:00 2001 From: Gabi Davar Date: Wed, 7 Aug 2024 11:23:42 +0300 Subject: [PATCH] Tell Go runtime about the CPU & memory limits. (#699) * Tell Go runtime about the CPU & memory limits. Signed-off-by: Gabi Davar * review comments --------- Signed-off-by: Gabi Davar --- .github/workflows/push.yaml | 4 ++-- .../chart/reloader/templates/deployment.yaml | 19 ++++++++++++++++--- .../kubernetes/chart/reloader/values.yaml | 5 +++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index 3e9524c3e..a7a665aa2 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -212,8 +212,8 @@ jobs: - name: Helm Template run: | helm template reloader deployments/kubernetes/chart/reloader/ \ - --set reloader.deployment.resources.limits.cpu=150m \ - --set reloader.deployment.resources.limits.memory=512Mi \ + --set-string reloader.deployment.resources.limits.cpu=1 \ + --set reloader.deployment.resources.limits.memory=128Mi \ --set reloader.deployment.resources.requests.cpu=10m \ --set reloader.deployment.resources.requests.memory=128Mi > deployments/kubernetes/reloader.yaml diff --git a/deployments/kubernetes/chart/reloader/templates/deployment.yaml b/deployments/kubernetes/chart/reloader/templates/deployment.yaml index e1105343b..d43bd872b 100644 --- a/deployments/kubernetes/chart/reloader/templates/deployment.yaml +++ b/deployments/kubernetes/chart/reloader/templates/deployment.yaml @@ -76,8 +76,23 @@ 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: + - name: GOMAXPROCS + {{- if .Values.reloader.deployment.gomaxprocsOverride }} + value: {{ .Values.reloader.deployment.gomaxprocsOverride | quote }} + {{- else }} + valueFrom: + resourceFieldRef: + resource: limits.memory + {{- end }} + - name: GOMEMLIMIT + {{- if .Values.reloader.deployment.gomemlimitOverride }} + value: {{ .Values.reloader.deployment.gomemlimitOverride | quote }} + {{- else }} + valueFrom: + resourceFieldRef: + resource: limits.cpu + {{- end }} {{- range $name, $value := .Values.reloader.deployment.env.open }} {{- if not (empty $value) }} - name: {{ $name | quote }} @@ -112,7 +127,6 @@ spec: fieldRef: fieldPath: {{ $value | quote}} {{- end }} - {{- end }} {{- if eq .Values.reloader.watchGlobally false }} - name: KUBERNETES_NAMESPACE valueFrom: @@ -134,7 +148,6 @@ spec: value: enabled {{- end }} {{- end }} - ports: - name: http containerPort: 9090 diff --git a/deployments/kubernetes/chart/reloader/values.yaml b/deployments/kubernetes/chart/reloader/values.yaml index bb0f55e54..629dafb1b 100644 --- a/deployments/kubernetes/chart/reloader/values.yaml +++ b/deployments/kubernetes/chart/reloader/values.yaml @@ -147,6 +147,11 @@ reloader: # imagePullSecrets: # - name: myregistrykey + # Put "0" in either to have go runtime ignore the set value. + # Otherwise, see https://pkg.go.dev/runtime#hdr-Environment_Variables for GOMAXPROCS and GOMEMLIMIT + gomaxprocsOverride: "" + gomemlimitOverride: "" + service: {} # labels: {} # annotations: {}