Skip to content

Commit

Permalink
Fix additional volumes in MirrorMaker 2 (#11022)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Scholz <[email protected]>
  • Loading branch information
scholzj authored Jan 9, 2025
1 parent ef507d2 commit ac319a6
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,8 @@ protected List<VolumeMount> getVolumeMounts() {
String oauthTlsVolumeMountPath = buildClusterVolumeMountPath(MIRRORMAKER_2_OAUTH_TLS_CERTS_BASE_VOLUME_MOUNT, alias);
String oauthVolumeMountPath = buildClusterVolumeMountPath(MIRRORMAKER_2_OAUTH_SECRETS_BASE_VOLUME_MOUNT, alias);
AuthenticationUtils.configureClientAuthenticationVolumeMounts(mirrorMaker2Cluster.getAuthentication(), volumeMountList, tlsVolumeMountPath, passwordVolumeMountPath, oauthTlsVolumeMountPath, mirrorMaker2Cluster.getAlias() + "-oauth-certs", mirrorMaker2Cluster.getAlias() + '-', true, oauthVolumeMountPath);

}

TemplateUtils.addAdditionalVolumeMounts(volumeMountList, templateContainer);

return volumeMountList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -903,13 +903,42 @@ public void testTemplate() {
assertThat(pod.getSpec().getDnsConfig(), is(dnsConfig));
assertThat(pod.getSpec().getTopologySpreadConstraints(), containsInAnyOrder(tsc1, tsc2));
assertThat(pod.getSpec().getEnableServiceLinks(), is(false));
assertThat(getVolume(pod, VolumeUtils.STRIMZI_TMP_DIRECTORY_DEFAULT_VOLUME_NAME).getEmptyDir().getSizeLimit(), is(new Quantity("10Mi")));
assertThat(getVolume(pod, additionalVolumeMountEmptyDir.getName()).getEmptyDir(), is(emptyDir));
assertThat(getVolume(pod, additionalVolumeMountSecret.getName()).getSecret(), is(secret));
assertThat(getVolume(pod, additionalVolumeMountConfigMap.getName()).getConfigMap(), is(configMap));
assertThat(getVolumeMount(pod.getSpec().getContainers().get(0), additionalVolumeMountEmptyDir.getName()), is(additionalVolumeMountEmptyDir));
assertThat(getVolumeMount(pod.getSpec().getContainers().get(0), additionalVolumeMountSecret.getName()), is(additionalVolumeMountSecret));
assertThat(getVolumeMount(pod.getSpec().getInitContainers().get(0), additionalVolumeMountConfigMap.getName()), is(additionalVolumeMountConfigMap));


assertThat(pod.getSpec().getVolumes().size(), is(6));
assertThat(pod.getSpec().getVolumes().get(0).getName(), is(VolumeUtils.STRIMZI_TMP_DIRECTORY_DEFAULT_VOLUME_NAME));
assertThat(pod.getSpec().getVolumes().get(0).getEmptyDir(), is(notNullValue()));
assertThat(pod.getSpec().getVolumes().get(0).getEmptyDir().getSizeLimit(), is(new Quantity("10Mi")));
assertThat(pod.getSpec().getVolumes().get(1).getName(), is("kafka-metrics-and-logging"));
assertThat(pod.getSpec().getVolumes().get(1).getConfigMap().getName(), is("foo-connect-config"));
assertThat(pod.getSpec().getVolumes().get(2).getName(), is("rack-volume"));
assertThat(pod.getSpec().getVolumes().get(2).getEmptyDir(), is(notNullValue()));
assertThat(pod.getSpec().getVolumes().get(2).getEmptyDir().getSizeLimit(), is(new Quantity("1Mi")));
assertThat(pod.getSpec().getVolumes().get(3).getName(), is("secret-volume-name"));
assertThat(pod.getSpec().getVolumes().get(3).getSecret().getSecretName(), is("secret1"));
assertThat(pod.getSpec().getVolumes().get(4).getName(), is("empty-dir-volume-name"));
assertThat(pod.getSpec().getVolumes().get(4).getEmptyDir(), is(notNullValue()));
assertThat(pod.getSpec().getVolumes().get(4).getEmptyDir().getMedium(), is("Memory"));
assertThat(pod.getSpec().getVolumes().get(5).getName(), is("config-map-volume-name"));
assertThat(pod.getSpec().getVolumes().get(5).getConfigMap().getName(), is("configMap1"));

assertThat(pod.getSpec().getInitContainers().get(0).getVolumeMounts().size(), is(2));
assertThat(pod.getSpec().getInitContainers().get(0).getVolumeMounts().get(0).getName(), is("rack-volume"));
assertThat(pod.getSpec().getInitContainers().get(0).getVolumeMounts().get(0).getMountPath(), is("/opt/kafka/init"));
assertThat(pod.getSpec().getInitContainers().get(0).getVolumeMounts().get(1).getName(), is("config-map-volume-name"));
assertThat(pod.getSpec().getInitContainers().get(0).getVolumeMounts().get(1).getMountPath(), is("/mnt/config"));

assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().size(), is(5));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getName(), is(VolumeUtils.STRIMZI_TMP_DIRECTORY_DEFAULT_VOLUME_NAME));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath(), is(VolumeUtils.STRIMZI_TMP_DIRECTORY_DEFAULT_MOUNT_PATH));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(1).getName(), is("kafka-metrics-and-logging"));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(1).getMountPath(), is("/opt/kafka/custom-config/"));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(2).getName(), is("rack-volume"));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(2).getMountPath(), is("/opt/kafka/init"));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(3).getName(), is("secret-volume-name"));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(3).getMountPath(), is("/mnt/secret"));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(4).getName(), is("empty-dir-volume-name"));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(4).getMountPath(), is("/mnt/empty-dir"));
});

