소스 검색

Add method to render all volumes/env variables

Waqar Ahmed 4 년 전
부모
커밋
502e700103
2개의 변경된 파일44개의 추가작업 그리고 6개의 파일을 삭제
  1. 11 0
      library/common/2101.0.0/templates/lib/containers/_environment.tpl
  2. 33 6
      library/common/2101.0.0/templates/lib/storage/_appStorage.tpl

+ 11 - 0
library/common/2101.0.0/templates/lib/containers/_environment.tpl

@@ -28,3 +28,14 @@ Render environment variables
 {{- include "common.containers.environmentVariable" $envVariable | nindent 0 -}}
 {{- end -}}
 {{- end -}}
+
+{{/*
+Render environment variables if present
+*/}}
+{{- define "common.containers.allEnvironmentVariables" -}}
+{{- $values := . -}}
+{{- include "common.schema.validateKeys" (dict "values" $values "checkKeys" (list "environmentVariables")) -}}
+{{- if $values.environmentVariables -}}
+env: {{- include "common.containers.environmentVariables" $values | nindent 2 -}}
+{{- end -}}
+{{- end -}}

+ 33 - 6
library/common/2101.0.0/templates/lib/storage/_appStorage.tpl

@@ -2,8 +2,10 @@
 Define appVolumeMounts for container
 */}}
 {{- define "common.storage.configureAppVolumeMountsInContainer" -}}
-{{- if and .Values.appVolumesEnabled .Values.appVolumeMounts }}
-{{- range $name, $avm := .Values.appVolumeMounts -}}
+{{- include "common.schema.validateKeys" (dict "values" . "checkKeys" (list "appVolumeMounts")) -}}
+{{- $appVolumeMounts := .appVolumeMounts -}}
+{{- if $appVolumeMounts }}
+{{- range $name, $avm := $appVolumeMounts -}}
 {{- if (default true $avm.enabled) }}
 {{- if $avm.containerNameOverride -}}
 {{- $name = $avm.containerNameOverride -}}
@@ -23,19 +25,22 @@ Define appVolumeMounts for container
 Define hostPath for appVolumes
 */}}
 {{- define "common.storage.configureAppVolumes" -}}
-{{- if .Values.appVolumeMounts }}
-{{- range $name, $av := .Values.appVolumeMounts -}}
+{{- include "common.schema.validateKeys" (dict "values" . "checkKeys" (list "appVolumeMounts")) -}}
+{{- $appVolumeMounts := .appVolumeMounts -}}
+{{- if $appVolumeMounts }}
+{{- range $name, $av := $appVolumeMounts -}}
 {{- if (default true $av.enabled) }}
 - name: {{ $name }}
-  {{- if or $av.emptyDir $.Values.emptyDirVolumes }}
+  {{- if or $av.emptyDir $.emptyDirVolumes }}
   emptyDir: {}
   {{- else }}
   hostPath:
     {{ if $av.hostPathEnabled }}
     path: {{ required "hostPath not set" $av.hostPath }}
     {{- else }}
+    {{- include "common.schema.validateKeys" (dict "values" . "checkKeys" (list "ixVolumes")) -}}
     {{- include "common.schema.validateKeys" (dict "values" $av "checkKeys" (list "datasetName")) -}}
-    {{- $volDict := dict "datasetName" $av.datasetName "ixVolumes" $.Values.ixVolumes -}}
+    {{- $volDict := dict "datasetName" $av.datasetName "ixVolumes" $.ixVolumes -}}
     path: {{ include "common.storage.retrieveHostPathFromiXVolume" $volDict }}
     {{- end }}
   {{- end }}
@@ -43,3 +48,25 @@ Define hostPath for appVolumes
 {{- end }}
 {{- end }}
 {{- end -}}
+
+
+{{/*
+Get all volumes configuration
+*/}}
+{{- define "common.storage.allAppVolumes" -}}
+{{- $appVolumeMounts := .appVolumeMounts -}}
+{{- if $appVolumeMounts -}}
+volumes: {{- include "common.storage.configureAppVolumes" . | nindent 2 -}}
+{{- end -}}
+{{- end -}}
+
+
+{{/*
+Get all container volume moutns configuration
+*/}}
+{{- define "common.storage.allContainerVolumeMounts" -}}
+{{- $appVolumeMounts := .appVolumeMounts -}}
+{{- if $appVolumeMounts -}}
+volumeMounts: {{- include "common.storage.configureAppVolumeMountsInContainer" . | nindent 2 -}}
+{{- end -}}
+{{- end -}}