From 956daafe7a6f899752702a4bdb7bfcf3218c99b6 Mon Sep 17 00:00:00 2001 From: Giovanni Toraldo <71768+gionn@users.noreply.github.com> Date: Fri, 27 Sep 2024 12:25:40 +0200 Subject: [PATCH] OPSEXP-2654 Reindex job as configurable helm hook (#376) --- charts/alfresco-search-enterprise/Chart.yaml | 2 +- charts/alfresco-search-enterprise/README.md | 4 ++- .../ci/default-values.yaml | 4 ++- .../templates/reindexing-job.yaml | 7 +++- .../tests/reindexing-job_test.yaml | 34 +++++++++++++++++++ charts/alfresco-search-enterprise/values.yaml | 5 +++ 6 files changed, 52 insertions(+), 4 deletions(-) diff --git a/charts/alfresco-search-enterprise/Chart.yaml b/charts/alfresco-search-enterprise/Chart.yaml index 399e3b42..b5f02ea1 100644 --- a/charts/alfresco-search-enterprise/Chart.yaml +++ b/charts/alfresco-search-enterprise/Chart.yaml @@ -3,7 +3,7 @@ apiVersion: v2 name: alfresco-search-enterprise description: A Helm chart for deploying Alfresco Elasticsearch connector type: application -version: 4.1.0 +version: 4.2.0-alpha.0 appVersion: 4.1.0 dependencies: - name: alfresco-common diff --git a/charts/alfresco-search-enterprise/README.md b/charts/alfresco-search-enterprise/README.md index 06fce94e..64d77ef9 100644 --- a/charts/alfresco-search-enterprise/README.md +++ b/charts/alfresco-search-enterprise/README.md @@ -5,7 +5,7 @@ parent: Charts Reference # alfresco-search-enterprise -![Version: 4.1.0](https://img.shields.io/badge/Version-4.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 4.1.0](https://img.shields.io/badge/AppVersion-4.1.0-informational?style=flat-square) +![Version: 4.2.0-alpha.0](https://img.shields.io/badge/Version-4.2.0--alpha.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 4.1.0](https://img.shields.io/badge/AppVersion-4.1.0-informational?style=flat-square) A Helm chart for deploying Alfresco Elasticsearch connector @@ -81,6 +81,7 @@ Checkout [alfresco-content-services chart's doc](https://github.com/Alfresco/acs | reindexing.db.username | string | `nil` | The username required to access the service | | reindexing.enabled | bool | `true` | Create the one-shot job to trigger the reindexing of repo contents | | reindexing.environment | object | `{}` | | +| reindexing.hookExecution | string | `"post-install"` | When to execute the reindexing job (e.g. `post-install` or `post-upgrade` or set to false to apply as a standard resource) | | reindexing.image.pullPolicy | string | `"IfNotPresent"` | | | reindexing.image.repository | string | `"quay.io/alfresco/alfresco-elasticsearch-reindexing"` | | | reindexing.image.tag | string | `"4.1.0"` | | @@ -94,6 +95,7 @@ Checkout [alfresco-content-services chart's doc](https://github.com/Alfresco/acs | reindexing.resources.limits.memory | string | `"512Mi"` | | | reindexing.resources.requests.cpu | string | `"0.5"` | | | reindexing.resources.requests.memory | string | `"128Mi"` | | +| reindexing.ttlSecondsAfterFinished | int | `3600` | Time to live for the job after it has finished to run | | resources.limits.cpu | string | `"2"` | | | resources.limits.memory | string | `"2048Mi"` | | | resources.requests.cpu | string | `"0.5"` | | diff --git a/charts/alfresco-search-enterprise/ci/default-values.yaml b/charts/alfresco-search-enterprise/ci/default-values.yaml index bf5b4045..e790586c 100644 --- a/charts/alfresco-search-enterprise/ci/default-values.yaml +++ b/charts/alfresco-search-enterprise/ci/default-values.yaml @@ -1,8 +1,10 @@ # avoid too long resource names being truncated and conflicting nameOverride: aesc reindexing: - # requires postgres database at startup + # A database is required for reindexing, but Helm does not wait for the job to complete during installation. enabled: true + # Allows tests to pass, otherwise when reindexing job is run as hook, installation will fail. + hookExecution: false repository: url: http://repository db: diff --git a/charts/alfresco-search-enterprise/templates/reindexing-job.yaml b/charts/alfresco-search-enterprise/templates/reindexing-job.yaml index 2121f3db..0fde6b76 100644 --- a/charts/alfresco-search-enterprise/templates/reindexing-job.yaml +++ b/charts/alfresco-search-enterprise/templates/reindexing-job.yaml @@ -2,10 +2,15 @@ apiVersion: batch/v1 kind: Job metadata: - name: {{ include "alfresco-search-enterprise.fullname" . }}-reindexing + name: {{ include "alfresco-search-enterprise.fullname" . }}-reindexing{{ if eq (.Values.reindexing.hookExecution | default "") "post-upgrade" }}-{{ randAlphaNum 5 | lower }}{{ end }} labels: {{- include "alfresco-search-enterprise.labels" $ | nindent 4 }} + annotations: + {{- with .Values.reindexing.hookExecution }} + "helm.sh/hook": {{ . | quote }} + {{- end }} spec: + ttlSecondsAfterFinished: {{ .Values.reindexing.ttlSecondsAfterFinished }} template: metadata: {{- with .Values.podAnnotations }} diff --git a/charts/alfresco-search-enterprise/tests/reindexing-job_test.yaml b/charts/alfresco-search-enterprise/tests/reindexing-job_test.yaml index 6de4bb0f..00397284 100644 --- a/charts/alfresco-search-enterprise/tests/reindexing-job_test.yaml +++ b/charts/alfresco-search-enterprise/tests/reindexing-job_test.yaml @@ -157,3 +157,37 @@ tests: configMapKeyRef: name: mycm key: REPO_URL + + - it: has default hook annotation + asserts: + - equal: + path: metadata.annotations + value: + "helm.sh/hook": "post-install" + - equal: + path: metadata.name + value: RELEASE-NAME-alfresco-search-enterprise-reindexing + + - it: has changed hook annotation + set: + reindexing: + hookExecution: post-upgrade + asserts: + - equal: + path: metadata.annotations + value: + "helm.sh/hook": "post-upgrade" + - matchRegex: + path: metadata.name + pattern: RELEASE-NAME-alfresco-search-enterprise-reindexing-[a-z0-9]{5} + + - it: has no hook annotation when disabled + set: + reindexing: + hookExecution: false + asserts: + - notExists: + path: metadata.annotations."helm.sh/hook" + - equal: + path: metadata.name + value: RELEASE-NAME-alfresco-search-enterprise-reindexing diff --git a/charts/alfresco-search-enterprise/values.yaml b/charts/alfresco-search-enterprise/values.yaml index c6de849a..39e058e8 100644 --- a/charts/alfresco-search-enterprise/values.yaml +++ b/charts/alfresco-search-enterprise/values.yaml @@ -187,6 +187,11 @@ reindexing: pullPolicy: IfNotPresent pathIndexingEnabled: true environment: {} + # -- When to execute the reindexing job (e.g. `post-install` or `post-upgrade` + # or set to false to apply as a standard resource) + hookExecution: post-install + # -- Time to live for the job after it has finished to run + ttlSecondsAfterFinished: 3600 repository: # -- URL of the Alfresco repository url: null