diff --git a/test/nextcloud/1.0.0/.helmignore b/test/nextcloud/1.1.0/.helmignore similarity index 100% rename from test/nextcloud/1.0.0/.helmignore rename to test/nextcloud/1.1.0/.helmignore diff --git a/test/nextcloud/1.0.0/Chart.yaml b/test/nextcloud/1.1.0/Chart.yaml similarity index 96% rename from test/nextcloud/1.0.0/Chart.yaml rename to test/nextcloud/1.1.0/Chart.yaml index 81b380228bf..df04f529d5d 100644 --- a/test/nextcloud/1.0.0/Chart.yaml +++ b/test/nextcloud/1.1.0/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: nextcloud -version: 1.0.0 +version: 1.1.0 appVersion: 19.0.3 description: A file sharing server that puts the control and security of your own data back into your hands. keywords: diff --git a/test/nextcloud/1.0.0/README.md b/test/nextcloud/1.1.0/README.md similarity index 100% rename from test/nextcloud/1.0.0/README.md rename to test/nextcloud/1.1.0/README.md diff --git a/test/nextcloud/1.0.0/app-readme.md b/test/nextcloud/1.1.0/app-readme.md similarity index 100% rename from test/nextcloud/1.0.0/app-readme.md rename to test/nextcloud/1.1.0/app-readme.md diff --git a/test/nextcloud/1.0.0/questions.yaml b/test/nextcloud/1.1.0/questions.yaml similarity index 100% rename from test/nextcloud/1.0.0/questions.yaml rename to test/nextcloud/1.1.0/questions.yaml diff --git a/test/nextcloud/1.0.0/templates/NOTES.txt b/test/nextcloud/1.1.0/templates/NOTES.txt similarity index 100% rename from test/nextcloud/1.0.0/templates/NOTES.txt rename to test/nextcloud/1.1.0/templates/NOTES.txt diff --git a/test/nextcloud/1.1.0/templates/_backup.tpl b/test/nextcloud/1.1.0/templates/_backup.tpl new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/nextcloud/1.0.0/templates/_helpers.tpl b/test/nextcloud/1.1.0/templates/_helpers.tpl similarity index 94% rename from test/nextcloud/1.0.0/templates/_helpers.tpl rename to test/nextcloud/1.1.0/templates/_helpers.tpl index 3c582e14d7b..43114be492d 100644 --- a/test/nextcloud/1.0.0/templates/_helpers.tpl +++ b/test/nextcloud/1.1.0/templates/_helpers.tpl @@ -107,9 +107,8 @@ app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} {{/* -Postgres Selector labels +Nextcloud service account */}} -{{- define "nextcloud.postgres.selectorLabels" -}} -app.kubernetes.io/name: {{ include "nextcloud.name" . }}-postgres -app.kubernetes.io/instance: {{ .Release.Name }}-postgres -{{- end }} +{{- 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 new file mode 100644 index 00000000000..038a680c802 --- /dev/null +++ b/test/nextcloud/1.1.0/templates/_postgres.tpl @@ -0,0 +1,28 @@ +{{/* +Get Nextloud Postgres Database Name +*/}} +{{- define "postgres.DatabaseName" -}} +{{- print "nextcloud" -}} +{{- end -}} + +{{/* +Postgres Selector labels +*/}} +{{- define "nextcloud.postgres.selectorLabels" -}} +app.kubernetes.io/name: {{ include "nextcloud.name" . }}-postgres +app.kubernetes.io/instance: {{ .Release.Name }}-postgres +{{- end }} + +{{- define "postgres.imageName" -}} +{{- print "postgres:13.1" -}} +{{- end -}} + +{{/* +Retrieve postgres backup name +This will return a unique name based on revision and chart numbers specified. +*/}} +{{- define "postgres.backupName" -}} +{{- $upgradeDict := .Values.ixChartContext.upgradeMetadata -}} +{{- printf "postgres-backup-from-%s-to-%s-revision-%d" $upgradeDict.oldChartVersion $upgradeDict.newChartVersion (int64 $upgradeDict.preUpgradeRevision) -}} +{{- end }} + diff --git a/test/nextcloud/1.1.0/templates/_upgrade.tpl b/test/nextcloud/1.1.0/templates/_upgrade.tpl new file mode 100644 index 00000000000..eb0ae1e6603 --- /dev/null +++ b/test/nextcloud/1.1.0/templates/_upgrade.tpl @@ -0,0 +1,21 @@ +{{/* +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-config.yaml b/test/nextcloud/1.1.0/templates/backup-postgres-config.yaml new file mode 100644 index 00000000000..c9ccf66dbaa --- /dev/null +++ b/test/nextcloud/1.1.0/templates/backup-postgres-config.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: "postgres-backup-hook-config-map" + annotations: + rollme: {{ randAlphaNum 5 | quote }} +data: + entrypoint.sh: |- + #!/bin/sh + cmd="/docker-entrypoint.sh postgres" + eval "${cmd}" & disown; + until pg_isready; do + sleep 5; + done; + pg_dump -U $POSTGRES_USER -d {{ template "postgres.DatabaseName" . }} > /postgres_backups/$BACKUP_NAME; diff --git a/test/nextcloud/1.1.0/templates/backup-postgres-hook.yaml b/test/nextcloud/1.1.0/templates/backup-postgres-hook.yaml new file mode 100644 index 00000000000..3f6c6dc3662 --- /dev/null +++ b/test/nextcloud/1.1.0/templates/backup-postgres-hook.yaml @@ -0,0 +1,57 @@ +{{- if .Values.ixChartContext.isUpgrade -}} +apiVersion: batch/v1 +kind: Job +metadata: + name: "pre-upgrade-hook2" + annotations: + "helm.sh/hook": pre-upgrade + "helm.sh/hook-weight": "1" + "helm.sh/hook-delete-policy": hook-succeeded + rollme: {{ randAlphaNum 5 | quote }} +spec: + template: + metadata: + name: "pre-upgrade-hook2" + spec: + restartPolicy: Never + serviceAccountName: "{{ template "nextcloud.serviceAccountName" . }}" + containers: + - name: {{ .Chart.Name }}-postgres-backup + image: {{ template "postgres.imageName" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: db-details + key: db-user + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: db-details + key: db-password + - name: BACKUP_NAME + value: {{ template "postgres.backupName" . }} + volumeMounts: + - name: postgres-data + mountPath: /var/lib/postgresql/data + - name: postgres-backup + mountPath: /postgres_backups + - name: backup-script-configmap + mountPath: /bin/backup_entrypoint.sh + readOnly: true + subPath: entrypoint.sh + command: + - "/bin/backup_entrypoint.sh" + volumes: + - name: postgres-data + hostPath: + path: {{ template "configuredPostgresHostPath" . }} + - name: postgres-backup + hostPath: + path: {{ template "configuredBackupPostgresHostPath" . }} + - name: backup-script-configmap + configMap: + defaultMode: 0700 + name: "postgres-backup-hook-config-map" +{{- end -}} diff --git a/test/nextcloud/1.0.0/templates/deployment.yaml b/test/nextcloud/1.1.0/templates/deployment.yaml similarity index 93% rename from test/nextcloud/1.0.0/templates/deployment.yaml rename to test/nextcloud/1.1.0/templates/deployment.yaml index e73c7f366de..a4cfd7c2d7a 100644 --- a/test/nextcloud/1.0.0/templates/deployment.yaml +++ b/test/nextcloud/1.1.0/templates/deployment.yaml @@ -38,8 +38,8 @@ spec: {{- end }} initContainers: - name: init-postgresdb - image: busybox:latest - command: ['sh', '-c', "until nc -w 5 -vz {{ template "nextcloud.fullname" . }}-postgres 5432; do echo waiting for postgres; sleep 2; done"] + image: {{ template "postgres.imageName" . }} + command: ['sh', '-c', "until pg_isready -h {{ template "nextcloud.fullname" . }}-postgres; do echo waiting for postgres; sleep 2; done"] imagePullPolicy: {{ .Values.image.pullPolicy }} containers: - name: {{ .Chart.Name }} @@ -49,7 +49,7 @@ spec: - name: POSTGRES_HOST value: {{ template "nextcloud.fullname" . }}-postgres:5432 - name: POSTGRES_DB - value: "nextcloud" + value: {{ template "postgres.DatabaseName" . }} - name: POSTGRES_USER valueFrom: secretKeyRef: diff --git a/test/nextcloud/1.1.0/templates/nuke-deployments-hook.yaml b/test/nextcloud/1.1.0/templates/nuke-deployments-hook.yaml new file mode 100644 index 00000000000..7307db6c1d6 --- /dev/null +++ b/test/nextcloud/1.1.0/templates/nuke-deployments-hook.yaml @@ -0,0 +1,22 @@ +{{- if .Values.ixChartContext.isUpgrade -}} +apiVersion: batch/v1 +kind: Job +metadata: + name: "pre-upgrade-hook1" + annotations: + "helm.sh/hook": pre-upgrade + "helm.sh/hook-weight": "-1" + "helm.sh/hook-delete-policy": hook-succeeded + rollme: {{ randAlphaNum 5 | quote }} +spec: + template: + metadata: + name: "pre-upgrade-hook1" + spec: + restartPolicy: Never + serviceAccountName: "{{ template "nextcloud.serviceAccountName" . }}" + containers: + - name: kubectl + image: "bitnami/kubectl:1.19" + command: ["kubectl", "delete" , "deployment", "{{ template "nextcloud.fullname" . }}", "{{ template "nextcloud.fullname" . }}-postgres"] +{{- end -}} diff --git a/test/nextcloud/1.0.0/templates/postgres-deployment.yaml b/test/nextcloud/1.1.0/templates/postgres-deployment.yaml similarity index 97% rename from test/nextcloud/1.0.0/templates/postgres-deployment.yaml rename to test/nextcloud/1.1.0/templates/postgres-deployment.yaml index da39a2cd76d..47ce9363394 100644 --- a/test/nextcloud/1.0.0/templates/postgres-deployment.yaml +++ b/test/nextcloud/1.1.0/templates/postgres-deployment.yaml @@ -25,7 +25,7 @@ spec: spec: containers: - name: {{ .Chart.Name }}-postgres - image: "postgres:13.1" + image: {{ template "postgres.imageName" . }} imagePullPolicy: {{ .Values.image.pullPolicy }} env: - name: POSTGRES_USER diff --git a/test/nextcloud/1.0.0/templates/postgres-secret.yaml b/test/nextcloud/1.1.0/templates/postgres-secret.yaml similarity index 100% rename from test/nextcloud/1.0.0/templates/postgres-secret.yaml rename to test/nextcloud/1.1.0/templates/postgres-secret.yaml diff --git a/test/nextcloud/1.0.0/templates/postgres-service.yaml b/test/nextcloud/1.1.0/templates/postgres-service.yaml similarity index 100% rename from test/nextcloud/1.0.0/templates/postgres-service.yaml rename to test/nextcloud/1.1.0/templates/postgres-service.yaml diff --git a/test/nextcloud/1.0.0/templates/secrets.yaml b/test/nextcloud/1.1.0/templates/secrets.yaml similarity index 100% rename from test/nextcloud/1.0.0/templates/secrets.yaml rename to test/nextcloud/1.1.0/templates/secrets.yaml diff --git a/test/nextcloud/1.0.0/templates/service.yaml b/test/nextcloud/1.1.0/templates/service.yaml similarity index 100% rename from test/nextcloud/1.0.0/templates/service.yaml rename to test/nextcloud/1.1.0/templates/service.yaml diff --git a/test/nextcloud/1.1.0/templates/serviceaccount.yaml b/test/nextcloud/1.1.0/templates/serviceaccount.yaml new file mode 100644 index 00000000000..c25bd439fd5 --- /dev/null +++ b/test/nextcloud/1.1.0/templates/serviceaccount.yaml @@ -0,0 +1,39 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: "{{ template "nextcloud.serviceAccountName" . }}" + namespace: {{ .Release.Namespace }} + +--- + +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: "{{ .Release.Name }}-service-account-role-binding" +subjects: +- kind: ServiceAccount + name: "{{ template "nextcloud.serviceAccountName" . }}" + namespace: {{ .Release.Namespace }} +roleRef: + kind: Role + name: "{{ .Release.Name }}-service-account-role" + apiGroup: rbac.authorization.k8s.io + +--- + +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: "{{ .Release.Name }}-service-account-role" + namespace: {{ .Release.Namespace }} +rules: + - apiGroups: + - "" + - "apps" + resources: + - pods + - deployments + verbs: + - delete + - get + - list diff --git a/test/nextcloud/1.0.0/test_values.yaml b/test/nextcloud/1.1.0/test_values.yaml similarity index 96% rename from test/nextcloud/1.0.0/test_values.yaml rename to test/nextcloud/1.1.0/test_values.yaml index d087f4c6f7c..13feb4fc964 100644 --- a/test/nextcloud/1.0.0/test_values.yaml +++ b/test/nextcloud/1.1.0/test_values.yaml @@ -25,3 +25,4 @@ service: nodePort: 31000 emptyDirVolumes: true +ixChartContext: {} diff --git a/test/nextcloud/1.0.0/values.yaml b/test/nextcloud/1.1.0/values.yaml similarity index 100% rename from test/nextcloud/1.0.0/values.yaml rename to test/nextcloud/1.1.0/values.yaml