diff --git a/charts/self-host/templates/post-install-db-migrator-job.yaml b/charts/self-host/templates/post-install-db-migrator-job.yaml index 6e25d8237..d8c74bbbf 100644 --- a/charts/self-host/templates/post-install-db-migrator-job.yaml +++ b/charts/self-host/templates/post-install-db-migrator-job.yaml @@ -140,7 +140,9 @@ spec: {{ toYaml . | indent 8 }} {{- end }} {{- if or ( not .Values.database.enabled ) ( and .Values.database.enabled .Release.IsUpgrade ) }} - args: [ "-f", "DbScripts_transition", "-r"] + args: [ "-f", "DbScripts_transition", "-r"{{ if .Values.jobs.db.migrationTimeoutSeconds }}, "-t", {{ .Values.jobs.db.migrationTimeoutSeconds | quote }}{{ end }}] + {{- else if .Values.jobs.db.migrationTimeoutSeconds }} + args: [ "-t", {{ .Values.jobs.db.migrationTimeoutSeconds | quote }}] {{- end }} restartPolicy: Never volumes: diff --git a/charts/self-host/templates/pre-install-db-migrator-job.yaml b/charts/self-host/templates/pre-install-db-migrator-job.yaml index 85078c615..b132ce62f 100644 --- a/charts/self-host/templates/pre-install-db-migrator-job.yaml +++ b/charts/self-host/templates/pre-install-db-migrator-job.yaml @@ -101,6 +101,9 @@ spec: {{- with .Values.jobs.extraVolumeMounts }} {{ toYaml . | indent 8 }} {{- end }} + {{- if .Values.jobs.db.migrationTimeoutSeconds }} + args: [ "-t", {{ .Values.jobs.db.migrationTimeoutSeconds | quote }}] + {{- end }} restartPolicy: Never volumes: - name: migrator-extract-dir diff --git a/charts/self-host/templates/pre-install-hook-configmap.yaml b/charts/self-host/templates/pre-install-hook-configmap.yaml index 7d30e2140..a349c14e2 100644 --- a/charts/self-host/templates/pre-install-hook-configmap.yaml +++ b/charts/self-host/templates/pre-install-hook-configmap.yaml @@ -74,6 +74,9 @@ data: {{- end }} {{- if .Values.general.knownNetworks }} globalSettings__knownNetworks: {{ .Values.general.knownNetworks | quote }} +{{- end }} +{{- if .Values.jobs.db.migrationTimeoutSeconds }} + globalSettings__sqlServer__migrationExecutionTimeoutSeconds: {{ .Values.jobs.db.migrationTimeoutSeconds | quote }} {{- end }} adminSettings__admins: {{ .Values.general.admins | quote }} LOCAL_UID: "1000" diff --git a/charts/self-host/tests/configmap_test.yaml b/charts/self-host/tests/configmap_test.yaml index e3fe204a7..3ac264017 100644 --- a/charts/self-host/tests/configmap_test.yaml +++ b/charts/self-host/tests/configmap_test.yaml @@ -62,3 +62,14 @@ tests: - isNull: path: data.globalSettings__IdentityServer__AbsoluteRefreshTokenLifetimeSeconds documentIndex: 0 + + - it: should include the migration timeout when migrationTimeoutSeconds is set + template: templates/pre-install-hook-configmap.yaml + set: + general.domain: "example.com" + jobs.db.migrationTimeoutSeconds: "900" + asserts: + - equal: + path: data.globalSettings__sqlServer__migrationExecutionTimeoutSeconds + value: "900" + documentIndex: 0 diff --git a/charts/self-host/tests/post_install_db_migrator_test.yaml b/charts/self-host/tests/post_install_db_migrator_test.yaml index fd48fdcb3..fbce13afa 100644 --- a/charts/self-host/tests/post_install_db_migrator_test.yaml +++ b/charts/self-host/tests/post_install_db_migrator_test.yaml @@ -105,3 +105,31 @@ tests: asserts: - hasDocuments: count: 0 + + - it: should append the timeout to the transition args when migrationTimeoutSeconds is set + template: templates/post-install-db-migrator-job.yaml + set: + database.enabled: false + jobs.db.migrationTimeoutSeconds: "900" + asserts: + - equal: + path: spec.template.spec.containers[0].args + value: ["-f", "DbScripts_transition", "-r", "-t", "900"] + + - it: should pass only the timeout when transition args are not rendered + template: templates/post-install-db-migrator-job.yaml + set: + database.enabled: true + jobs.db.migrationTimeoutSeconds: "900" + asserts: + - equal: + path: spec.template.spec.containers[0].args + value: ["-t", "900"] + + - it: should not set args when database is enabled and no timeout is set + template: templates/post-install-db-migrator-job.yaml + set: + database.enabled: true + asserts: + - isNull: + path: spec.template.spec.containers[0].args diff --git a/charts/self-host/tests/pre_install_db_migrator_test.yaml b/charts/self-host/tests/pre_install_db_migrator_test.yaml new file mode 100644 index 000000000..f4052c85c --- /dev/null +++ b/charts/self-host/tests/pre_install_db_migrator_test.yaml @@ -0,0 +1,55 @@ +suite: test pre-install db migrator job +templates: + - templates/helpers.tpl + - templates/pre-install-db-migrator-job.yaml +tests: + - it: should pass the timeout when migrationTimeoutSeconds is set + template: templates/pre-install-db-migrator-job.yaml + set: + jobs.db.migrationTimeoutSeconds: "900" + asserts: + - isKind: + of: Job + - equal: + path: metadata.annotations["helm.sh/hook"] + value: pre-upgrade + - equal: + path: spec.template.spec.containers[0].args + value: ["-t", "900"] + + - it: should pass the timeout when database is disabled + template: templates/pre-install-db-migrator-job.yaml + set: + database.enabled: false + jobs.db.migrationTimeoutSeconds: "900" + asserts: + - equal: + path: metadata.annotations["helm.sh/hook"] + value: pre-install,pre-upgrade + - equal: + path: spec.template.spec.containers[0].args + value: ["-t", "900"] + + - it: should pass the timeout when migrationTimeoutSeconds is "0" for unlimited + template: templates/pre-install-db-migrator-job.yaml + set: + jobs.db.migrationTimeoutSeconds: "0" + asserts: + - equal: + path: spec.template.spec.containers[0].args + value: ["-t", "0"] + + - it: should not set args when no timeout is set + template: templates/pre-install-db-migrator-job.yaml + asserts: + - isNull: + path: spec.template.spec.containers[0].args + + - it: should not render job when databaseProvider is postgres + template: templates/pre-install-db-migrator-job.yaml + set: + general.databaseProvider: postgres + jobs.db.migrationTimeoutSeconds: "900" + asserts: + - hasDocuments: + count: 0 diff --git a/charts/self-host/values.schema.json b/charts/self-host/values.schema.json index 40d6b468d..9a9802fe3 100644 --- a/charts/self-host/values.schema.json +++ b/charts/self-host/values.schema.json @@ -3381,6 +3381,12 @@ }, "db": { "properties": { + "migrationTimeoutSeconds": { + "default": "", + "description": "Timeout seconds for MSSQL migrations.\nDefault: 5 minutes\nA value of \"0\" can be used for unlimited timeout, useful for large databases", + "title": "migrationTimeoutSeconds", + "type": "string" + }, "postInstallMigrator": { "properties": { "annotations": { diff --git a/charts/self-host/values.yaml b/charts/self-host/values.yaml index 818bbbf1f..46c357d15 100644 --- a/charts/self-host/values.yaml +++ b/charts/self-host/values.yaml @@ -893,6 +893,10 @@ jobs: extraVolumes: [] db: + # Timeout seconds for MSSQL migrations. + # Default: 5 minutes + # A value of "0" can be used for unlimited timeout, useful for large databases + migrationTimeoutSeconds: "" preInstallMigrator: # Additional job labels labels: {}