From 202190740e4936dde36c8941cd3193009f05a05a Mon Sep 17 00:00:00 2001 From: Alex Chapellon Date: Thu, 10 Aug 2023 18:06:20 +0200 Subject: [PATCH] OPSEXP-1862: align all non-secret config to using alfresco-common read.cm helpers (#96) --- charts/alfresco-repository/Chart.yaml | 2 +- charts/alfresco-repository/README.md | 2 +- .../templates/_helpers-message-broker.tpl | 13 +++++ .../templates/configmap-message-broker.yaml | 17 ------- .../templates/configmap.yaml | 6 ++- .../templates/deployment.yaml | 9 ---- .../tests/message-broker_test.yaml | 49 ++++++++++--------- 7 files changed, 46 insertions(+), 52 deletions(-) create mode 100644 charts/alfresco-repository/templates/_helpers-message-broker.tpl delete mode 100644 charts/alfresco-repository/templates/configmap-message-broker.yaml diff --git a/charts/alfresco-repository/Chart.yaml b/charts/alfresco-repository/Chart.yaml index e503dd08..1c4956a0 100644 --- a/charts/alfresco-repository/Chart.yaml +++ b/charts/alfresco-repository/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: alfresco-repository description: Alfresco content repository Helm chart type: application -version: 0.1.0-alpha.6 +version: 0.1.0-alpha.7 appVersion: 23.1.0-A21 dependencies: - name: alfresco-common diff --git a/charts/alfresco-repository/README.md b/charts/alfresco-repository/README.md index da844eb9..1791b17e 100644 --- a/charts/alfresco-repository/README.md +++ b/charts/alfresco-repository/README.md @@ -1,6 +1,6 @@ # alfresco-repository -![Version: 0.1.0-alpha.6](https://img.shields.io/badge/Version-0.1.0--alpha.6-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 23.1.0-A21](https://img.shields.io/badge/AppVersion-23.1.0--A21-informational?style=flat-square) +![Version: 0.1.0-alpha.7](https://img.shields.io/badge/Version-0.1.0--alpha.7-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 23.1.0-A21](https://img.shields.io/badge/AppVersion-23.1.0--A21-informational?style=flat-square) Alfresco content repository Helm chart diff --git a/charts/alfresco-repository/templates/_helpers-message-broker.tpl b/charts/alfresco-repository/templates/_helpers-message-broker.tpl new file mode 100644 index 00000000..41a72ce0 --- /dev/null +++ b/charts/alfresco-repository/templates/_helpers-message-broker.tpl @@ -0,0 +1,13 @@ +{{/* +Validate ActiveMQ is a failover transport URL + +Usage: include "alfresco-repository.mq.url.valid" "URL" + +*/}} +{{- define "alfresco-repository.mq.url.valid" -}} +{{- if hasPrefix "failover:(" . }} + {{- . }} +{{- else -}} + {{- printf "failover:(%s)" . }} +{{- end }} +{{- end -}} diff --git a/charts/alfresco-repository/templates/configmap-message-broker.yaml b/charts/alfresco-repository/templates/configmap-message-broker.yaml deleted file mode 100644 index 07eae7ec..00000000 --- a/charts/alfresco-repository/templates/configmap-message-broker.yaml +++ /dev/null @@ -1,17 +0,0 @@ -{{- if not .Values.configuration.messageBroker.existingConfigMap.name }} -apiVersion: v1 -kind: ConfigMap -metadata: - name: >- - {{- $mqconfigCtx := dict "Values" (dict "nameOverride" "configmap-mq") "Chart" .Chart "Release" .Release }} - {{ template "alfresco-repository.fullname" $mqconfigCtx }} - labels: - {{- include "alfresco-repository.labels" . | nindent 4 }} -data: - BROKER_URL: >- - {{- with .Values.configuration.messageBroker }} - {{- $reqmsg := "You must either provide a valid Message broker URL or use an existingConfigMap.name with that URL" }} - {{- $mqurl := required $reqmsg .url }} - {{- hasPrefix "failover:(" $mqurl | ternary $mqurl (printf "failover:(%s)" $mqurl) | nindent 4 }} - {{- end }} -{{- end }} diff --git a/charts/alfresco-repository/templates/configmap.yaml b/charts/alfresco-repository/templates/configmap.yaml index 96b772df..0260a3c3 100644 --- a/charts/alfresco-repository/templates/configmap.yaml +++ b/charts/alfresco-repository/templates/configmap.yaml @@ -10,7 +10,8 @@ data: CATALINA_OPTS: >- {{- with .Values.configuration }} -Ddeployment.method=HELM_CHART - -Ddb.url=jdbc:{{ .db.url }} + {{- $db_url := include "alfresco-common.read.cm.then.value" (dict "ns" $.Release.Namespace "key" "url" "context" .db) }} + -Ddb.url=jdbc:{{ $db_url }} -Ddb.username=${DATABASE_USERNAME} -Ddb.password=${DATABASE_PASSWORD} -Ddb.driver={{ include "alfresco-common.db.driver" .db }} @@ -22,7 +23,8 @@ data: -Dmetadata-keystore.metadata.algorithm=DESede -Dmetadata-keystore.password=mp6yc0UD9e -Dmetadata-keystore.metadata.password=oKIWzVdEdA - -Dmessaging.broker.url="$BROKER_URL" + {{- $mq_url := include "alfresco-common.reqRead.cm.then.value" (dict "ns" $.Release.Namespace "key" "url" "context" .messageBroker) }} + -Dmessaging.broker.url={{ include "alfresco-repository.mq.url.valid" $mq_url | quote }} -Dmessaging.broker.username="$BROKER_USERNAME" -Dmessaging.broker.password="$BROKER_PASSWORD" {{- $search_flavor := include "alfresco-common.read.cm.then.value" (dict "ns" $.Release.Namespace "key" "flavor" "context" .search) }} diff --git a/charts/alfresco-repository/templates/deployment.yaml b/charts/alfresco-repository/templates/deployment.yaml index e835e186..e771dd97 100644 --- a/charts/alfresco-repository/templates/deployment.yaml +++ b/charts/alfresco-repository/templates/deployment.yaml @@ -65,8 +65,6 @@ spec: {{- $dbsecret := "" }} {{- $mqsecretCtx := dict }} {{- $mqsecret := "" }} - {{- $mqconfigCtx := dict }} - {{- $mqconfig := "" }} {{- $searchsecretCtx := dict }} {{- $searchsecret := "" }} {{- with .Values.configuration }} @@ -74,8 +72,6 @@ spec: {{- $dbsecret = coalesce .db.existingSecret.name (include "alfresco-repository.fullname" $dbsecretCtx) }} {{- $mqsecretCtx = dict "Values" (dict "nameOverride" "secret-mq") "Chart" $.Chart "Release" $.Release }} {{- $mqsecret = coalesce .messageBroker.existingSecret.name (include "alfresco-repository.fullname" $mqsecretCtx) }} - {{- $mqconfigCtx = dict "Values" (dict "nameOverride" "configmap-mq") "Chart" $.Chart "Release" $.Release }} - {{- $mqconfig = coalesce .messageBroker.existingConfigMap.name (include "alfresco-repository.fullname" $mqconfigCtx) }} {{- $searchsecretCtx = dict "Values" (dict "nameOverride" "secret-search") "Chart" $.Chart "Release" $.Release }} {{- $searchsecret = coalesce .search.existingSecret.name (include "alfresco-repository.fullname" $searchsecretCtx) }} {{- end }} @@ -127,11 +123,6 @@ spec: name: {{ $mqsecret }} key: {{ .Values.configuration.messageBroker.existingSecret.keys.password }} optional: true - - name: BROKER_URL - valueFrom: - configMapKeyRef: - name: {{ $mqconfig }} - key: {{ .Values.configuration.messageBroker.existingConfigMap.keys.url }} {{- $optsCtx := dict "Values" (dict "nameOverride" "alfresco-opts") "Chart" .Chart "Release" .Release }} envFrom: - configMapRef: diff --git a/charts/alfresco-repository/tests/message-broker_test.yaml b/charts/alfresco-repository/tests/message-broker_test.yaml index bd464e71..6acb5e6a 100644 --- a/charts/alfresco-repository/tests/message-broker_test.yaml +++ b/charts/alfresco-repository/tests/message-broker_test.yaml @@ -3,25 +3,17 @@ suite: test Message Queue Broker templates: - secret-message-broker.yaml - deployment.yaml - - configmap-message-broker.yaml + - configmap.yaml values: - values/test_values.yaml tests: - it: should render ActiveMQ minimal config asserts: - - contains: - path: spec.template.spec.containers[0].env - content: - name: BROKER_URL - valueFrom: - configMapKeyRef: - name: RELEASE-NAME-configmap-mq - key: BROKER_URL - template: deployment.yaml - - equal: - path: data.BROKER_URL - value: failover:(tcp://localhost:61616) - template: configmap-message-broker.yaml + - matchRegex: + path: data.CATALINA_OPTS + pattern: |- + (^\s*|[^\s]\s+)-Dmessaging.broker.url="failover:\(tcp://localhost:61616\)"($|\s) + template: configmap.yaml - equal: path: spec.template.metadata.annotations['checksum.config.alfresco.org/messageBroker'] value: &cfgsum c2939932894f879e156e0ccaebb43552058663dbbedd75c74afd20a86662e054 @@ -36,20 +28,33 @@ tests: keys: username: mquser password: mqpass - existingConfigMap: - name: mqConfigmap - keys: - url: myurl + url: ssl://amqs:61617 asserts: - contains: path: spec.template.spec.containers[0].env content: - name: BROKER_URL + name: BROKER_USERNAME + valueFrom: + secretKeyRef: + name: mqSecret + key: mquser + optional: true + template: deployment.yaml + - contains: + path: spec.template.spec.containers[0].env + content: + name: BROKER_PASSWORD valueFrom: - configMapKeyRef: - name: mqConfigmap - key: myurl + secretKeyRef: + name: mqSecret + key: mqpass + optional: true template: deployment.yaml + - matchRegex: + path: data.CATALINA_OPTS + pattern: |- + (^\s*|[^\s]\s+)-Dmessaging.broker.url="failover:\(ssl://amqs:61617\)"($|\s) + template: configmap.yaml - hasDocuments: count: 0 template: secret-message-broker.yaml