provide existing configmap Andrea Pulvirenti <an.pulvy@gmail.com>
This commit is contained in:
		
							parent
							
								
									814e0d8d92
								
							
						
					
					
						commit
						ef0d82733a
					
				|  | @ -1,3 +1,11 @@ | ||||||
|  | 
 | ||||||
|  | {{/*  | ||||||
|  |    Allow namespace to be overriden | ||||||
|  | */}} | ||||||
|  | {{- define "common.names.namespace" -}} | ||||||
|  | {{- default .Release.Namespace .Values.namespaceOverride | trunc 63 | trimSuffix "-" -}} | ||||||
|  | {{- end -}} | ||||||
|  | 
 | ||||||
| {{/* vim: set filetype=mustache: */}} | {{/* vim: set filetype=mustache: */}} | ||||||
| {{/* | {{/* | ||||||
| Expand the name of the chart. | Expand the name of the chart. | ||||||
|  | @ -101,3 +109,50 @@ Selector labels | ||||||
| app: {{ template "nfs-subdir-external-provisioner.name" . }} | app: {{ template "nfs-subdir-external-provisioner.name" . }} | ||||||
| release: {{ .Release.Name }} | release: {{ .Release.Name }} | ||||||
| {{- end }} | {{- 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: | ||||||
|  |   - config - 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" .context.Values.nfs.existingConfigMap.namespace .config).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,16 @@ | ||||||
|  | {{- $server := .Values.nfs.server  | default "127.0.0.1" -}} | ||||||
|  | {{ if (include "nfs.existing-configmap-provided" .) }} | ||||||
|  | {{- $existingConfigMap := (lookup "v1" "ConfigMap" .Values.nfs.existingConfigMap.namespace .Values.nfs.existingConfigMap.name).data }} | ||||||
|  | {{- if (not $existingConfigMap)  }} | ||||||
|  | apiVersion: v1 | ||||||
|  | data: | ||||||
|  |   path: {{ .Values.nfs.path }} | ||||||
|  |   server: {{ $server }} | ||||||
|  | immutable: false | ||||||
|  | kind: ConfigMap | ||||||
|  | metadata: | ||||||
|  |   name: {{ template "nfs.existing-configmap" . }} | ||||||
|  |   annotation:  | ||||||
|  |     helm.sh/hook: pre-install, pre-upgrade | ||||||
|  | {{- end }} | ||||||
|  | {{- end }} | ||||||
|  | @ -1,3 +1,9 @@ | ||||||
|  | {{- $server := .Values.nfs.server | default "127.0.0.1" -}} | ||||||
|  | {{- $path := .Values.nfs.path -}} | ||||||
|  | {{- if (include "nfs.existing-configmap-provided" .) -}} | ||||||
|  | {{- $server = (include "common.configmap.lookup" (dict "config" .Values.nfs.existingConfigMap.name "key" "server" "defaultValue" "127.0.0.1" "context" $)) -}} | ||||||
|  | {{- $path = (include "common.configmap.lookup" (dict "config" .Values.nfs.existingConfigMap.name "key" "path" "defaultValue" .Values.nfs.path "context" $)) -}} | ||||||
|  | {{- end -}} | ||||||
| apiVersion: apps/v1 | apiVersion: apps/v1 | ||||||
| kind: Deployment | kind: Deployment | ||||||
| metadata: | metadata: | ||||||
|  | @ -54,9 +60,9 @@ spec: | ||||||
|             - name: PROVISIONER_NAME |             - name: PROVISIONER_NAME | ||||||
|               value: {{ template "nfs-subdir-external-provisioner.provisionerName" . }} |               value: {{ template "nfs-subdir-external-provisioner.provisionerName" . }} | ||||||
|             - name: NFS_SERVER |             - name: NFS_SERVER | ||||||
|               value: {{ .Values.nfs.server }} |               value: {{ $server }} | ||||||
|             - name: NFS_PATH |             - name: NFS_PATH | ||||||
|               value: {{ .Values.nfs.path }} |               value: {{ $path }} | ||||||
|             {{- if eq .Values.leaderElection.enabled false }} |             {{- if eq .Values.leaderElection.enabled false }} | ||||||
|             - name: ENABLE_LEADER_ELECTION |             - name: ENABLE_LEADER_ELECTION | ||||||
|               value: "false" |               value: "false" | ||||||
|  | @ -74,8 +80,8 @@ spec: | ||||||
|             claimName: pvc-{{ template "nfs-subdir-external-provisioner.fullname" . }} |             claimName: pvc-{{ template "nfs-subdir-external-provisioner.fullname" . }} | ||||||
| {{- else }} | {{- else }} | ||||||
|           nfs: |           nfs: | ||||||
|             server: {{ .Values.nfs.server }} |             server: {{ $server}} | ||||||
|             path: {{ .Values.nfs.path }} |             path: {{ $path }} | ||||||
| {{- end }} | {{- end }} | ||||||
|       {{- if and (.Values.tolerations) (semverCompare "^1.6-0" .Capabilities.KubeVersion.GitVersion) }} |       {{- if and (.Values.tolerations) (semverCompare "^1.6-0" .Capabilities.KubeVersion.GitVersion) }} | ||||||
|       tolerations: |       tolerations: | ||||||
|  |  | ||||||
|  | @ -1,4 +1,10 @@ | ||||||
| {{ if .Values.nfs.mountOptions -}} | {{ 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 | apiVersion: v1 | ||||||
| kind: PersistentVolume | kind: PersistentVolume | ||||||
| metadata: | metadata: | ||||||
|  | @ -21,6 +27,6 @@ spec: | ||||||
|     {{- end }} |     {{- end }} | ||||||
|   {{- end }} |   {{- end }} | ||||||
|   nfs: |   nfs: | ||||||
|     server: {{ .Values.nfs.server }} |     server: {{ $server }} | ||||||
|     path: {{ .Values.nfs.path }} |     path: {{ $path }} | ||||||
| {{ end -}} | {{ end -}} | ||||||
|  |  | ||||||
|  | @ -14,6 +14,10 @@ nfs: | ||||||
|   volumeName: nfs-subdir-external-provisioner-root |   volumeName: nfs-subdir-external-provisioner-root | ||||||
|   # Reclaim policy for the main nfs volume |   # Reclaim policy for the main nfs volume | ||||||
|   reclaimPolicy: Retain |   reclaimPolicy: Retain | ||||||
|  |   # existing configmap in order to get server and path | ||||||
|  |   existingConfigMap: | ||||||
|  |     name: oiadp-nfs-config | ||||||
|  |     namespace: default | ||||||
| 
 | 
 | ||||||
| # For creating the StorageClass automatically: | # For creating the StorageClass automatically: | ||||||
| storageClass: | storageClass: | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue