existing configmap provided Andrea Pulvirenti <an.pulvygmail.com>
This commit is contained in:
parent
34237fe857
commit
bf290931ce
|
|
@ -1,3 +1,11 @@
|
|||
|
||||
{{/*
|
||||
Allow namespace to be overriden
|
||||
*/}}
|
||||
{{- define "common.name.namespace" -}}
|
||||
{{- default .Release.Namespace .Values.namespaceOverride | trunc 63 | trimSuffix "-" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* vim: set filetype=mustache: */}}
|
||||
{{/*
|
||||
Expand the name of the chart.
|
||||
|
|
@ -101,3 +109,50 @@ Selector labels
|
|||
app: {{ template "nfs-subdir-external-provisioner.name" . }}
|
||||
release: {{ .Release.Name }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Return true if an existing configmap name has been provided
|
||||
*/}}
|
||||
{{- define "nfs.existing-configmap-provided" -}}
|
||||
{{- if .Values.nfs.existingConfigMap.name -}}
|
||||
{{- true -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/*
|
||||
Return the existing NFS Configmap Name
|
||||
*/}}
|
||||
{{- define "nfs.existing-configmap" -}}
|
||||
{{- if .Values.nfs.existingConfigMap.name -}}
|
||||
{{- printf "%s" (tpl .Values.nfs.existingConfigMap.name $) -}}
|
||||
{{- else -}}
|
||||
{{- printf "\n%s CONFIGMAP ERROR: no existing configmap has been provided" }}
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
|
||||
|
||||
{{/*
|
||||
Reuses the value from an existing configmap, otherwise sets its value to a default value.
|
||||
|
||||
Usage:
|
||||
{{ include "common.configmap.lookup" (dict "secret" "configmap-name" "key" "keyName" "defaultValue" .Values.myValue "context" $) }}
|
||||
|
||||
Params:
|
||||
- configmapName - String - Required - Name of the 'Secret' resource where the password is stored.
|
||||
- key - String - Required - Name of the key in the secret.
|
||||
- defaultValue - String - Required - The path to the validating value in the values.yaml, e.g: "mysql.password". Will pick first parameter with a defined value.
|
||||
- context - Context - Required - Parent context.
|
||||
|
||||
*/}}
|
||||
{{- define "common.configmap.lookup" -}}
|
||||
{{- $value := "" -}}
|
||||
{{- $configmapData := (lookup "v1" "ConfigMap" (include "common.names.namespace" .context) .configmapName).data -}}
|
||||
{{- if and $configmapData (hasKey $configmapData .key) -}}
|
||||
{{- $value = index $configmapData .key -}}
|
||||
{{- else if .defaultValue -}}
|
||||
{{- $value = .defaultValue | toString -}}
|
||||
{{- end -}}
|
||||
{{- if $value -}}
|
||||
{{- printf "%s" $value -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
{{ if (include "nfs.existing-configmap-provided" .) }}
|
||||
{{- $existingConfigMap := (lookup "v1" "ConfigMap" .Values.nfs.existingConfigMap.namespace .Values.nfs.existingConfigMap.name).data | default dict }}
|
||||
{{- if not $existingConfigMap }}
|
||||
apiVersion: v1
|
||||
data:
|
||||
path: {{ .Values.nfs.path }}
|
||||
server: {{ .Values.nfs.server}}
|
||||
immutable: false
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: {{ template "nfs.existing-configmap" . }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
|
@ -1,3 +1,11 @@
|
|||
|
||||
{{- $server := .Values.nfs.server -}}
|
||||
{{- $path := .Values.nfs.path -}}
|
||||
{{- if (include "nfs.existing-configmap-provided" .) -}}
|
||||
{{- $server := (include "common.configmap.lookup" (dict "config" .Values.nfs.existingConfigMap.name "key" "server" "defaultValue" .Values.nfs.server "context")) -}}
|
||||
{{- $path := (include "common.configmap.lookup" (dict "config" .Values.nfs.existingConfigMap.name "key" "path" "defaultValue" .Values.nfs.path "context")) -}}
|
||||
{{- end -}}
|
||||
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
|
|
@ -54,9 +62,9 @@ spec:
|
|||
- name: PROVISIONER_NAME
|
||||
value: {{ template "nfs-subdir-external-provisioner.provisionerName" . }}
|
||||
- name: NFS_SERVER
|
||||
value: {{ .Values.nfs.server }}
|
||||
value: {{ $server }}
|
||||
- name: NFS_PATH
|
||||
value: {{ .Values.nfs.path }}
|
||||
value: {{ $path }}
|
||||
{{- if eq .Values.leaderElection.enabled false }}
|
||||
- name: ENABLE_LEADER_ELECTION
|
||||
value: "false"
|
||||
|
|
@ -74,8 +82,8 @@ spec:
|
|||
claimName: pvc-{{ template "nfs-subdir-external-provisioner.fullname" . }}
|
||||
{{- else }}
|
||||
nfs:
|
||||
server: {{ .Values.nfs.server }}
|
||||
path: {{ .Values.nfs.path }}
|
||||
server: {{ $server}}
|
||||
path: {{ $path }}
|
||||
{{- end }}
|
||||
{{- if and (.Values.tolerations) (semverCompare "^1.6-0" .Capabilities.KubeVersion.GitVersion) }}
|
||||
tolerations:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
{{ if .Values.nfs.mountOptions -}}
|
||||
{{- $server := .Values.nfs.server -}}
|
||||
{{- $path := .Values.nfs.path -}}
|
||||
{{- if (include "nfs.existing-configmap-provided" .) -}}
|
||||
{{- $server := (include "common.configmap.lookup" (dict "config" .Values.nfs.existingConfigMap.name "key" "server" "defaultValue" .Values.nfs.server "context")) -}}
|
||||
{{- $path := (include "common.configmap.lookup" (dict "config" .Values.nfs.existingConfigMap.name "key" "path" "defaultValue" .Values.nfs.path "context")) -}}
|
||||
{{- end -}}
|
||||
apiVersion: v1
|
||||
kind: PersistentVolume
|
||||
metadata:
|
||||
|
|
@ -21,6 +27,6 @@ spec:
|
|||
{{- end }}
|
||||
{{- end }}
|
||||
nfs:
|
||||
server: {{ .Values.nfs.server }}
|
||||
path: {{ .Values.nfs.path }}
|
||||
server: {{ $server }}
|
||||
path: {{ $path }}
|
||||
{{ end -}}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,10 @@ nfs:
|
|||
volumeName: nfs-subdir-external-provisioner-root
|
||||
# Reclaim policy for the main nfs volume
|
||||
reclaimPolicy: Retain
|
||||
# existing configmap in order to get server and path
|
||||
existingConfigMap:
|
||||
name:
|
||||
namespace: default
|
||||
|
||||
# For creating the StorageClass automatically:
|
||||
storageClass:
|
||||
|
|
|
|||
Loading…
Reference in New Issue