[Operator] Handle cache.directory option automatically

Change-Id: I6051c98c513a082eeb0609fd5e106f9edb385b0a
diff --git a/operator/README.md b/operator/README.md
index b839106..67ec68a 100644
--- a/operator/README.md
+++ b/operator/README.md
@@ -424,8 +424,6 @@
           name = Gerrit Code Review
           email = gerrit@example.com
           anonymousCoward = Unnamed User
-        [cache]
-          directory = cache
         [container]
           javaOptions = -Xms200m
           javaOptions = -Xmx4g
@@ -443,6 +441,11 @@
 automatically and won't allow different values, i.e. it will fail to reconcile
 if a value is set to an illegal value. These options are:
 
+- `cache.directory`
+
+    This should stay in the volume mounted to contain the Gerrit site and will
+    thus be set to `cache`.
+
 - `container.javaHome`
 
     This has to be set to `/usr/lib/jvm/java-11-openjdk-amd64`, since this is
diff --git a/operator/k8s/gerrit.sample.yaml b/operator/k8s/gerrit.sample.yaml
index 058242e..483ad52 100644
--- a/operator/k8s/gerrit.sample.yaml
+++ b/operator/k8s/gerrit.sample.yaml
@@ -11,8 +11,6 @@
     gerrit.config: |-
       [auth]
         type = DEVELOPMENT_BECOME_ANY_ACCOUNT
-      [cache]
-        directory = cache
       [container]
         javaOptions = -Xms200m
         javaOptions = -Xmx4g
diff --git a/operator/src/main/java/com/google/gerrit/k8s/operator/gerrit/config/GerritConfigBuilder.java b/operator/src/main/java/com/google/gerrit/k8s/operator/gerrit/config/GerritConfigBuilder.java
index fe3fcca..a123db8 100644
--- a/operator/src/main/java/com/google/gerrit/k8s/operator/gerrit/config/GerritConfigBuilder.java
+++ b/operator/src/main/java/com/google/gerrit/k8s/operator/gerrit/config/GerritConfigBuilder.java
@@ -42,6 +42,7 @@
             Set.of("-Djavax.net.ssl.trustStore=/var/gerrit/etc/keystore")));
     requiredOptions.add(new RequiredOption<String>("container", "user", "gerrit"));
     requiredOptions.add(new RequiredOption<String>("gerrit", "basepath", "git"));
+    requiredOptions.add(new RequiredOption<String>("cache", "directory", "cache"));
     requiredOptions.add(new RequiredOption<Boolean>("index", "onlineUpgrade", false));
     return requiredOptions;
   }
diff --git a/operator/src/test/java/com/google/gerrit/k8s/operator/test/TestGerrit.java b/operator/src/test/java/com/google/gerrit/k8s/operator/test/TestGerrit.java
index 1cb00c5..b1af7eb 100644
--- a/operator/src/test/java/com/google/gerrit/k8s/operator/test/TestGerrit.java
+++ b/operator/src/test/java/com/google/gerrit/k8s/operator/test/TestGerrit.java
@@ -72,8 +72,6 @@
           + "  name = Gerrit Code Review\n"
           + "  email = gerrit@example.com\n"
           + "  anonymousCoward = Unnamed User\n"
-          + "[cache]\n"
-          + "  directory = cache\n"
           + "[container]\n"
           + "  javaOptions = -Xmx4g";