From d8e2b5e8fee7e2d60b224928a2be8940e4fb0de4 Mon Sep 17 00:00:00 2001
From: Vineet Reddy Rajula <rajula.vineet.reddy@cern.ch>
Date: Fri, 16 Jul 2021 11:04:47 +0200
Subject: [PATCH] Fix templates & restic password file name

---
 .../cluster-tasks/templates/clear-cache.yaml  |  3 +-
 .../templates/database-restore.yaml           | 36 +++++++++++++++++++
 .../templates/drupalsite-restore.yaml         |  2 +-
 .../drupal_operation_job.yaml                 |  4 +--
 tekton-task-templates/restore_pv_job.yaml     | 10 ++----
 velero-restic-restore/restore_pvs.sh          |  2 +-
 6 files changed, 44 insertions(+), 13 deletions(-)
 create mode 100644 chart/cluster-tasks/templates/database-restore.yaml

diff --git a/chart/cluster-tasks/templates/clear-cache.yaml b/chart/cluster-tasks/templates/clear-cache.yaml
index 1508b43..8c8a63e 100644
--- a/chart/cluster-tasks/templates/clear-cache.yaml
+++ b/chart/cluster-tasks/templates/clear-cache.yaml
@@ -21,7 +21,8 @@ spec:
       - |-
         echo "--------------------------- Clear cache ---------------------------"
         echo "Drupal site name: $(params.drupalSite)"
-        export TASK=clear-cache
+        export DATE=$(date +%F-%H-%M)
+        export TASK=clear-cache-$DATE
         export OPERATION="clear-cache"
         export DRUPALSITE=$(params.drupalSite)
         export NAMESPACE=$(params.namespace)
diff --git a/chart/cluster-tasks/templates/database-restore.yaml b/chart/cluster-tasks/templates/database-restore.yaml
new file mode 100644
index 0000000..4188bcc
--- /dev/null
+++ b/chart/cluster-tasks/templates/database-restore.yaml
@@ -0,0 +1,36 @@
+apiVersion: tekton.dev/v1beta1
+kind: ClusterTask
+metadata:
+  name: database-restore
+spec:
+  params:
+    - name: drupalSite
+      type: string
+      description: The name of the drupal site
+    - name: namespace
+      type: string
+      description: The namespace of the drupal site
+  steps:
+    - name: database-restore
+      image: gitlab-registry.cern.ch/drupal/paas/drupal-operations/openshift-cli:velero-restore
+      imagePullPolicy: Always
+      command:
+        - /bin/sh
+        - '-c'
+      args:
+      - |-
+        echo "--------------------------- Database restore ---------------------------"
+        echo "Drupal site name: $(params.drupalSite)"
+        export DATE=$(date +%F-%H-%M)
+        export TASK=database-restore-$DATE
+        export OPERATION="database-restore"
+        export DRUPALSITE=$(params.drupalSite)
+        export ARGS="-f 'database_backup.sql'"
+        export NAMESPACE=$(params.namespace)
+        export SERVING_POD_IMAGE=$(oc get -n $(params.namespace) drupalsite/$(params.drupalSite) -o=jsonpath='{.status.servingPodImage}')
+        envsubst < /tekton-task-templates/drupal_operation_job.yaml | oc create -n $(params.namespace) -f -
+        oc wait --for=condition=complete job/$TASK-$(params.drupalSite)
+        jobStatus=$(oc get job/$TASK-$(params.drupalSite) -o=jsonpath='{.status.conditions[*].type}' | grep -i -E 'failed|complete' || echo "Failed")
+        echo "Job status: $jobStatus"
+        echo "Job logs:"
+        oc logs job/$TASK-$DRUPALSITE -n $(params.namespace)
diff --git a/chart/cluster-tasks/templates/drupalsite-restore.yaml b/chart/cluster-tasks/templates/drupalsite-restore.yaml
index 380f23d..16bfa0d 100644
--- a/chart/cluster-tasks/templates/drupalsite-restore.yaml
+++ b/chart/cluster-tasks/templates/drupalsite-restore.yaml
@@ -43,7 +43,7 @@ spec:
         export TASK=db-restore-$DATE
         export SERVING_POD_IMAGE=$(oc get -n $NAMESPACE drupalsite/$(params.drupalSite) -o=jsonpath='{.status.servingPodImage}')
         export OPERATION="database-restore"
