From 0659e9d7c0a6b5ba73addb0ba7acd4da12504735 Mon Sep 17 00:00:00 2001 From: Marco Mancuso Date: Fri, 5 Jan 2018 09:15:05 +0000 Subject: [PATCH 1/2] Investigate and Update ACS initContainer to reliably wait for the db to be up --- .../templates/_helpers.tpl | 37 ++++++++++++++++++- .../templates/config-repository.yaml | 10 ++--- .../templates/deployment-repository.yaml | 4 +- helm/alfresco-content-services/values.yaml | 4 ++ 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/helm/alfresco-content-services/templates/_helpers.tpl b/helm/alfresco-content-services/templates/_helpers.tpl index a834dbe6a0..05a8699044 100644 --- a/helm/alfresco-content-services/templates/_helpers.tpl +++ b/helm/alfresco-content-services/templates/_helpers.tpl @@ -5,4 +5,39 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{- define "content-services.fullname" -}} {{- $name := default .Chart.Name .Values.nameOverride -}} {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} -{{- end -}} \ No newline at end of file +{{- end -}} + +{{- define "database.hostname" -}} +{{- $dbtype := ( .Values.database.type | toString ) -}} +{{- if eq $dbtype "postgresql" }} +{{- printf "%s-%s" .Release.Name .Values.postgresql.nameOverride | trim -}} +{{- end }} +{{- end -}} + +{{- define "database.port" -}} +{{- $dbtype := ( .Values.database.type | toString ) -}} +{{- if eq $dbtype "postgresql" }} +{{- print .Values.postgresql.service.port | trim -}} +{{- end }} +{{- end -}} + +{{- define "database.driver" -}} +{{- $dbtype := ( .Values.database.type | toString ) -}} +{{- if eq $dbtype "postgresql" }} +{{- print .Values.postgresql.driver | trim -}} +{{- end }} +{{- end -}} + +{{- define "database.user" -}} +{{- $dbtype := ( .Values.database.type | toString ) -}} +{{- if eq $dbtype "postgresql" }} +{{- print .Values.postgresql.postgresUser | trim -}} +{{- end }} +{{- end -}} + +{{- define "database.password" }} +{{- $dbtype := ( .Values.database.type | toString ) -}} +{{- if eq $dbtype "postgresql" -}} +{{- print .Values.postgresql.postgresPassword | trim -}} +{{- end }} +{{- end -}} diff --git a/helm/alfresco-content-services/templates/config-repository.yaml b/helm/alfresco-content-services/templates/config-repository.yaml index 77a5ca87b1..5f16955e51 100644 --- a/helm/alfresco-content-services/templates/config-repository.yaml +++ b/helm/alfresco-content-services/templates/config-repository.yaml @@ -17,9 +17,9 @@ data: -Dalfresco.port={{ .Values.repository.service.externalPort }} -Dshare.host={{ template "content-services.fullname" . }}-share -Dshare.port={{ .Values.share.service.externalPort }} - -Ddb.driver=org.postgresql.Driver - -Ddb.username={{ .Values.postgresql.postgresUser }} - -Ddb.password={{ .Values.postgresql.postgresPassword }} - -Ddb.url=jdbc:postgresql://{{ .Release.Name }}-postgresql-acs:5432/{{ .Values.postgresql.postgresDatabase }} + -Ddb.driver={{ template "database.driver" . }} + -Ddb.username={{ template "database.user" . }} + -Ddb.password={{ template "database.password" . }} + -Ddb.url=jdbc:{{ .Values.database.type }}://{{ template "database.hostname" . }}:{{ template "database.port" . }}/{{ .Values.postgresql.postgresDatabase }} -Dsolr.host={{ template "content-services.fullname" . }}-solr - -Dsolr.port={{ .Values.solr.service.externalPort }}" \ No newline at end of file + -Dsolr.port={{ .Values.solr.service.externalPort }}" diff --git a/helm/alfresco-content-services/templates/deployment-repository.yaml b/helm/alfresco-content-services/templates/deployment-repository.yaml index 2fd87a2a1a..84ecceb699 100644 --- a/helm/alfresco-content-services/templates/deployment-repository.yaml +++ b/helm/alfresco-content-services/templates/deployment-repository.yaml @@ -29,6 +29,6 @@ spec: resources: {{ toYaml .Values.repository.resources | indent 12 }} initContainers: - - name: init-postgres + - name: init-db image: busybox - command: ['sh', '-c', 'until nslookup {{ .Release.Name }}-postgresql-acs; do echo "waiting for postgres"; sleep 2; done;'] + command: ['sh', '-c', 'until nc -w1 {{ template "database.hostname" . }} {{ template "database.port" . }}; do echo "waiting for {{ .Values.database.type }}"; sleep 2; done;'] diff --git a/helm/alfresco-content-services/values.yaml b/helm/alfresco-content-services/values.yaml index 8637c91f8e..45a0d66753 100644 --- a/helm/alfresco-content-services/values.yaml +++ b/helm/alfresco-content-services/values.yaml @@ -82,5 +82,9 @@ postgresql: memory: "250Mi" limits: memory: "500Mi" + driver: org.postgresql.Driver + +database: + type: postgresql replicaCount: 1 From 3315755450176872702f21090cc78293751090e9 Mon Sep 17 00:00:00 2001 From: Marco Mancuso Date: Fri, 5 Jan 2018 09:53:54 +0000 Subject: [PATCH 2/2] adding comments per functions + cleaning --- .../templates/_helpers.tpl | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/helm/alfresco-content-services/templates/_helpers.tpl b/helm/alfresco-content-services/templates/_helpers.tpl index 05a8699044..272ae223bd 100644 --- a/helm/alfresco-content-services/templates/_helpers.tpl +++ b/helm/alfresco-content-services/templates/_helpers.tpl @@ -7,37 +7,47 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} {{- end -}} +{{/* +Get the Database hostname depending on the Database type +*/}} {{- define "database.hostname" -}} -{{- $dbtype := ( .Values.database.type | toString ) -}} -{{- if eq $dbtype "postgresql" }} -{{- printf "%s-%s" .Release.Name .Values.postgresql.nameOverride | trim -}} +{{- if eq ( .Values.database.type | toString ) "postgresql" }} +{{- printf "%s-%s" .Release.Name .Values.postgresql.nameOverride -}} {{- end }} {{- end -}} +{{/* +Get the Database port depending on the Database type +*/}} {{- define "database.port" -}} -{{- $dbtype := ( .Values.database.type | toString ) -}} -{{- if eq $dbtype "postgresql" }} -{{- print .Values.postgresql.service.port | trim -}} +{{- if eq ( .Values.database.type | toString ) "postgresql" }} +{{- print .Values.postgresql.service.port -}} {{- end }} {{- end -}} +{{/* +Create the Database driver depending on the Database type +*/}} {{- define "database.driver" -}} -{{- $dbtype := ( .Values.database.type | toString ) -}} -{{- if eq $dbtype "postgresql" }} -{{- print .Values.postgresql.driver | trim -}} +{{- if eq ( .Values.database.type | toString ) "postgresql" }} +{{- print .Values.postgresql.driver -}} {{- end }} {{- end -}} +{{/* +Get the Database user depending on the Database type +*/}} {{- define "database.user" -}} -{{- $dbtype := ( .Values.database.type | toString ) -}} -{{- if eq $dbtype "postgresql" }} -{{- print .Values.postgresql.postgresUser | trim -}} +{{- if eq ( .Values.database.type | toString ) "postgresql" }} +{{- print .Values.postgresql.postgresUser -}} {{- end }} {{- end -}} +{{/* +Get the Database password depending on the Database type +*/}} {{- define "database.password" }} -{{- $dbtype := ( .Values.database.type | toString ) -}} -{{- if eq $dbtype "postgresql" -}} -{{- print .Values.postgresql.postgresPassword | trim -}} +{{- if eq ( .Values.database.type | toString ) "postgresql" -}} +{{- print .Values.postgresql.postgresPassword -}} {{- end }} {{- end -}}