From f145210c0d92048952625a635f5bd72adac23a62 Mon Sep 17 00:00:00 2001 From: Giovanni Toraldo Date: Thu, 11 Jan 2024 16:01:39 +0100 Subject: [PATCH] evaluates existing configmap for securecomms value --- .../templates/_helpers-misc.tpl | 10 ++++++++++ charts/alfresco-search-service/templates/config.yaml | 9 +++------ .../templates/deployment.yaml | 12 ++++++------ .../templates/secret-repository.yaml | 4 ++-- .../alfresco-search-service/tests/config_test.yaml | 3 ++- .../tests/values/test_values.yaml | 2 ++ charts/alfresco-search-service/values.yaml | 8 +++++--- 7 files changed, 30 insertions(+), 18 deletions(-) diff --git a/charts/alfresco-search-service/templates/_helpers-misc.tpl b/charts/alfresco-search-service/templates/_helpers-misc.tpl index 174b212a..3a3de0b2 100644 --- a/charts/alfresco-search-service/templates/_helpers-misc.tpl +++ b/charts/alfresco-search-service/templates/_helpers-misc.tpl @@ -42,3 +42,13 @@ Get Alfresco Search Docker Image {{- printf "%s:%s" .Values.searchServicesImage.repository .Values.searchServicesImage.tag }} {{- end }} {{- end -}} + + +{{- define "alfresco-search.securecomms" -}} +{{- if .Values.repository.existingConfigMap.name }} +{{- $cm := lookup "v1" "ConfigMap" .Release.Namespace (.Values.repository.existingConfigMap.name) }} +{{- index $cm "data" .Values.repository.existingConfigMap.keys.securecomms | default .Values.repository.securecomms }} +{{- else }} +{{- .Values.repository.securecomms }} +{{- end }} +{{- end -}} diff --git a/charts/alfresco-search-service/templates/config.yaml b/charts/alfresco-search-service/templates/config.yaml index 92fc5716..0150dce8 100644 --- a/charts/alfresco-search-service/templates/config.yaml +++ b/charts/alfresco-search-service/templates/config.yaml @@ -7,11 +7,8 @@ metadata: {{- include "alfresco-search-service.labels" . | nindent 4 }} data: {{- with .Values.repository }} - SOLR_ALFRESCO_HOST: >- - {{ template "alfresco-common.url.host" .url }} - SOLR_ALFRESCO_PORT: >- - {{ template "alfresco-common.url.port" .url }} + {{ .existingConfigMap.keys.host }}: {{ .host | quote }} + {{ .existingConfigMap.keys.port }}: {{ .port | quote }} + {{ .existingConfigMap.keys.securecomms }}: {{ .securecomms | quote }} {{- end }} - SOLR_ALFRESCO_SECURE_COMMS: >- - {{ .Values.repository.securecomms }} {{- end }} diff --git a/charts/alfresco-search-service/templates/deployment.yaml b/charts/alfresco-search-service/templates/deployment.yaml index a70a35b4..d121103a 100644 --- a/charts/alfresco-search-service/templates/deployment.yaml +++ b/charts/alfresco-search-service/templates/deployment.yaml @@ -35,27 +35,27 @@ spec: {{- include "alfresco-common.component-security-context" .Values | indent 8 }} env: {{- with .Values.repository }} - {{- if eq .securecomms "secret" }} + {{- if (eq (include "alfresco-search.securecomms" $) "secret") }} - name: SOLR_ALFRESCO_SECURECOMMS_SECRET valueFrom: secretKeyRef: - name: {{ template "alfresco-search-service.repository-config.name" $ }} - key: {{ index .existingSecret.keys "sharedSecret" }} + name: {{ .existingSecret.name | default (include "alfresco-search-service.repository-config.name" $) }} + key: {{ .existingSecret.keys.sharedSecret }} {{- end }} - name: SOLR_ALFRESCO_HOST valueFrom: configMapKeyRef: - name: {{ template "alfresco-search-service.repository-config.name" $ }} + name: {{ .existingConfigMap.name | default (include "alfresco-search-service.repository-config.name" $) }} key: {{ .existingConfigMap.keys.host }} - name: SOLR_ALFRESCO_PORT valueFrom: configMapKeyRef: - name: {{ template "alfresco-search-service.repository-config.name" $ }} + name: {{ .existingConfigMap.name | default (include "alfresco-search-service.repository-config.name" $) }} key: {{ .existingConfigMap.keys.port }} - name: SOLR_ALFRESCO_SECURECOMMS valueFrom: configMapKeyRef: - name: {{ template "alfresco-search-service.repository-config.name" $ }} + name: {{ .existingConfigMap.name | default (include "alfresco-search-service.repository-config.name" $) }} key: {{ .existingConfigMap.keys.securecomms }} {{- end }} - name: SOLR_SOLR_HOST diff --git a/charts/alfresco-search-service/templates/secret-repository.yaml b/charts/alfresco-search-service/templates/secret-repository.yaml index 8dd85f66..aafca7e6 100644 --- a/charts/alfresco-search-service/templates/secret-repository.yaml +++ b/charts/alfresco-search-service/templates/secret-repository.yaml @@ -1,4 +1,4 @@ -{{- if and (not .Values.repository.existingSecret.name) (eq "secret" .Values.repository.securecomms) }} +{{- if and (not .Values.repository.existingSecret.name) (eq "secret" (include "alfresco-search.securecomms" $)) }} apiVersion: v1 kind: Secret metadata: @@ -8,6 +8,6 @@ metadata: type: Opaque data: {{- $reqmsg := "Please provide a shared secret for solr and repository in value repository.sharedSecret" }} - {{- $shared_secret := required $reqmsg (index .Values.repository "sharedSecret") }} + {{- $shared_secret := required $reqmsg .Values.repository.sharedSecret }} SOLR_ALFRESCO_SECURECOMMS_SECRET: {{ $shared_secret | b64enc | quote }} {{- end }} diff --git a/charts/alfresco-search-service/tests/config_test.yaml b/charts/alfresco-search-service/tests/config_test.yaml index 4195581e..792b4899 100644 --- a/charts/alfresco-search-service/tests/config_test.yaml +++ b/charts/alfresco-search-service/tests/config_test.yaml @@ -21,7 +21,8 @@ tests: values: *testvalues set: repository: - url: http://somehost:8888 + host: somehost + port: 8888 asserts: - equal: path: data.SOLR_ALFRESCO_HOST diff --git a/charts/alfresco-search-service/tests/values/test_values.yaml b/charts/alfresco-search-service/tests/values/test_values.yaml index 0c2fdbd7..d6d06c4e 100644 --- a/charts/alfresco-search-service/tests/values/test_values.yaml +++ b/charts/alfresco-search-service/tests/values/test_values.yaml @@ -1,3 +1,5 @@ --- repository: + host: alfresco-search-service + port: 80 sharedSecret: dummy diff --git a/charts/alfresco-search-service/values.yaml b/charts/alfresco-search-service/values.yaml index 59c973a5..1269ff02 100644 --- a/charts/alfresco-search-service/values.yaml +++ b/charts/alfresco-search-service/values.yaml @@ -59,9 +59,11 @@ ingress: nginx.ingress.kubernetes.io/whitelist-source-range: 0.0.0.0/0 # Below values must be set by parent chart repository: - # -- Alfresco repository URL - url: http://alfresco-search-service - # -- repository security level to use when tracking the repo ('none' or 'secret') + # -- Alfresco repository hostname + host: null + # -- Alfresco repository port + port: null + # -- Alfresco repository security level to use when tracking the repo ('none' or 'secret') securecomms: secret # -- Shared secret used with repository when `securecomms` is `secret` sharedSecret: null