Create Volume(Mounts) in the cluster resource
Change-Id: If80650dffe052b21ba220037e52f50647f37ff11
diff --git a/operator/src/main/java/com/google/gerrit/k8s/operator/cluster/GerritCluster.java b/operator/src/main/java/com/google/gerrit/k8s/operator/cluster/GerritCluster.java
index f96a6d7..693602a 100644
--- a/operator/src/main/java/com/google/gerrit/k8s/operator/cluster/GerritCluster.java
+++ b/operator/src/main/java/com/google/gerrit/k8s/operator/cluster/GerritCluster.java
@@ -14,9 +14,15 @@
package com.google.gerrit.k8s.operator.cluster;
+import static com.google.gerrit.k8s.operator.cluster.GitRepositoriesPVC.REPOSITORY_PVC_NAME;
+
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.fabric8.kubernetes.api.model.Namespaced;
import io.fabric8.kubernetes.api.model.Status;
+import io.fabric8.kubernetes.api.model.Volume;
+import io.fabric8.kubernetes.api.model.VolumeBuilder;
+import io.fabric8.kubernetes.api.model.VolumeMount;
+import io.fabric8.kubernetes.api.model.VolumeMountBuilder;
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.ShortNames;
@@ -31,6 +37,7 @@
@ShortNames("gclus")
public class GerritCluster extends CustomResource<GerritClusterSpec, Status> implements Namespaced {
private static final long serialVersionUID = 1L;
+ private static final String GIT_REPOSITORIES_VOLUME_NAME = "git-repositories";
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
@@ -50,4 +57,22 @@
return labels;
}
+
+ @JsonIgnore
+ public Volume getGitRepositoriesVolume() {
+ return new VolumeBuilder()
+ .withName(GIT_REPOSITORIES_VOLUME_NAME)
+ .withNewPersistentVolumeClaim()
+ .withClaimName(REPOSITORY_PVC_NAME)
+ .endPersistentVolumeClaim()
+ .build();
+ }
+
+ @JsonIgnore
+ public VolumeMount getGitRepositoriesVolumeMount() {
+ return new VolumeMountBuilder()
+ .withName(GIT_REPOSITORIES_VOLUME_NAME)
+ .withMountPath("/var/gerrit/git")
+ .build();
+ }
}
diff --git a/operator/src/main/java/com/google/gerrit/k8s/operator/gitgc/GitGarbageCollectionCronJob.java b/operator/src/main/java/com/google/gerrit/k8s/operator/gitgc/GitGarbageCollectionCronJob.java
index 77782ae..4c473dc 100644
--- a/operator/src/main/java/com/google/gerrit/k8s/operator/gitgc/GitGarbageCollectionCronJob.java
+++ b/operator/src/main/java/com/google/gerrit/k8s/operator/gitgc/GitGarbageCollectionCronJob.java
@@ -14,8 +14,6 @@
package com.google.gerrit.k8s.operator.gitgc;
-import static com.google.gerrit.k8s.operator.cluster.GitRepositoriesPVC.REPOSITORY_PVC_NAME;
-
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.k8s.operator.cluster.GerritCluster;
import io.fabric8.kubernetes.api.model.Container;
@@ -41,7 +39,6 @@
extends CRUDKubernetesDependentResource<CronJob, GitGarbageCollection> {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
- private static final String GIT_REPOSITORIES_VOLUME_NAME = "git-repositories";
private static final String LOGS_VOLUME_NAME = "logs";
public GitGarbageCollectionCronJob() {
@@ -67,13 +64,7 @@
Map<String, String> gitGcLabels =
gerritCluster.getLabels("GitGc", this.getClass().getSimpleName());
- Volume gitRepositoriesVolume =
- new VolumeBuilder()
- .withName(GIT_REPOSITORIES_VOLUME_NAME)
- .withNewPersistentVolumeClaim()
- .withClaimName(REPOSITORY_PVC_NAME)
- .endPersistentVolumeClaim()
- .build();
+ Volume gitRepositoriesVolume = gerritCluster.getGitRepositoriesVolume();
Volume logsVolume =
new VolumeBuilder()
@@ -101,7 +92,7 @@
.withNewSecurityContext()
.withFsGroup(100L)
.endSecurityContext()
- .addToContainers(buildGitGcContainer(gitGc))
+ .addToContainers(buildGitGcContainer(gitGc, gerritCluster))
.withVolumes(List.of(gitRepositoriesVolume, logsVolume))
.endSpec()
.endTemplate()
@@ -131,13 +122,7 @@
.build();
}
- private Container buildGitGcContainer(GitGarbageCollection gitGc) {
- VolumeMount gitRepositoriesVolumeMount =
- new VolumeMountBuilder()
- .withName(GIT_REPOSITORIES_VOLUME_NAME)
- .withMountPath("/var/gerrit/git")
- .build();
-
+ private Container buildGitGcContainer(GitGarbageCollection gitGc, GerritCluster gerritCluster) {
VolumeMount logsVolumeMount =
new VolumeMountBuilder()
.withName(LOGS_VOLUME_NAME)
@@ -161,7 +146,8 @@
.withImage(gitGc.getSpec().getImage())
.withResources(gitGc.getSpec().getResources())
.withEnv(podNameEnvVar)
- .withVolumeMounts(List.of(gitRepositoriesVolumeMount, logsVolumeMount));
+ .withVolumeMounts(
+ List.of(gerritCluster.getGitRepositoriesVolumeMount(), logsVolumeMount));
ArrayList<String> args = new ArrayList<>();
for (String project : gitGc.getSpec().getProjects()) {