// Check Service
Expand All @@ -934,14 +963,6 @@ public void testTemplate() {
assertThat(sa.getMetadata().getLabels().entrySet().containsAll(saLabels.entrySet()), is(true));
assertThat(sa.getMetadata().getAnnotations().entrySet().containsAll(saAnots.entrySet()), is(true));
}

private static Volume getVolume(Pod pod, String volumeName) {
return pod.getSpec().getVolumes().stream().filter(volume -> volumeName.equals(volume.getName())).iterator().next();
}

private static VolumeMount getVolumeMount(Container container, String volumeName) {
return container.getVolumeMounts().stream().filter(volumeMount -> volumeName.equals(volumeMount.getName())).iterator().next();
}

@ParallelTest
public void testExternalConfigurationSecretEnvs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,6 @@ protected List<EnvVar> getExpectedEnvVars() {
return expected;
}

private static Volume getVolume(Pod pod, String volumeName) {
return pod.getSpec().getVolumes().stream().filter(volume -> volumeName.equals(volume.getName())).iterator().next();
}

private static VolumeMount getVolumeMount(Container container, String volumeName) {
return container.getVolumeMounts().stream().filter(volumeMount -> volumeName.equals(volumeMount.getName())).iterator().next();
}


@ParallelTest
public void testDefaultValues() {
KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, ResourceUtils.createEmptyKafkaMirrorMaker2(namespace, clusterName), VERSIONS, SHARED_ENV_PROVIDER);
Expand Down Expand Up @@ -993,13 +984,13 @@ public void testTemplate() {
.build();

VolumeMount additionalVolumeMountConfigMap = new VolumeMountBuilder()
.withName("config-map-volume-name-2")
.withName("config-map-volume-name")
.withMountPath("/mnt/myconfigmap")
.withSubPath("def")
.build();

VolumeMount additionalVolumeMountPvc = new VolumeMountBuilder()
.withName("pvc-volume-name-2")
.withName("pvc-volume-name")
.withMountPath("/mnt/mypvc")
.build();

Expand Down Expand Up @@ -1078,13 +1069,38 @@ public void testTemplate() {
assertThat(pod.getSpec().getDnsPolicy(), is(DnsPolicy.NONE.toValue()));
assertThat(pod.getSpec().getDnsConfig(), is(dnsConfig));
assertThat(pod.getSpec().getEnableServiceLinks(), is(false));
assertThat(getVolume(pod, "strimzi-tmp").getEmptyDir().getSizeLimit(), is(new Quantity("10Mi")));
assertThat(getVolume(pod, additionalVolumeConfigMap.getName()).getConfigMap(), is(configMap));
assertThat(getVolume(pod, additionalVolumePvc.getName()).getPersistentVolumeClaim(), is(pvc));
assertThat(getVolumeMount(pod.getSpec().getContainers().get(0), additionalVolumeMountConfigMap.getName()), is(additionalVolumeMountConfigMap));
assertThat(getVolumeMount(pod.getSpec().getInitContainers().get(0), additionalVolumeMountPvc.getName()), is(additionalVolumeMountPvc));

assertThat(pod.getSpec().getVolumes().size(), is(5));
assertThat(pod.getSpec().getVolumes().get(0).getName(), is(VolumeUtils.STRIMZI_TMP_DIRECTORY_DEFAULT_VOLUME_NAME));
assertThat(pod.getSpec().getVolumes().get(0).getEmptyDir(), is(notNullValue()));
assertThat(pod.getSpec().getVolumes().get(0).getEmptyDir().getSizeLimit(), is(new Quantity("10Mi")));
assertThat(pod.getSpec().getVolumes().get(1).getName(), is("kafka-metrics-and-logging"));
assertThat(pod.getSpec().getVolumes().get(1).getConfigMap().getName(), is("foo-mirrormaker2-config"));
assertThat(pod.getSpec().getVolumes().get(2).getName(), is("rack-volume"));
assertThat(pod.getSpec().getVolumes().get(2).getEmptyDir(), is(notNullValue()));
assertThat(pod.getSpec().getVolumes().get(2).getEmptyDir().getSizeLimit(), is(new Quantity("1Mi")));
assertThat(pod.getSpec().getVolumes().get(3).getName(), is("config-map-volume-name"));
assertThat(pod.getSpec().getVolumes().get(3).getConfigMap().getName(), is("configMap1"));
assertThat(pod.getSpec().getVolumes().get(4).getName(), is("pvc-volume-name"));
assertThat(pod.getSpec().getVolumes().get(4).getPersistentVolumeClaim().getClaimName(), is("pvc-name"));

assertThat(pod.getSpec().getInitContainers().get(0).getVolumeMounts().size(), is(2));
assertThat(pod.getSpec().getInitContainers().get(0).getVolumeMounts().get(0).getName(), is("rack-volume"));
assertThat(pod.getSpec().getInitContainers().get(0).getVolumeMounts().get(0).getMountPath(), is("/opt/kafka/init"));
assertThat(pod.getSpec().getInitContainers().get(0).getVolumeMounts().get(1).getName(), is("pvc-volume-name"));
assertThat(pod.getSpec().getInitContainers().get(0).getVolumeMounts().get(1).getMountPath(), is("/mnt/mypvc"));

assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().size(), is(4));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getName(), is(VolumeUtils.STRIMZI_TMP_DIRECTORY_DEFAULT_VOLUME_NAME));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath(), is(VolumeUtils.STRIMZI_TMP_DIRECTORY_DEFAULT_MOUNT_PATH));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(1).getName(), is("kafka-metrics-and-logging"));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(1).getMountPath(), is("/opt/kafka/custom-config/"));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(2).getName(), is("rack-volume"));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(2).getMountPath(), is("/opt/kafka/init"));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(3).getName(), is("config-map-volume-name"));
assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(3).getMountPath(), is("/mnt/myconfigmap"));
});

// Check Service
Service svc = kmm2.generateService();
assertThat(svc.getMetadata().getLabels().entrySet().containsAll(svcLabels.entrySet()), is(true));
Expand Down

0 comments on commit ac319a6

Please sign in to comment.