Add configurable SSH port to service in gerrit-chart

Adds the possibility to expose ssh in the gerrit service, which
in turn allows to execute ssh commands.

Note, that for using SSH, using the ingress is not possible. SSH
requests have to be sent directly to the service.

Change-Id: If92a07627f48c2b3f98dbb540abe5060da45b5a5
diff --git a/helm-charts/gerrit/README.md b/helm-charts/gerrit/README.md
index 4b0ba8a..8250c59 100644
--- a/helm-charts/gerrit/README.md
+++ b/helm-charts/gerrit/README.md
@@ -232,35 +232,38 @@
 future.
 ***
 
-| Parameter                              | Description                                                                                         | Default                                                                                  |
-|----------------------------------------|-----------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|
-| `gerrit.images.gerritInit`             | Image name of the Gerrit init container image                                                       | `k8s-gerrit/gerrit-init`                                                                 |
-| `gerrit.images.gerrit`                 | Image name of the Gerrit container image                                                            | `k8s-gerrit/gerrit`                                                                      |
-| `gerrit.replicas`                      | Number of replica pods to deploy                                                                    | `1`                                                                                      |
-| `gerrit.updatePartition`               | Number of pods to update simultaneously                                                             | `1`                                                                                      |
-| `gerrit.resources`                     | Configure the amount of resources the pod requests/is allowed                                       | `requests.cpu: 1`                                                                        |
-|                                        |                                                                                                     | `requests.memory: 5Gi`                                                                   |
-|                                        |                                                                                                     | `limits.cpu: 1`                                                                          |
-|                                        |                                                                                                     | `limits.memory: 6Gi`                                                                     |
-| `gerrit.persistence.enabled`           | Whether to persist the Gerrit site                                                                  | `true`                                                                                   |
-| `gerrit.persistence.size`              | Storage size for persisted Gerrit site                                                              | `10Gi`                                                                                   |
-| `gerrit.livenessProbe`                 | Configuration of the liveness probe timings                                                         | `{initialDelaySeconds: 30, periodSeconds: 5}`                                            |
-| `gerrit.readinessProbe`                | Configuration of the readiness probe timings                                                        | `{initialDelaySeconds: 5, periodSeconds: 1}`                                             |
-| `gerrit.networkPolicy.ingress`         | Custom ingress-network policy for gerrit pods                                                       | `nil`                                                                                    |
-| `gerrit.networkPolicy.egress`          | Custom egress-network policy for gerrit pods                                                        | `nil`                                                                                    |
-| `gerrit.service.type`                  | Which kind of Service to deploy                                                                     | `NodePort`                                                                               |
-| `gerrit.service.http.port`             | Port over which to expose HTTP                                                                      | `80`                                                                                     |
-| `gerrit.keystore`                      | base64-encoded Java keystore (`cat keystore.jks | base64`) to be used by Gerrit, when using SSL     | `nil`                                                                                    |
-| `gerrit.index.type`                    | Index type used by Gerrit (either `lucene` or `elasticsearch`)                                      | `lucene`                                                                                 |
-| `gerrit.plugins.packaged`              | List of Gerrit plugins that are packaged into the Gerrit-war-file to install                        | `["commit-message-length-validator", "download-commands", "replication", "reviewnotes"]` |
-| `gerrit.plugins.downloaded`            | List of Gerrit plugins that will be downloaded                                                      | `nil`                                                                                    |
-| `gerrit.plugins.downloaded[0].name`    | Name of plugin                                                                                      | `nil`                                                                                    |
-| `gerrit.plugins.downloaded[0].url`     | Download url of plugin                                                                              | `nil`                                                                                    |
-| `gerrit.plugins.downloaded[0].sha1`    | SHA1 sum of plugin jar used to ensure file integrity and version (optional)                         | `nil`                                                                                    |
-| `gerrit.plugins.cache.enabled`         | Whether to cache downloaded plugins                                                                 | `false`                                                                                  |
-| `gerrit.plugins.cache.size`            | Size of the volume used to store cached plugins                                                     | `1Gi`                                                                                    |
-| `gerrit.etc.config`                    | Map of config files (e.g. `gerrit.config`) that will be mounted to `$GERRIT_SITE/etc`by a ConfigMap | `{gerrit.config: ..., replication.config: ...}`[see here](#Gerrit-config-files)          |
-| `gerrit.etc.secret`                    | Map of config files (e.g. `secure.config`) that will be mounted to `$GERRIT_SITE/etc`by a Secret    | `{secure.config: ...}` [see here](#Gerrit-config-files)                                  |
+| Parameter                           | Description                                                                                         | Default                                                                                  |
+|-------------------------------------|-----------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|
+| `gerrit.images.gerritInit`          | Image name of the Gerrit init container image                                                       | `k8s-gerrit/gerrit-init`                                                                 |
+| `gerrit.images.gerrit`              | Image name of the Gerrit container image                                                            | `k8s-gerrit/gerrit`                                                                      |
+| `gerrit.replicas`                   | Number of replica pods to deploy                                                                    | `1`                                                                                      |
+| `gerrit.updatePartition`            | Number of pods to update simultaneously                                                             | `1`                                                                                      |
+| `gerrit.resources`                  | Configure the amount of resources the pod requests/is allowed                                       | `requests.cpu: 1`                                                                        |
+|                                     |                                                                                                     | `requests.memory: 5Gi`                                                                   |
+|                                     |                                                                                                     | `limits.cpu: 1`                                                                          |
+|                                     |                                                                                                     | `limits.memory: 6Gi`                                                                     |
+| `gerrit.persistence.enabled`        | Whether to persist the Gerrit site                                                                  | `true`                                                                                   |
+| `gerrit.persistence.size`           | Storage size for persisted Gerrit site                                                              | `10Gi`                                                                                   |
+| `gerrit.livenessProbe`              | Configuration of the liveness probe timings                                                         | `{initialDelaySeconds: 30, periodSeconds: 5}`                                            |
+| `gerrit.readinessProbe`             | Configuration of the readiness probe timings                                                        | `{initialDelaySeconds: 5, periodSeconds: 1}`                                             |
+| `gerrit.networkPolicy.ingress`      | Custom ingress-network policy for gerrit pods                                                       | `nil`                                                                                    |
+| `gerrit.networkPolicy.egress`       | Custom egress-network policy for gerrit pods                                                        | `nil`                                                                                    |
+| `gerrit.service.type`               | Which kind of Service to deploy                                                                     | `NodePort`                                                                               |
+| `gerrit.service.http.port`          | Port over which to expose HTTP                                                                      | `80`                                                                                     |
+| `gerrit.service.ssh.enabled`        | Whether to enable SSH                                                                               | `false`                                                                                  |
+| `gerrit.service.ssh.port`           | Port over which to expose SSH                                                                       | `29418`                                                                                  |
+| `gerrit.service.ssh.rsaKey`         | Private SSH key in RSA format                                                                       | `-----BEGIN RSA PRIVATE KEY-----`                                                        |
+| `gerrit.keystore`                   | base64-encoded Java keystore (`cat keystore.jks | base64`) to be used by Gerrit, when using SSL     | `nil`                                                                                    |
+| `gerrit.index.type`                 | Index type used by Gerrit (either `lucene` or `elasticsearch`)                                      | `lucene`                                                                                 |
+| `gerrit.plugins.packaged`           | List of Gerrit plugins that are packaged into the Gerrit-war-file to install                        | `["commit-message-length-validator", "download-commands", "replication", "reviewnotes"]` |
+| `gerrit.plugins.downloaded`         | List of Gerrit plugins that will be downloaded                                                      | `nil`                                                                                    |
+| `gerrit.plugins.downloaded[0].name` | Name of plugin                                                                                      | `nil`                                                                                    |
+| `gerrit.plugins.downloaded[0].url`  | Download url of plugin                                                                              | `nil`                                                                                    |
+| `gerrit.plugins.downloaded[0].sha1` | SHA1 sum of plugin jar used to ensure file integrity and version (optional)                         | `nil`                                                                                    |
+| `gerrit.plugins.cache.enabled`      | Whether to cache downloaded plugins                                                                 | `false`                                                                                  |
+| `gerrit.plugins.cache.size`         | Size of the volume used to store cached plugins                                                     | `1Gi`                                                                                    |
+| `gerrit.etc.config`                 | Map of config files (e.g. `gerrit.config`) that will be mounted to `$GERRIT_SITE/etc`by a ConfigMap | `{gerrit.config: ..., replication.config: ...}`[see here](#Gerrit-config-files)          |
+| `gerrit.etc.secret`                 | Map of config files (e.g. `secure.config`) that will be mounted to `$GERRIT_SITE/etc`by a Secret    | `{secure.config: ...}` [see here](#Gerrit-config-files)                                  |
 
 ### Gerrit config files
 
diff --git a/helm-charts/gerrit/templates/gerrit.secrets.yaml b/helm-charts/gerrit/templates/gerrit.secrets.yaml
index 4d67840..9ccb233 100644
--- a/helm-charts/gerrit/templates/gerrit.secrets.yaml
+++ b/helm-charts/gerrit/templates/gerrit.secrets.yaml
@@ -11,6 +11,9 @@
   {{ if .Values.gerrit.keystore -}}
   keystore: {{ .Values.gerrit.keystore }}
   {{- end }}
+  {{ if .Values.gerrit.service.ssh.enabled -}}
+  ssh_host_rsa_key: {{ .Values.gerrit.service.ssh.rsaKey | b64enc }}
+  {{- end }}
   {{- range $key, $value := .Values.gerrit.etc.secret }}
   {{ $key }}: {{ $value | b64enc }}
   {{- end }}
diff --git a/helm-charts/gerrit/templates/gerrit.service.yaml b/helm-charts/gerrit/templates/gerrit.service.yaml
index 4fab1ef..dc51f8e 100644
--- a/helm-charts/gerrit/templates/gerrit.service.yaml
+++ b/helm-charts/gerrit/templates/gerrit.service.yaml
@@ -13,6 +13,11 @@
   - name: http
     port: {{ .http.port }}
     targetPort: 8080
+  {{- if .ssh.enabled }}
+  - name: ssh
+    port: {{ .ssh.port }}
+    targetPort: 29418
+  {{- end }}
   selector:
     app: gerrit
   type: {{ .type }}
diff --git a/helm-charts/gerrit/templates/gerrit.stateful-set.yaml b/helm-charts/gerrit/templates/gerrit.stateful-set.yaml
index 55b6cba..3361031 100644
--- a/helm-charts/gerrit/templates/gerrit.stateful-set.yaml
+++ b/helm-charts/gerrit/templates/gerrit.stateful-set.yaml
@@ -79,6 +79,10 @@
             -c /var/config/gerrit-init.yaml \
             -s /var/gerrit
 
+          {{ if .Values.gerrit.service.ssh.enabled -}}
+          rm -f /var/gerrit/etc/ssh_host*key*
+          {{- end }}
+
           symlink_config_to_site
 
           {{ if not .Values.gerrit.persistence.enabled -}}
@@ -122,6 +126,10 @@
         ports:
         - name: gerrit-port
           containerPort: 8080
+        {{- if .Values.gerrit.service.ssh.enabled }}
+        - name: gerrit-ssh
+          containerPort: 29418
+        {{- end }}
         volumeMounts:
         - name: gerrit-site
           mountPath: "/var/gerrit"
diff --git a/helm-charts/gerrit/values.yaml b/helm-charts/gerrit/values.yaml
index 506227a..61f9164 100644
--- a/helm-charts/gerrit/values.yaml
+++ b/helm-charts/gerrit/values.yaml
@@ -154,6 +154,13 @@
     type: NodePort
     http:
       port: 80
+    ssh:
+      enabled: false
+      port: 29418
+      rsaKey: |-
+        -----BEGIN RSA PRIVATE KEY-----
+
+        -----END RSA PRIVATE KEY-----
 
   # `gerrit.keystore` expects a base64-encoded Java-keystore
   # Since Java keystores are binary files, adding the unencoded content and