diff --git a/postgresql/templates/bin/_readiness.sh.tpl b/postgresql/templates/bin/_readiness.sh.tpl new file mode 100644 index 0000000000..c8c6b269df --- /dev/null +++ b/postgresql/templates/bin/_readiness.sh.tpl @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +{{/* +Copyright 2017 The Openstack-Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/}} + +set -ex + +pg_isready -U ${POSTGRES_USER} diff --git a/postgresql/templates/bin/_start.sh.tpl b/postgresql/templates/bin/_start.sh.tpl new file mode 100644 index 0000000000..5419fe36fc --- /dev/null +++ b/postgresql/templates/bin/_start.sh.tpl @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +{{/* +Copyright 2017 The Openstack-Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/}} + +set -ex + +exec /docker-entrypoint.sh postgres diff --git a/postgresql/templates/configmap-bin.yaml b/postgresql/templates/configmap-bin.yaml new file mode 100644 index 0000000000..2501678a7b --- /dev/null +++ b/postgresql/templates/configmap-bin.yaml @@ -0,0 +1,30 @@ +{{/* +Copyright 2017 The Openstack-Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/}} + +{{- if .Values.manifests.configmap_bin }} +{{- $envAll := . }} +{{- $configMapBinName := printf "%s-%s" $envAll.Release.Name "etcd-bin" }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: postgresql-bin +data: + start.sh: | +{{ tuple "bin/_start.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }} + readiness.sh: | +{{ tuple "bin/_readiness.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }} +{{- end }} diff --git a/postgresql/templates/secret-admin.yaml b/postgresql/templates/secret-admin.yaml index 93903e3539..998cb384e5 100644 --- a/postgresql/templates/secret-admin.yaml +++ b/postgresql/templates/secret-admin.yaml @@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */}} + {{- if .Values.manifests.secret_admin }} --- apiVersion: v1 diff --git a/postgresql/templates/service.yaml b/postgresql/templates/service.yaml index 89f43dc7d2..7ad24b288f 100644 --- a/postgresql/templates/service.yaml +++ b/postgresql/templates/service.yaml @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */}} +{{- if .Values.manifests.service }} {{- $envAll := . }} --- apiVersion: v1 @@ -26,3 +27,4 @@ spec: port: {{ tuple "postgresql" "internal" "postgresql" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} selector: {{ tuple $envAll "postgresql" "server" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} +{{- end }} diff --git a/postgresql/templates/statefulset.yaml b/postgresql/templates/statefulset.yaml index 973428361a..c9b2e53e6d 100644 --- a/postgresql/templates/statefulset.yaml +++ b/postgresql/templates/statefulset.yaml @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */}} +{{- if .Values.manifests.statefulset }} {{- $envAll := . }} {{- $dependencies := .Values.dependencies.postgresql }} @@ -43,8 +44,9 @@ spec: - name: postgresql image: {{ .Values.images.tags.postgresql }} imagePullPolicy: {{ .Values.images.pull_policy }} +{{ tuple $envAll $envAll.Values.pod.resources.server | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }} ports: - - containerPort: {{ tuple "postgresql" "internal" "postgresql" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} + - containerPort: {{ tuple "postgresql" "internal" "postgresql" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} env: - name: 'POSTGRES_PASSWORD' valueFrom: @@ -58,41 +60,51 @@ spec: key: 'POSTGRES_USER' - name: 'PGDATA' value: {{ .Values.storage.mount.path | quote }} + command: + - /tmp/start.sh livenessProbe: exec: command: - - pg_isready - - -U - - {{ .Values.endpoints.postgresql.auth.admin.username }} + - /tmp/readiness.sh initialDelaySeconds: 20 timeoutSeconds: 5 readinessProbe: exec: command: - - pg_isready - - -U - - {{ .Values.endpoints.postgresql.auth.admin.username }} + - /tmp/readiness.sh initialDelaySeconds: 20 timeoutSeconds: 5 -{{ tuple $envAll $envAll.Values.pod.resources.server | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }} volumeMounts: - - name: postgresql-data - mountPath: {{ .Values.storage.mount.path }} - subPath: {{ .Values.storage.mount.subpath }} -{{- if not .Values.storage.pvc.enabled }} + - name: postgresql-bin + mountPath: /tmp/start.sh + subPath: start.sh + readOnly: true + - name: postgresql-bin + mountPath: /tmp/readiness.sh + subPath: readiness.sh + readOnly: true + - name: postgresql-data + mountPath: {{ .Values.storage.mount.path }} + subPath: {{ .Values.storage.mount.subpath }} volumes: - - name: postgresql-data - hostPath: - path: {{ .Values.storage.host.host_path }} + - name: postgresql-bin + configMap: + name: postgresql-bin + defaultMode: 0555 +{{- if not .Values.storage.pvc.enabled }} + - name: postgresql-data + hostPath: + path: {{ .Values.storage.host.host_path }} {{- else }} volumeClaimTemplates: - - metadata: - name: postgresql-data - annotations: - {{ .Values.storage.pvc.class_path }}: {{ .Values.storage.pvc.class_name }} - spec: - accessModes: [ "ReadWriteOnce" ] - resources: - requests: - storage: {{ .Values.storage.pvc.size }} + - metadata: + name: postgresql-data + annotations: + {{ .Values.storage.pvc.class_path }}: {{ .Values.storage.pvc.class_name }} + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: {{ .Values.storage.pvc.size }} +{{- end }} {{- end }} diff --git a/postgresql/values.yaml b/postgresql/values.yaml index 70671cd3e2..88ec5d643f 100644 --- a/postgresql/values.yaml +++ b/postgresql/values.yaml @@ -80,10 +80,13 @@ endpoints: host_fqdn_override: default: null path: null - scheme: 'http' + scheme: postgresql port: postgresql: default: 5432 manifests: + configmap_bin: true secret_admin: true + service: true + statefulset: true