Commit 58a796ab authored by Waqar Ahmed's avatar Waqar Ahmed

Update nextcloud chart migrating it to newer storage format

parent 7db9059e
#!/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]))))
...@@ -9,6 +9,8 @@ groups: ...@@ -9,6 +9,8 @@ groups:
description: "Configure nextcloud container parameters" description: "Configure nextcloud container parameters"
- name: "Postgresql Configuration" - name: "Postgresql Configuration"
description: "Configure Postgresql for nextcloud" description: "Configure Postgresql for nextcloud"
- name: "Scaling/Upgrade Policy"
description: "Configure how pods are replaced when configuration is upgraded"
portals: portals:
web_portal: web_portal:
...@@ -94,16 +96,20 @@ questions: ...@@ -94,16 +96,20 @@ questions:
type: path type: path
default: "/var/www/html/data" default: "/var/www/html/data"
required: true required: true
- variable: strategy
label: "Nextcloud update strategy" # Update strategy
schema: - variable: updateStrategy
type: string description: "Upgrade Policy"
default: "Recreate" label: "Update Strategy"
enum: group: "Scaling/Upgrade Policy"
- value: "RollingUpdate" schema:
description: "Create new pods and then kill old ones" type: string
- value: "Recreate" default: "Recreate"
description: "Kill existing pods before creating new ones" enum:
- value: "RollingUpdate"
description: "Create new pods and then kill old ones"
- value: "Recreate"
description: "Kill existing pods before creating new ones"
- variable: service - variable: service
description: "Nextcloud Service Configuration" description: "Nextcloud Service Configuration"
...@@ -122,80 +128,89 @@ questions: ...@@ -122,80 +128,89 @@ questions:
default: 9001 default: 9001
required: true required: true
- variable: nextcloudDataHostPathEnabled - variable: appVolumeMounts
label: "Configure Host Path for Nextcloud data" label: "Nextcloud Storage"
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"
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"
schema:
type: path
editable: false
default: "/var/www"
- variable: datasetName
label: "Nextcloud Dataset Name"
schema:
type: string
default: "ix-nextcloud_data"
editable: false
- variable: postgresBackupVolume
label: "Postgres Backup Volume Defaults"
group: "Storage" group: "Storage"
schema: schema:
type: dict type: dict
$ref:
- "normalize/ixVolume"
attrs: attrs:
- variable: mountPath - variable: nextcloud-data
label: "Postgres Backup Mount Path" label: "Nextcloud Data Volume"
schema: schema:
type: path type: dict
editable: false attrs:
default: "/postgres_backups" - variable: datasetName
- variable: datasetName label: "Nextcloud Data Volume Name"
label: "Postgres Backup Dataset Name" schema:
schema: type: string
type: string $ref:
default: "ix-postgres_backups" - "normalize/ixVolume"
editable: false 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: postgresDataVolume - variable: postgresAppVolumeMounts
label: "Postgresql Data Volume Defaults" label: "Postgres Storage"
group: "Storage" group: "Storage"
schema: schema:
type: dict type: dict
$ref:
- "normalize/ixVolume"
attrs: attrs:
- variable: mountPath - variable: postgres-data
label: "Postgres Mount Path" label: "Postgres Data Volume"
schema: schema:
type: path type: dict
editable: false attrs:
default: "/var/lib/postgresql/data" - variable: datasetName
- variable: datasetName label: "Postgres Data Volume Name"
label: "Postgres Dataset Name" schema:
schema: type: string
type: string $ref:
default: "ix-postgres_data" - "normalize/ixVolume"
editable: false 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: 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"
{{/* 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 -}}
...@@ -36,8 +36,14 @@ Retrieve postgres credentials for environment variables configuration ...@@ -36,8 +36,14 @@ Retrieve postgres credentials for environment variables configuration
Retrieve postgres volume configuration Retrieve postgres volume configuration
*/}} */}}
{{- define "postgres.volumeConfiguration" -}} {{- define "postgres.volumeConfiguration" -}}
{{ $vols := list }} {{ include "common.storage.configureAppVolumes" (dict "appVolumeMounts" .Values.postgresAppVolumeMounts "emptyDirVolumes" .Values.emptyDirVolumes "ixVolumes" .Values.ixVolumes) | nindent 0 }}
{{ $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) }}
{{- end -}} {{- end -}}
{{/*
Retrieve postgres volume mounts configuration
*/}}
{{- define "postgres.volumeMountsConfiguration" -}}
{{ include "common.storage.configureAppVolumeMountsInContainer" (dict "appVolumeMounts" .Values.postgresAppVolumeMounts ) | nindent 0 }}
{{- end -}}
{{/*
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 -}}
{{- if .Values.ixChartContext.isUpgrade -}} {{- if .Values.ixChartContext.isUpgrade -}}
{{ $values := . }} {{ $values := (. | mustDeepCopy) }}
{{ $_ := set $values "nameSuffix" "postgres" }} {{ $_ := set $values "common" (dict "nameSuffix" "postgres") }}
apiVersion: batch/v1 apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
...@@ -24,11 +24,7 @@ spec: ...@@ -24,11 +24,7 @@ spec:
env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }} env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }}
- name: BACKUP_NAME - name: BACKUP_NAME
value: {{ template "postgres.backupName" . }} value: {{ template "postgres.backupName" . }}
volumeMounts: volumeMounts: {{ include "postgres.volumeMountsConfiguration" $values | nindent 10 }}
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: postgres-backup
mountPath: /postgres_backups
- name: backup-script-configmap - name: backup-script-configmap
mountPath: /bin/backup_entrypoint.sh mountPath: /bin/backup_entrypoint.sh
readOnly: true readOnly: true
......
{{ $postgres_values := (. | mustDeepCopy) }} {{ $postgres_values := (. | mustDeepCopy) }}
{{ $_ := set $postgres_values "common" (dict "nameSuffix" "postgres") }} {{ $_ := set $postgres_values "common" (dict "nameSuffix" "postgres") }}
apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }} {{ include "common.deployment.common_config" . | nindent 0 }}
kind: Deployment spec: {{ include "common.deployment.common_spec" . | nindent 2 }}
metadata: template: {{ include "common.deployment.pod.metadata" . | nindent 4 }}
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 }}
spec: spec:
initContainers: initContainers:
- name: init-postgresdb - name: init-postgresdb
...@@ -61,10 +48,7 @@ spec: ...@@ -61,10 +48,7 @@ spec:
- name: nextcloud-data - name: nextcloud-data
mountPath: /var/www/html/themes mountPath: /var/www/html/themes
subPath: "themes" subPath: "themes"
volumes: {{ include "common.storage.allAppVolumes" .Values | nindent 6 }}
{{ $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 }}
# Will mount configuration files as www-data (id: 33) for nextcloud # Will mount configuration files as www-data (id: 33) for nextcloud
securityContext: securityContext:
fsGroup: 33 fsGroup: 33
{{ $values := (. | mustDeepCopy) }} {{ $values := (. | mustDeepCopy) }}
{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }} {{ $_ := set $values "common" (dict "nameSuffix" "postgres") }}
apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }} {{ include "common.deployment.common_config" $values | nindent 0 }}
kind: Deployment spec: {{ include "common.deployment.common_spec" $values | nindent 2 }}
metadata: template: {{ include "common.deployment.pod.metadata" $values | nindent 4 }}
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 }}
spec: spec:
containers: containers:
- name: {{ .Chart.Name }}-postgres - name: {{ .Chart.Name }}-postgres
image: {{ template "postgres.imageName" . }} image: {{ template "postgres.imageName" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }} imagePullPolicy: {{ .Values.image.pullPolicy }}
env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }} env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }}
volumeMounts: volumeMounts: {{ include "postgres.volumeMountsConfiguration" $values | nindent 10 }}
- name: postgres-data
mountPath: /var/lib/postgresql/data
- name: postgres-backup
mountPath: /postgres_backups
ports: ports:
- name: postgres-tcp - name: postgres-tcp
containerPort: 5432 containerPort: 5432
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment