Share the Gerrit site between containers in a pod

Only parts of the Gerrit site are persisted. The other parts were taken
from the site existing in the container. Thus, when using initContainers
the site in the initContainer and the main container could differ, which
is not ideal and could lead to unwanted effects.

This change adds an emptyDir-volume to the Gerrit-deployments in the
gerrit-master and gerrit-slave charts. This volume is shared by all
containers in the pod accessing the site. Persistent volumes used to
persist parts of the site overwrite the emptyDir volume. Some
adjustments had to be made to the startup scripts, since the emptyDir
overwrites the site present in the container on startup with an empty
directory, thereby removing resources expected by the scripts.

Change-Id: I649280f2ddf2b2d41aaf7f9953ade794ab84a900
diff --git a/container-images/gerrit-init/tools/start b/container-images/gerrit-init/tools/start
index 48f733d..b1e4e32 100755
--- a/container-images/gerrit-init/tools/start
+++ b/container-images/gerrit-init/tools/start
@@ -103,7 +103,7 @@
 wait_for_db_connection
 
 if [[ "$TEST_MODE" == "true" ]]; then
-  java -jar /var/gerrit/bin/gerrit.war init \
+  java -jar /var/war/gerrit.war init \
     --batch \
     --no-auto-start \
     --install-plugin singleusergroup \
@@ -113,4 +113,4 @@
 # wait for db schema to arrive via replication from master
 wait_for_db_schema
 
-echo "Gerrit site appears to be initialized. Gerrit slave can be startet."
\ No newline at end of file
+echo "Gerrit site appears to be initialized. Gerrit slave can be startet."
diff --git a/helm-charts/gerrit-master/templates/gerrit-master.deployment.yaml b/helm-charts/gerrit-master/templates/gerrit-master.deployment.yaml
index 5243005..95b57c7 100644
--- a/helm-charts/gerrit-master/templates/gerrit-master.deployment.yaml
+++ b/helm-charts/gerrit-master/templates/gerrit-master.deployment.yaml
@@ -46,6 +46,8 @@
         - -c
         args:
         - |
+          mkdir -p /var/gerrit/etc
+
           {{ if .Values.gerritMaster.keystore -}}
           ln -s /var/keystore /var/gerrit/etc/keystore
           {{- end }}
@@ -54,7 +56,7 @@
           ln -sf /var/config/replication.config /var/gerrit/etc/replication.config
           ln -sf /var/config/secure.config /var/gerrit/etc/secure.config
 
-          java -jar /var/gerrit/bin/gerrit.war init \
+          java -jar /var/war/gerrit.war init \
               --batch \
               --install-plugin replication \
               --install-plugin commit-message-length-validator \
@@ -78,6 +80,8 @@
         ports:
         - containerPort: 8080
         volumeMounts:
+        - name: gerrit-site
+          mountPath: "/var/gerrit"
         - name: gerrit-db
           mountPath: "/var/gerrit/db"
         - name: git-filesystem
@@ -101,6 +105,8 @@
         resources:
 {{ toYaml .Values.gerritMaster.resources | indent 10 }}
       volumes:
+      - name: gerrit-site
+        emptyDir: {}
       - name: gerrit-db
         {{ if .Values.gerritMaster.h2Database.persistence.enabled -}}
         persistentVolumeClaim:
diff --git a/helm-charts/gerrit-slave/templates/gerrit-slave.deployment.yaml b/helm-charts/gerrit-slave/templates/gerrit-slave.deployment.yaml
index db26d27..4020022 100644
--- a/helm-charts/gerrit-slave/templates/gerrit-slave.deployment.yaml
+++ b/helm-charts/gerrit-slave/templates/gerrit-slave.deployment.yaml
@@ -32,6 +32,8 @@
         - -c
         args:
         - |
+          mkdir -p /var/gerrit/etc
+
           {{ if .Values.gerritSlave.keystore -}}
           ln -s /var/keystore /var/gerrit/etc/keystore
           {{- end }}
@@ -46,10 +48,10 @@
               name: {{ .Release.Name }}-gerrit-slave-configmap
               key: test-mode
         volumeMounts:
+        - name: gerrit-site
+          mountPath: "/var/gerrit"
         - name: gerrit-db
           mountPath: "/var/gerrit/db"
-        - name: git-filesystem
-          mountPath: "/var/gerrit/git"
         - name: gerrit-logs
           mountPath: "/var/gerrit/logs"
         - name: gerrit-config
@@ -102,6 +104,11 @@
 
           JAVA_OPTIONS=$(git config --file /var/gerrit/etc/gerrit.config --get-all container.javaOptions)
 
+          DB=$(git config --file /var/gerrit/etc/gerrit.config --get database.type)
+          if [[ "${DB^^}" == "MYSQL" ]]; then
+            /var/tools/download_db_driver
+          fi
+
           java ${JAVA_OPTIONS} -jar /var/gerrit/bin/gerrit.war daemon \
               -d /var/gerrit \
               --enable-httpd \
@@ -117,6 +124,8 @@
         ports:
         - containerPort: 8080
         volumeMounts:
+        - name: gerrit-site
+          mountPath: "/var/gerrit"
         - name: gerrit-db
           mountPath: "/var/gerrit/db"
         - name: git-filesystem
@@ -137,6 +146,8 @@
         resources:
 {{ toYaml .Values.gerritSlave.resources | indent 10 }}
       volumes:
+      - name: gerrit-site
+        emptyDir: {}
       - name: gerrit-db
         {{ if .Values.gerritSlave.h2Database.persistence.enabled -}}
         persistentVolumeClaim: