From 58a796ab6ffd067d1fd77f47f860482fa89c1c78 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Wed, 3 Feb 2021 22:13:33 +0500 Subject: [PATCH] Update nextcloud chart migrating it to newer storage format --- test/nextcloud/1.1.0/migrations/migrate | 23 +++ test/nextcloud/1.1.0/questions.yaml | 165 ++++++++++-------- test/nextcloud/1.1.0/templates/_backup.tpl | 0 test/nextcloud/1.1.0/templates/_helpers.tpl | 114 ------------ test/nextcloud/1.1.0/templates/_postgres.tpl | 14 +- test/nextcloud/1.1.0/templates/_upgrade.tpl | 21 --- .../1.1.0/templates/backup-postgres-hook.yaml | 10 +- .../nextcloud/1.1.0/templates/deployment.yaml | 24 +-- .../1.1.0/templates/postgres-deployment.yaml | 24 +-- 9 files changed, 134 insertions(+), 261 deletions(-) create mode 100755 test/nextcloud/1.1.0/migrations/migrate delete mode 100644 test/nextcloud/1.1.0/templates/_backup.tpl delete mode 100644 test/nextcloud/1.1.0/templates/_helpers.tpl delete mode 100644 test/nextcloud/1.1.0/templates/_upgrade.tpl diff --git a/test/nextcloud/1.1.0/migrations/migrate b/test/nextcloud/1.1.0/migrations/migrate new file mode 100755 index 0000000000..be01e7a9f2 --- /dev/null +++ b/test/nextcloud/1.1.0/migrations/migrate @@ -0,0 +1,23 @@ +#!/usr/bin/python3 +import json +import sys + + +def migrate(values): + values.update({ + 'appVolumeMounts': { + 'nextcloud-data': { + 'hostPathEnabled': values['nextcloudDataHostPathEnabled'], + **({'hostPath': values['nextcloudHostPath']} if values.get('nextcloudHostPath') else {}) + }, + }, + 'updateStrategy': values.get('nextcloud').get('strategy', 'Recreate'), + }) + return values + + +if __name__ == '__main__': + if len(sys.argv) != 2: + exit(1) + + print(json.dumps(migrate(json.loads(sys.argv[1])))) diff --git a/test/nextcloud/1.1.0/questions.yaml b/test/nextcloud/1.1.0/questions.yaml index 545fe5647b..bea8812ed5 100644 --- a/test/nextcloud/1.1.0/questions.yaml +++ b/test/nextcloud/1.1.0/questions.yaml @@ -9,6 +9,8 @@ groups: description: "Configure nextcloud container parameters" - name: "Postgresql Configuration" description: "Configure Postgresql for nextcloud" + - name: "Scaling/Upgrade Policy" + description: "Configure how pods are replaced when configuration is upgraded" portals: web_portal: @@ -94,16 +96,20 @@ questions: type: path default: "/var/www/html/data" required: true - - variable: strategy - label: "Nextcloud update strategy" - schema: - type: string - default: "Recreate" - enum: - - value: "RollingUpdate" - description: "Create new pods and then kill old ones" - - value: "Recreate" - description: "Kill existing pods before creating new ones" + + # Update strategy + - variable: updateStrategy + description: "Upgrade Policy" + label: "Update Strategy" + group: "Scaling/Upgrade Policy" + schema: + type: string + default: "Recreate" + enum: + - value: "RollingUpdate" + description: "Create new pods and then kill old ones" + - value: "Recreate" + description: "Kill existing pods before creating new ones" - variable: service description: "Nextcloud Service Configuration" @@ -122,80 +128,89 @@ questions: default: 9001 required: true - - variable: nextcloudDataHostPathEnabled - label: "Configure Host Path for Nextcloud data" - group: "Storage" - schema: - type: boolean - default: false - show_subquestions_if: true - subquestions: - - variable: nextcloudHostPath - label: "Specify HostPath for Nextcloud data" - schema: - type: hostpath - - - variable: nextcloudDataVolume - label: "Nextcloud Data Volume Defaults" + - variable: appVolumeMounts + label: "Nextcloud Storage" group: "Storage" schema: type: dict - $ref: - - "normalize/ixVolume" - show_if: [["nextcloudDataHostPathEnabled", "=", false]] attrs: - - variable: mountPath - label: "Nextcloud Data Mount Path" - description: "Path where the volume will be mounted inside the pod" + - variable: nextcloud-data + label: "Nextcloud Data Volume" schema: - type: path - editable: false - default: "/var/www" - - variable: datasetName - label: "Nextcloud Dataset Name" - schema: - type: string - default: "ix-nextcloud_data" - editable: false + type: dict + attrs: + - variable: datasetName + label: "Nextcloud Data Volume Name" + schema: + type: string + $ref: + - "normalize/ixVolume" + show_if: [["hostPathEnabled", "=", false]] + default: "ix-nextcloud_data" + editable: false + - variable: mountPath + label: "Nextcloud Data Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + editable: false + default: "/var/www" + - variable: hostPathEnabled + label: "Enable Host Path for Nextcloud Data Volume" + schema: + type: boolean + default: false + show_subquestions_if: true + subquestions: + - variable: hostPath + label: "Host Path for Nextcloud Data Volume" + schema: + type: hostpath + required: true - - variable: postgresBackupVolume - label: "Postgres Backup Volume Defaults" + - variable: postgresAppVolumeMounts + label: "Postgres Storage" group: "Storage" schema: type: dict - $ref: - - "normalize/ixVolume" attrs: - - variable: mountPath - label: "Postgres Backup Mount Path" + - variable: postgres-data + label: "Postgres Data Volume" schema: - type: path - editable: false - default: "/postgres_backups" - - variable: datasetName - label: "Postgres Backup Dataset Name" + type: dict + attrs: + - variable: datasetName + label: "Postgres Data Volume Name" + schema: + type: string + $ref: + - "normalize/ixVolume" + default: "ix-postgres_data" + editable: false + - variable: mountPath + label: "Postgresql Data Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + editable: false + default: "/var/lib/postgresql/data" + - variable: postgres-backup + label: "Postgres Backup Volume" schema: - type: string - default: "ix-postgres_backups" - editable: false - - - variable: postgresDataVolume - label: "Postgresql Data Volume Defaults" - group: "Storage" - schema: - type: dict - $ref: - - "normalize/ixVolume" - attrs: - - variable: mountPath - label: "Postgres Mount Path" - schema: - type: path - editable: false - default: "/var/lib/postgresql/data" - - variable: datasetName - label: "Postgres Dataset Name" - schema: - type: string - default: "ix-postgres_data" - editable: false + type: dict + attrs: + - variable: datasetName + label: "Postgres Backup Volume Name" + schema: + type: string + $ref: + - "normalize/ixVolume" + default: "ix-postgres_backups" + editable: false + - variable: mountPath + label: "Postgresql Backup Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + editable: false + default: "/postgres_backups" diff --git a/test/nextcloud/1.1.0/templates/_backup.tpl b/test/nextcloud/1.1.0/templates/_backup.tpl deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/nextcloud/1.1.0/templates/_helpers.tpl b/test/nextcloud/1.1.0/templates/_helpers.tpl deleted file mode 100644 index 43114be492..0000000000 --- a/test/nextcloud/1.1.0/templates/_helpers.tpl +++ /dev/null @@ -1,114 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "nextcloud.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -If release name contains chart name it will be used as a full name. -*/}} -{{- define "nextcloud.fullname" -}} -{{- if .Values.fullnameOverride -}} -{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} -{{- else -}} -{{- $name := default .Chart.Name .Values.nameOverride -}} -{{- if contains $name .Release.Name -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "nextcloud.mariadb.fullname" -}} -{{- printf "%s-%s" .Release.Name "mariadb" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - - -{{/* -Create a default fully qualified redis app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "nextcloud.redis.fullname" -}} -{{- printf "%s-%s" .Release.Name "redis" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "nextcloud.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Retrieve host path from ix volumes based on dataset name -*/}} -{{- define "retrieveHostPathFromiXVolume" -}} -{{- range $index, $hostPathConfiguration := $.ixVolumes }} -{{- $dsName := base $hostPathConfiguration.hostPath -}} -{{- if eq $.datasetName $dsName -}} -{{- $hostPathConfiguration.hostPath -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Retrieve host path defined in volume -*/}} -{{- define "configuredHostPath" -}} -{{- if .Values.emptyDirVolumes -}} -{{- printf "" -}} -{{- else if .Values.nextcloudDataHostPathEnabled -}} -{{- required "Please specify a host path for nextcloud" .Values.nextcloudHostPath -}} -{{- else -}} -{{- $volDict := dict "datasetName" $.Values.nextcloudDataVolume.datasetName "ixVolumes" $.Values.ixVolumes -}} -{{- include "retrieveHostPathFromiXVolume" $volDict -}} -{{- end -}} -{{- end -}} - -{{/* -Retrieve backup postgresql host path defined in volume -*/}} -{{- define "configuredBackupPostgresHostPath" -}} -{{- if .Values.emptyDirVolumes -}} -{{- printf "" -}} -{{- else -}} -{{- $volDict := dict "datasetName" $.Values.postgresBackupVolume.datasetName "ixVolumes" $.Values.ixVolumes -}} -{{- include "retrieveHostPathFromiXVolume" $volDict -}} -{{- end -}} -{{- end -}} - -{{/* -Retrieve postgresql data host path defined in volume -*/}} -{{- define "configuredPostgresHostPath" -}} -{{- if .Values.emptyDirVolumes -}} -{{- printf "" -}} -{{- else -}} -{{- $volDict := dict "datasetName" $.Values.postgresDataVolume.datasetName "ixVolumes" $.Values.ixVolumes -}} -{{- include "retrieveHostPathFromiXVolume" $volDict -}} -{{- end -}} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "nextcloud.selectorLabels" -}} -app.kubernetes.io/name: {{ include "nextcloud.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end }} - -{{/* -Nextcloud service account -*/}} -{{- define "nextcloud.serviceAccountName" -}} -{{- printf "%s-service-account" .Release.Name -}} -{{- end -}} diff --git a/test/nextcloud/1.1.0/templates/_postgres.tpl b/test/nextcloud/1.1.0/templates/_postgres.tpl index e9244da240..0cdfc8b015 100644 --- a/test/nextcloud/1.1.0/templates/_postgres.tpl +++ b/test/nextcloud/1.1.0/templates/_postgres.tpl @@ -36,8 +36,14 @@ Retrieve postgres credentials for environment variables configuration Retrieve postgres volume configuration */}} {{- define "postgres.volumeConfiguration" -}} -{{ $vols := list }} -{{ $vols = mustAppend $vols (dict "name" "postgres-data" "emptyDirVolumes" .Values.emptyDirVolumes "hostPathEnabled" false "pathField" nil "datasetName" (.Values.postgresDataVolume | default dict).datasetName ) }} -{{ $vols = mustAppend $vols (dict "name" "postgres-backup" "emptyDirVolumes" .Values.emptyDirVolumes "hostPathEnabled" false "pathField" nil "datasetName" (.Values.postgresBackupVolume | default dict).datasetName ) }} -{{ include "common.storage.volumesConfiguration" (dict "ixVolumes" .Values.ixVolumes "volumes" $vols) }} +{{ include "common.storage.configureAppVolumes" (dict "appVolumeMounts" .Values.postgresAppVolumeMounts "emptyDirVolumes" .Values.emptyDirVolumes "ixVolumes" .Values.ixVolumes) | nindent 0 }} {{- end -}} + + +{{/* +Retrieve postgres volume mounts configuration +*/}} +{{- define "postgres.volumeMountsConfiguration" -}} +{{ include "common.storage.configureAppVolumeMountsInContainer" (dict "appVolumeMounts" .Values.postgresAppVolumeMounts ) | nindent 0 }} +{{- end -}} + diff --git a/test/nextcloud/1.1.0/templates/_upgrade.tpl b/test/nextcloud/1.1.0/templates/_upgrade.tpl deleted file mode 100644 index eb0ae1e660..0000000000 --- a/test/nextcloud/1.1.0/templates/_upgrade.tpl +++ /dev/null @@ -1,21 +0,0 @@ -{{/* -Retrieve previous chart version from which we are upgrading to a newer chart version -*/}} -{{- define "tn.chart.old_version" -}} -{{- if .Values.ixChartContext.is_upgrade -}} -{{- .Values.ixChartContext.upgradeMetadata.oldChartVersion -}} -{{- else -}} -{{- fail "A chart upgrade is not taking place" -}} -{{- end -}} -{{- end -}} - -{{/* -Retrieve new chart version to which we are upgrading from an old chart version -*/}} -{{- define "tn.chart.new_version" -}} -{{- if .Values.ixChartContext.is_upgrade -}} -{{- .Values.ixChartContext.upgradeMetadata.newChartVersion -}} -{{- else -}} -{{- fail "A chart upgrade is not taking place" -}} -{{- end -}} -{{- end -}} diff --git a/test/nextcloud/1.1.0/templates/backup-postgres-hook.yaml b/test/nextcloud/1.1.0/templates/backup-postgres-hook.yaml index 2286116f6b..175b0f2617 100644 --- a/test/nextcloud/1.1.0/templates/backup-postgres-hook.yaml +++ b/test/nextcloud/1.1.0/templates/backup-postgres-hook.yaml @@ -1,6 +1,6 @@ {{- if .Values.ixChartContext.isUpgrade -}} -{{ $values := . }} -{{ $_ := set $values "nameSuffix" "postgres" }} +{{ $values := (. | mustDeepCopy) }} +{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }} apiVersion: batch/v1 kind: Job metadata: @@ -24,11 +24,7 @@ spec: env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }} - name: BACKUP_NAME value: {{ template "postgres.backupName" . }} - volumeMounts: - - name: postgres-data - mountPath: /var/lib/postgresql/data - - name: postgres-backup - mountPath: /postgres_backups + volumeMounts: {{ include "postgres.volumeMountsConfiguration" $values | nindent 10 }} - name: backup-script-configmap mountPath: /bin/backup_entrypoint.sh readOnly: true diff --git a/test/nextcloud/1.1.0/templates/deployment.yaml b/test/nextcloud/1.1.0/templates/deployment.yaml index 61721d9b50..ba954a825c 100644 --- a/test/nextcloud/1.1.0/templates/deployment.yaml +++ b/test/nextcloud/1.1.0/templates/deployment.yaml @@ -1,21 +1,8 @@ {{ $postgres_values := (. | mustDeepCopy) }} {{ $_ := set $postgres_values "common" (dict "nameSuffix" "postgres") }} -apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }} -kind: Deployment -metadata: - name: {{ template "common.names.fullname" . }} - labels: {{ include "common.labels" . | nindent 4 }} - annotations: {{ include "common.annotations" . | nindent 4 }} -spec: - replicas: 1 - strategy: - type: {{ .Values.nextcloud.strategy }} - selector: - matchLabels: {{ include "common.labels.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: {{ include "common.labels.selectorLabels" . | nindent 8 }} - annotations: {{ include "common.annotations" . | nindent 8 }} +{{ include "common.deployment.common_config" . | nindent 0 }} +spec: {{ include "common.deployment.common_spec" . | nindent 2 }} + template: {{ include "common.deployment.pod.metadata" . | nindent 4 }} spec: initContainers: - name: init-postgresdb @@ -61,10 +48,7 @@ spec: - name: nextcloud-data mountPath: /var/www/html/themes subPath: "themes" - volumes: - {{ $vols := list }} - {{ $vols = mustAppend $vols (dict "name" "nextcloud-data" "emptyDirVolumes" .Values.emptyDirVolumes "hostPathEnabled" .Values.nextcloudDataHostPathEnabled "pathField" .Values.nextcloudHostPath "datasetName" (.Values.nextcloudDataVolume | default dict).datasetName ) }} - {{ include "common.storage.volumesConfiguration" (dict "ixVolumes" .Values.ixVolumes "volumes" $vols) | nindent 8 }} +{{ include "common.storage.allAppVolumes" .Values | nindent 6 }} # Will mount configuration files as www-data (id: 33) for nextcloud securityContext: fsGroup: 33 diff --git a/test/nextcloud/1.1.0/templates/postgres-deployment.yaml b/test/nextcloud/1.1.0/templates/postgres-deployment.yaml index 94aec328c8..c325ee8ced 100644 --- a/test/nextcloud/1.1.0/templates/postgres-deployment.yaml +++ b/test/nextcloud/1.1.0/templates/postgres-deployment.yaml @@ -1,31 +1,15 @@ {{ $values := (. | mustDeepCopy) }} {{ $_ := set $values "common" (dict "nameSuffix" "postgres") }} -apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }} -kind: Deployment -metadata: - name: {{ template "common.names.fullname" $values }} - labels: {{ include "common.labels.selectorLabels" $values | nindent 4 }} -spec: - replicas: 1 - strategy: - type: {{ .Values.nextcloud.strategy }} - selector: - matchLabels: {{- include "common.labels.selectorLabels" $values | nindent 6 }} - template: - metadata: - labels: {{- include "common.labels.selectorLabels" $values | nindent 8 }} - annotations: {{- include "common.annotations" $values | nindent 8 }} +{{ include "common.deployment.common_config" $values | nindent 0 }} +spec: {{ include "common.deployment.common_spec" $values | nindent 2 }} + template: {{ include "common.deployment.pod.metadata" $values | nindent 4 }} spec: containers: - name: {{ .Chart.Name }}-postgres image: {{ template "postgres.imageName" . }} imagePullPolicy: {{ .Values.image.pullPolicy }} env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }} - volumeMounts: - - name: postgres-data - mountPath: /var/lib/postgresql/data - - name: postgres-backup - mountPath: /postgres_backups + volumeMounts: {{ include "postgres.volumeMountsConfiguration" $values | nindent 10 }} ports: - name: postgres-tcp containerPort: 5432