From 3a817cc7c347c83a59a124d6bba4a0bf5cfe4812 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 24 Nov 2023 09:26:21 +1100 Subject: [PATCH] fix: resource overrides in nginx-php templates --- .../nginx-php-persistent/templates/_helpers.tpl | 13 +++++++++++++ .../nginx-php-persistent/templates/deployment.yaml | 5 ++--- legacy/helmcharts/nginx-php-persistent/values.yaml | 4 +++- legacy/helmcharts/nginx-php/templates/_helpers.tpl | 13 +++++++++++++ .../helmcharts/nginx-php/templates/deployment.yaml | 4 ++-- legacy/helmcharts/nginx-php/values.yaml | 4 +++- 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/legacy/helmcharts/nginx-php-persistent/templates/_helpers.tpl b/legacy/helmcharts/nginx-php-persistent/templates/_helpers.tpl index 0d290874..57d5420e 100644 --- a/legacy/helmcharts/nginx-php-persistent/templates/_helpers.tpl +++ b/legacy/helmcharts/nginx-php-persistent/templates/_helpers.tpl @@ -135,3 +135,16 @@ Generate path for twig storage emptyDir {{- define "nginx-php-persistent.twig-storage.path" -}} {{- printf "%s/php" .Values.persistentStorage.path }} {{- end -}} + +{{/* +Merge resources from global over resources defined in the values +*/}} +{{- define "resources" -}} +{{- $value := dict -}} +{{- range (rest .) -}} + {{- $value = merge $value . -}} +{{- end -}} +{{- if $value -}} +{{- toYaml $value }} +{{- end }} +{{- end -}} \ No newline at end of file diff --git a/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml b/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml index a96ac80d..67a41d92 100644 --- a/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml +++ b/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml @@ -109,8 +109,7 @@ spec: {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} {{- end }} resources: - {{- toYaml .Values.resources.nginx | nindent 12 }} - + {{- include "resources" (list "resources" .Values.resources .Values.containerResources.nginx) | nindent 12 }} - image: {{ .Values.images.php | quote }} name: "php" imagePullPolicy: {{ .Values.imagePullPolicy }} @@ -146,7 +145,7 @@ spec: {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} {{- end }} resources: - {{- toYaml .Values.resources.php | nindent 12 }} + {{- include "resources" (list "resources" .Values.resources .Values.containerResources.php ) | nindent 12 }} {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} diff --git a/legacy/helmcharts/nginx-php-persistent/values.yaml b/legacy/helmcharts/nginx-php-persistent/values.yaml index 349d9dc6..98f1ee06 100644 --- a/legacy/helmcharts/nginx-php-persistent/values.yaml +++ b/legacy/helmcharts/nginx-php-persistent/values.yaml @@ -40,7 +40,7 @@ fastly: # serviceId: '' # apiSecretName: '' -resources: +containerResources: nginx: # limits: # cpu: 100m @@ -56,6 +56,8 @@ resources: cpu: 10m memory: 100Mi +resources: {} + nodeSelector: {} cronjobNodeSelector: {} diff --git a/legacy/helmcharts/nginx-php/templates/_helpers.tpl b/legacy/helmcharts/nginx-php/templates/_helpers.tpl index b60c4a1d..99605844 100644 --- a/legacy/helmcharts/nginx-php/templates/_helpers.tpl +++ b/legacy/helmcharts/nginx-php/templates/_helpers.tpl @@ -113,3 +113,16 @@ lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} {{- end }} {{- end -}} + +{{/* +Merge resources from global over resources defined in the values +*/}} +{{- define "resources" -}} +{{- $value := dict -}} +{{- range (rest .) -}} + {{- $value = merge $value . -}} +{{- end -}} +{{- if $value -}} +{{- toYaml $value }} +{{- end }} +{{- end -}} \ No newline at end of file diff --git a/legacy/helmcharts/nginx-php/templates/deployment.yaml b/legacy/helmcharts/nginx-php/templates/deployment.yaml index c8eba938..dec5768e 100644 --- a/legacy/helmcharts/nginx-php/templates/deployment.yaml +++ b/legacy/helmcharts/nginx-php/templates/deployment.yaml @@ -72,7 +72,7 @@ spec: - configMapRef: name: lagoon-env resources: - {{- toYaml .Values.resources.nginx | nindent 12 }} + {{- include "resources" (list "resources" .Values.resources .Values.containerResources.nginx ) | nindent 12 }} {{- if .Values.dynamicSecretMounts }} volumeMounts: {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} @@ -105,7 +105,7 @@ spec: - name: NGINX_FASTCGI_PASS value: '127.0.0.1' resources: - {{- toYaml .Values.resources.php | nindent 12 }} + {{- include "resources" (list "resources" .Values.resources .Values.containerResources.php ) | nindent 12 }} {{- if .Values.dynamicSecretMounts }} volumeMounts: {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} diff --git a/legacy/helmcharts/nginx-php/values.yaml b/legacy/helmcharts/nginx-php/values.yaml index 6ff1e757..b23fa64f 100644 --- a/legacy/helmcharts/nginx-php/values.yaml +++ b/legacy/helmcharts/nginx-php/values.yaml @@ -37,7 +37,7 @@ fastly: # serviceId: '' # apiSecretName: '' -resources: +containerResources: nginx: # limits: # cpu: 100m @@ -53,6 +53,8 @@ resources: cpu: 10m memory: 100Mi +resources: {} + nodeSelector: {} cronjobNodeSelector: {}