-        export ARGS="-f database_backup.sql"
+        export ARGS="-f 'database_backup.sql'"
         envsubst < /tekton-task-templates/drupal_operation_job.yaml | oc create -n $NAMESPACE -f -
         oc wait --for=condition=complete job/$TASK-$(params.drupalSite)
         jobStatus=$(oc get job/$TASK-$(params.drupalSite) -o=jsonpath='{.status.conditions[*].type}' | grep -i -E 'failed|complete' || echo "Failed")
diff --git a/tekton-task-templates/drupal_operation_job.yaml b/tekton-task-templates/drupal_operation_job.yaml
index c505d1c..b9fb165 100644
--- a/tekton-task-templates/drupal_operation_job.yaml
+++ b/tekton-task-templates/drupal_operation_job.yaml
@@ -16,8 +16,8 @@ spec:
       containers:
       - command:
         - sh
-        - /operations/$OPERATION.sh 
-        - $ARGS
+        - '-c'
+        - /operations/$OPERATION.sh $ARGS
         env:
         - name: DRUPAL_SHARED_VOLUME
           value: /drupal-data
diff --git a/tekton-task-templates/restore_pv_job.yaml b/tekton-task-templates/restore_pv_job.yaml
index a40ff3d..9ef9e3b 100644
--- a/tekton-task-templates/restore_pv_job.yaml
+++ b/tekton-task-templates/restore_pv_job.yaml
@@ -43,12 +43,12 @@ spec:
               valueFrom:
                 secretKeyRef:
                   name: cephfs-backup-secrets
-                  key: cephfs-backup-s3-access-key
+                  key: cephfsBackupS3AccessKey
             - name: AWS_SECRET_ACCESS_KEY
               valueFrom:
                 secretKeyRef:
                   name: cephfs-backup-secrets
-                  key: cephfs-backup-s3-secret-key
+                  key: cephfsBackupS3SecretKey
           resources: {}
           volumeMounts:
             - name: openstack-credentials
@@ -69,13 +69,7 @@ spec:
           imagePullPolicy: Always
           securityContext:
             privileged: true
-            runAsUser: 0
       restartPolicy: Never
       terminationGracePeriodSeconds: 30
-      dnsPolicy: ClusterFirst
-      nodeSelector:
-        node-role.kubernetes.io/infra: ''
       serviceAccountName: $RESTORE_SERVICE_ACCOUNT
       serviceAccount: $RESTORE_SERVICE_ACCOUNT
-      securityContext: {}
-      schedulerName: default-scheduler
diff --git a/velero-restic-restore/restore_pvs.sh b/velero-restic-restore/restore_pvs.sh
index c86d0ce..e7c11dd 100755
--- a/velero-restic-restore/restore_pvs.sh
+++ b/velero-restic-restore/restore_pvs.sh
@@ -89,7 +89,7 @@ mount -t ceph "$CEPHFS_PATH_PV" -o name="$PV_NAME",noatime,secret="$CEPHFS_USERK
 mkdir -p /restore
 chmod 777 /restore
 
-restic -p /tmp/restic_password -r "$RESTIC_REPO" restore "$RESTIC_SNAPSHOT_ID" --target /restore
+restic -p /tmp/repository-password -r "$RESTIC_REPO" restore "$RESTIC_SNAPSHOT_ID" --target /restore
 
 rsync -avz /restore/ /mnt/ --delete
 
-- 
GitLab