aboutsummaryrefslogtreecommitdiffstats
path: root/tutorials/ApacheCNF/templates/cba/Templates/k8s-configs/deployment-config/templates
diff options
context:
space:
mode:
Diffstat (limited to 'tutorials/ApacheCNF/templates/cba/Templates/k8s-configs/deployment-config/templates')
-rw-r--r--tutorials/ApacheCNF/templates/cba/Templates/k8s-configs/deployment-config/templates/_helpers.tpl263
-rw-r--r--tutorials/ApacheCNF/templates/cba/Templates/k8s-configs/deployment-config/templates/deployment.yaml172
2 files changed, 435 insertions, 0 deletions
diff --git a/tutorials/ApacheCNF/templates/cba/Templates/k8s-configs/deployment-config/templates/_helpers.tpl b/tutorials/ApacheCNF/templates/cba/Templates/k8s-configs/deployment-config/templates/_helpers.tpl
new file mode 100644
index 00000000..e2e14018
--- /dev/null
+++ b/tutorials/ApacheCNF/templates/cba/Templates/k8s-configs/deployment-config/templates/_helpers.tpl
@@ -0,0 +1,263 @@
+{{/* vim: set filetype=mustache: */}}
+{{/*
+Expand the name of the chart.
+*/}}
+{{- define "apache.name" -}}
+{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
+{{- end -}}
+
+{{/*
+Create a default fully qualified app name.
+We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
+*/}}
+{{- define "apache.fullname" -}}
+{{- if .Values.fullnameOverride -}}
+{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
+{{- else -}}
+{{- $name := default .Chart.Name .Values.nameOverride -}}
+{{- if contains $name .Release.Name -}}
+{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
+{{- else -}}
+{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
+{{- end -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Common labels
+*/}}
+{{- define "apache.labels" -}}
+app.kubernetes.io/name: {{ include "apache.name" . }}
+helm.sh/chart: {{ include "apache.chart" . }}
+app.kubernetes.io/instance: {{ .Release.Name }}
+app.kubernetes.io/managed-by: {{ .Release.Service }}
+{{- end -}}
+
+{{/*
+Labels to use on deploy.spec.selector.matchLabels and svc.spec.selector
+*/}}
+{{- define "apache.matchLabels" -}}
+app.kubernetes.io/name: {{ include "apache.name" . }}
+app.kubernetes.io/instance: {{ .Release.Name }}
+{{- end -}}
+
+{{/*
+Return the proper Apache image name
+*/}}
+{{- define "apache.image" -}}
+{{- $registryName := .Values.image.registry -}}
+{{- $repositoryName := .Values.image.repository -}}
+{{- $tag := .Values.image.tag | toString -}}
+{{/*
+Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
+but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
+Also, we can't use a single if because lazy evaluation is not an option
+*/}}
+{{- if .Values.global }}
+ {{- if .Values.global.imageRegistry }}
+ {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
+ {{- else -}}
+ {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
+ {{- end -}}
+{{- else -}}
+ {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Return the proper Apache Docker Image Registry Secret Names
+*/}}
+{{- define "apache.imagePullSecrets" -}}
+{{/*
+Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
+but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
+Also, we can't use a single if because lazy evaluation is not an option
+*/}}
+{{- if .Values.global }}
+{{- if .Values.global.imagePullSecrets }}
+imagePullSecrets:
+{{- range .Values.global.imagePullSecrets }}
+ - name: {{ . }}
+{{- end }}
+{{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets }}
+imagePullSecrets:
+{{- range .Values.image.pullSecrets }}
+ - name: {{ . }}
+{{- end }}
+{{- range .Values.metrics.image.pullSecrets }}
+ - name: {{ . }}
+{{- end }}
+{{- end -}}
+{{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets }}
+imagePullSecrets:
+{{- range .Values.image.pullSecrets }}
+ - name: {{ . }}
+{{- end }}
+{{- range .Values.metrics.image.pullSecrets }}
+ - name: {{ . }}
+{{- end }}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Return the proper image name (for the metrics image)
+*/}}
+{{- define "apache.metrics.image" -}}
+{{- $registryName := .Values.metrics.image.registry -}}
+{{- $repositoryName := .Values.metrics.image.repository -}}
+{{- $tag := .Values.metrics.image.tag | toString -}}
+{{/*
+Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
+but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
+Also, we can't use a single if because lazy evaluation is not an option
+*/}}
+{{- if .Values.global }}
+ {{- if .Values.global.imageRegistry }}
+ {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
+ {{- else -}}
+ {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
+ {{- end -}}
+{{- else -}}
+ {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Return true if mouting a static web page
+*/}}
+{{- define "apache.useHtdocs" -}}
+{{ default "" (or .Values.cloneHtdocsFromGit.enabled .Values.htdocsConfigMap .Values.htdocsPVC) }}
+{{- end -}}
+
+{{/*
+Return associated volume
+*/}}
+{{- define "apache.htdocsVolume" -}}
+{{- if .Values.cloneHtdocsFromGit.enabled }}
+emptyDir: {}
+{{- else if .Values.htdocsConfigMap }}
+configMap:
+ name: {{ .Values.htdocsConfigMap }}
+{{- else if .Values.htdocsPVC }}
+persistentVolumeClaim:
+ claimName: {{ .Values.htdocsPVC }}
+{{- end }}
+{{- end -}}
+
+{{/*
+Validate data
+*/}}
+{{- define "apache.validateValues" -}}
+{{- $messages := list -}}
+{{- $messages := append $messages (include "apache.validateValues.htdocs" .) -}}
+{{- $messages := append $messages (include "apache.validateValues.htdocsGit" .) -}}
+{{- $messages := without $messages "" -}}
+{{- $message := join "\n" $messages -}}
+ {{- if $message -}}
+{{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Create chart name and version as used by the chart label.
+*/}}
+{{- define "apache.chart" -}}
+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
+{{- end -}}
+
+{{/*
+Validate data (htdocs)
+*/}}
+{{- define "apache.validateValues.htdocs" -}}
+{{- if or (and .Values.cloneHtdocsFromGit.enabled (or .Values.htdocsPVC .htdocsConfigMap )) (and .Values.htdocsPVC (or .Values.htdocsConfigMap .Values.cloneHtdocsFromGit.enabled )) (and .Values.htdocsConfigMap (or .Values.htdocsPVC .Values.cloneHtdocsFromGit.enabled )) }}
+apache: htdocs
+ You have selected more than one way of deploying htdocs. Please select only one of htdocsConfigMap cloneHtdocsFromGit or htdocsVolume
+{{- end }}
+{{- end -}}
+
+{{/*
+Validate data (htdocs git)
+*/}}
+{{- define "apache.validateValues.htdocsGit" -}}
+{{- if .Values.cloneHtdocsFromGit.enabled }}
+ {{- if not .Values.cloneHtdocsFromGit.repository }}
+apache: htdocs-git-repository
+ You did not specify a git repository to clone. Please set cloneHtdocsFromGit.repository
+ {{- end }}
+ {{- if not .Values.cloneHtdocsFromGit.branch }}
+apache: htdocs-git-branch
+ You did not specify a branch to checkout in the git repository. Please set cloneHtdocsFromGit.branch
+ {{- end }}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Validate values of Apache - Incorrect extra volume settings
+*/}}
+{{- define "apache.validateValues.extraVolumes" -}}
+{{- if and (.Values.extraVolumes) (not .Values.extraVolumeMounts) -}}
+apache: missing-extra-volume-mounts
+ You specified extra volumes but not mount points for them. Please set
+ the extraVolumeMounts value
+{{- end -}}
+{{- end -}}
+
+{{/*
+Return the proper git image name
+*/}}
+{{- define "git.image" -}}
+{{- $registryName := .Values.git.registry -}}
+{{- $repositoryName := .Values.git.repository -}}
+{{- $tag := .Values.git.tag | toString -}}
+{{/*
+Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
+but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
+Also, we can't use a single if because lazy evaluation is not an option
+*/}}
+{{- if .Values.global }}
+ {{- if .Values.global.imageRegistry }}
+ {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
+ {{- else -}}
+ {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
+ {{- end -}}
+{{- else -}}
+ {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Get the vhosts config map name.
+*/}}
+{{- define "apache.vhostsConfigMap" -}}
+{{- if .Values.vhostsConfigMap -}}
+ {{- printf "%s" (tpl .Values.vhostsConfigMap $) -}}
+{{- else -}}
+ {{- printf "%s-vhosts" (include "apache.fullname" . ) -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Get the httpd.conf config map name.
+*/}}
+{{- define "apache.httpdConfConfigMap" -}}
+{{- if .Values.httpdConfConfigMap -}}
+ {{- printf "%s" (tpl .Values.httpdConfConfigMap $) -}}
+{{- else -}}
+ {{- printf "%s-httpd-conf" (include "apache.fullname" . ) -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Renders a value that contains template.
+Usage:
+{{ include "apache.tplValue" ( dict "value" .Values.path.to.the.Value "context" $) }}
+*/}}
+{{- define "apache.tplValue" -}}
+ {{- if typeIs "string" .value }}
+ {{- tpl .value .context }}
+ {{- else }}
+ {{- tpl (.value | toYaml) .context }}
+ {{- end }}
+{{- end -}}
+
+
diff --git a/tutorials/ApacheCNF/templates/cba/Templates/k8s-configs/deployment-config/templates/deployment.yaml b/tutorials/ApacheCNF/templates/cba/Templates/k8s-configs/deployment-config/templates/deployment.yaml
new file mode 100644
index 00000000..45077121
--- /dev/null
+++ b/tutorials/ApacheCNF/templates/cba/Templates/k8s-configs/deployment-config/templates/deployment.yaml
@@ -0,0 +1,172 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: {{ include "apache.fullname" . }}
+ labels: {{- include "apache.labels" . | nindent 4 }}
+spec:
+ selector:
+ matchLabels: {{- include "apache.matchLabels" . | nindent 6 }}
+ replicas: {{ .Values.replicaCount }}
+ template:
+ metadata:
+ labels: {{- include "apache.labels" . | nindent 8 }}
+ {{- if or .Values.podAnnotations (and .Values.metrics.enabled .Values.metrics.podAnnotations) }}
+ annotations:
+ {{- if .Values.podAnnotations }}
+ {{- include "apache.tplValue" (dict "value" .Values.podAnnotations "context" $) | nindent 8 }}
+ {{- end }}
+ {{- if and .Values.metrics.enabled .Values.metrics.podAnnotations }}
+ {{- include "apache.tplValue" (dict "value" .Values.metrics.podAnnotations "context" $) | nindent 8 }}
+ {{- end }}
+ {{- end }}
+ spec:
+{{- include "apache.imagePullSecrets" . | nindent 6 }}
+ hostAliases:
+ - ip: "127.0.0.1"
+ hostnames:
+ - "status.localhost"
+ {{- if .Values.affinity }}
+ affinity: {{- include "apache.tplValue" (dict "value" .Values.affinity "context" $) | nindent 8 }}
+ {{- else }}
+ affinity:
+ podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAffinityPreset "context" $) | nindent 10 }}
+ podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAntiAffinityPreset "context" $) | nindent 10 }}
+ nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.nodeAffinityPreset.type "key" .Values.nodeAffinityPreset.key "values" .Values.nodeAffinityPreset.values) | nindent 10 }}
+ {{- end }}
+ {{- if .Values.nodeSelector }}
+ nodeSelector: {{- include "apache.tplValue" (dict "value" .Values.nodeSelector "context" $) | nindent 8 }}
+ {{- end }}
+ {{- if .Values.tolerations }}
+ tolerations: {{- include "apache.tplValue" (dict "value" .Values.tolerations "context" $) | nindent 8 }}
+ {{- end }}
+ {{- if .Values.cloneHtdocsFromGit.enabled }}
+ initContainers:
+ - name: git-clone-repository
+ image: {{ include "git.image" . }}
+ imagePullPolicy: {{ .Values.git.pullPolicy | quote }}
+ command:
+ - /bin/bash
+ - -ec
+ - |
+ git clone {{ .Values.cloneHtdocsFromGit.repository }} --branch {{ .Values.cloneHtdocsFromGit.branch }} /app
+ resources: {{- toYaml .Values.cloneHtdocsFromGit.resources | nindent 12 }}
+ volumeMounts:
+ - name: htdocs
+ mountPath: /app
+ containers:
+ - name: git-repo-syncer
+ image: {{ include "git.image" . }}
+ imagePullPolicy: {{ .Values.git.pullPolicy | quote }}
+ command:
+ - /bin/bash
+ - -ec
+ - |
+ while true; do
+ cd /app && git pull origin {{ .Values.cloneHtdocsFromGit.branch }}
+ sleep {{ .Values.cloneHtdocsFromGit.interval }}
+ done
+ resources: {{- toYaml .Values.cloneHtdocsFromGit.resources | nindent 12 }}
+ volumeMounts:
+ - name: htdocs
+ mountPath: /app
+ {{- else }}
+ containers:
+ {{- end }}
+ - name: apache
+ image: {{ include "apache.image" . }}
+ imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
+ env:
+ - name: BITNAMI_DEBUG
+ value: {{ ternary "true" "false" .Values.image.debug | quote }}
+ {{- if .Values.extraEnvVars }}
+ {{- include "apache.tplValue" (dict "value" .Values.extraEnvVars "context" $) | nindent 12 }}
+ {{- end }}
+ ports:
+ - name: http
+ containerPort: 8080
+ - name: https
+ containerPort: 8443
+ {{- if .Values.livenessProbe.enabled }}
+ livenessProbe:
+ httpGet:
+ path: {{ .Values.livenessProbe.path }}
+ port: http
+ initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
+ periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
+ timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
+ successThreshold: {{ .Values.livenessProbe.successThreshold }}
+ failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
+ {{- end }}
+ {{- if .Values.readinessProbe.enabled }}
+ readinessProbe:
+ httpGet:
+ path: {{ .Values.readinessProbe.path }}
+ port: http
+ initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
+ periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
+ timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
+ successThreshold: {{ .Values.readinessProbe.successThreshold }}
+ failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
+ {{- end }}
+ {{- if .Values.resources }}
+ resources: {{- toYaml .Values.resources | nindent 12 }}
+ {{- end }}
+ volumeMounts:
+ {{- if (include "apache.useHtdocs" .) }}
+ - name: htdocs
+ mountPath: /app
+ {{- end }}
+ {{- if or (.Files.Glob "files/vhosts/*.conf") (.Values.vhostsConfigMap) }}
+ - name: vhosts
+ mountPath: /vhosts
+ {{- end }}
+ {{- if or (.Files.Glob "files/httpd.conf") (.Values.httpdConfConfigMap) }}
+ - name: httpd-conf
+ mountPath: /opt/bitnami/apache/conf/httpd.conf
+ subPath: httpd.conf
+ {{- end }}
+ {{- if .Values.extraVolumeMounts }}
+ {{- include "common.tplvalues.render" ( dict "value" .Values.extraVolumeMounts "context" $) | nindent 12 }}
+ {{- end }}
+ {{- if .Values.metrics.enabled }}
+ - name: metrics
+ image: {{ template "apache.metrics.image" . }}
+ imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }}
+ command: ['/bin/apache_exporter', '--scrape_uri', 'http://status.localhost:8080/server-status/?auto']
+ ports:
+ - name: metrics
+ containerPort: 9117
+ livenessProbe:
+ httpGet:
+ path: /metrics
+ port: metrics
+ initialDelaySeconds: 15
+ timeoutSeconds: 5
+ readinessProbe:
+ httpGet:
+ path: /metrics
+ port: metrics
+ initialDelaySeconds: 5
+ timeoutSeconds: 1
+ {{- if .Values.metrics.resources }}
+ resources: {{- toYaml .Values.metrics.resources | nindent 12 }}
+ {{- end }}
+ {{- end }}
+ volumes:
+ {{- if (include "apache.useHtdocs" .) }}
+ - name: htdocs
+ {{- include "apache.htdocsVolume" . | nindent 10 }}
+ {{- end }}
+ {{- if or (.Files.Glob "files/vhosts/*.conf") (.Values.vhostsConfigMap) }}
+ - name: vhosts
+ configMap:
+ name: {{ include "apache.vhostsConfigMap" . }}
+ {{- end }}
+ {{- if or (.Files.Glob "files/httpd.conf") (.Values.httpdConfConfigMap) }}
+ - name: httpd-conf
+ configMap:
+ name: {{ include "apache.httpdConfConfigMap" . }}
+ {{- end }}
+ {{- if .Values.extraVolumes }}
+ {{- include "common.tplvalues.render" ( dict "value" .Values.extraVolumes "context" $) | nindent 8 }}
+ {{- end }}