From 502e700103ce139d08e08776e2b5f33dfec49279 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Tue, 2 Feb 2021 17:50:13 +0500 Subject: [PATCH] Add method to render all volumes/env variables --- .../templates/lib/containers/_environment.tpl | 11 ++++++ .../templates/lib/storage/_appStorage.tpl | 39 ++++++++++++++++--- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/library/common/2101.0.0/templates/lib/containers/_environment.tpl b/library/common/2101.0.0/templates/lib/containers/_environment.tpl index 4a1fd1410f..9d3862599b 100644 --- a/library/common/2101.0.0/templates/lib/containers/_environment.tpl +++ b/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 -}} diff --git a/library/common/2101.0.0/templates/lib/storage/_appStorage.tpl b/library/common/2101.0.0/templates/lib/storage/_appStorage.tpl index 84e5ed062d..969cbf414e 100644 --- a/library/common/2101.0.0/templates/lib/storage/_appStorage.tpl +++ b/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 -}}