Skip to content

Commit

Permalink
[ST] ConnectST: switch from (deprecated) External Config volumes to v…
Browse files Browse the repository at this point in the history
…olume mounts. (#10609)

Signed-off-by: hzrncik <[email protected]>
  • Loading branch information
henryZrncik authored Sep 25, 2024
1 parent 54a7661 commit ede3540
Showing 1 changed file with 65 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import io.fabric8.kubernetes.api.model.SecretBuilder;
import io.fabric8.kubernetes.api.model.SecretKeySelectorBuilder;
import io.fabric8.kubernetes.api.model.SecretVolumeSourceBuilder;
import io.fabric8.kubernetes.api.model.VolumeMount;
import io.fabric8.kubernetes.api.model.VolumeMountBuilder;
import io.skodjob.annotations.Desc;
import io.skodjob.annotations.Label;
import io.skodjob.annotations.Step;
Expand Down Expand Up @@ -1414,6 +1416,9 @@ void testMountingSecretAndConfigMapAsVolumesAndEnvVars() {

final String dotedConfigMapName = "connect.config.map";
final String dotedSecretName = "connect.secret";
// volumes for config maps and secrets containing "." symbol must be named without it (Kubernetes constraint)
final String dotedConfigMapVolumeName = "doted-configmap-volume-name";
final String dotedSecretVolumeName = "doted-secret-volume-name";

final String configMapKey = "my-key";
final String secretKey = "my-secret-key";
Expand Down Expand Up @@ -1452,6 +1457,30 @@ void testMountingSecretAndConfigMapAsVolumesAndEnvVars() {
.addToData(configMapKey, configMapValue)
.build();

final String secretMountPath = "/mnt/secret-volume";
final String configMapMountPath = "/mnt/configmap-volume";
final String dotedSecretMountPath = "/mnt/doted-secret-volume";
final String dotedConfigMapMountPath = "/mnt/doted-configmap-volume";

VolumeMount[] volumeMounts = new VolumeMount[]{
new VolumeMountBuilder()
.withName(secretName)
.withMountPath(secretMountPath)
.build(),
new VolumeMountBuilder()
.withName(configMapName)
.withMountPath(configMapMountPath)
.build(),
new VolumeMountBuilder()
.withName(dotedSecretVolumeName)
.withMountPath(dotedSecretMountPath)
.build(),
new VolumeMountBuilder()
.withName(dotedConfigMapVolumeName)
.withMountPath(dotedConfigMapMountPath)
.build()
};

kubeClient(testStorage.getNamespaceName()).createSecret(connectSecret);
kubeClient(testStorage.getNamespaceName()).createSecret(dotedConnectSecret);

Expand All @@ -1471,22 +1500,6 @@ void testMountingSecretAndConfigMapAsVolumesAndEnvVars() {
.endMetadata()
.editSpec()
.withNewExternalConfiguration()
.addNewVolume()
.withName(secretName)
.withSecret(new SecretVolumeSourceBuilder().withSecretName(secretName).build())
.endVolume()
.addNewVolume()
.withName(configMapName)
.withConfigMap(new ConfigMapVolumeSourceBuilder().withName(configMapName).build())
.endVolume()
.addNewVolume()
.withName(dotedSecretName)
.withSecret(new SecretVolumeSourceBuilder().withSecretName(dotedSecretName).build())
.endVolume()
.addNewVolume()
.withName(dotedConfigMapName)
.withConfigMap(new ConfigMapVolumeSourceBuilder().withName(dotedConfigMapName).build())
.endVolume()
.addNewEnv()
.withName(secretEnv)
.withNewValueFrom()
Expand Down Expand Up @@ -1531,7 +1544,35 @@ void testMountingSecretAndConfigMapAsVolumesAndEnvVars() {
.build())
.endValueFrom()
.endEnv()
// TODO remove deprecated (yet still working) way of provisioning external configurations
.addNewVolume()
.withName(configMapName)
.withConfigMap(new ConfigMapVolumeSourceBuilder().withName(configMapName).build())
.endVolume()
.endExternalConfiguration()
.editOrNewTemplate()
.editOrNewPod()
.addNewVolume()
.withName(secretName)
.withSecret(new SecretVolumeSourceBuilder().withSecretName(secretName).build())
.endVolume()
.addNewVolume()
.withName(configMapName)
.withConfigMap(new ConfigMapVolumeSourceBuilder().withName(configMapName).build())
.endVolume()
.addNewVolume()
.withName(dotedSecretVolumeName)
.withSecret(new SecretVolumeSourceBuilder().withSecretName(dotedSecretName).build())
.endVolume()
.addNewVolume()
.withName(dotedConfigMapVolumeName)
.withConfigMap(new ConfigMapVolumeSourceBuilder().withName(dotedConfigMapName).build())
.endVolume()
.endPod()
.editOrNewConnectContainer()
.addToVolumeMounts(volumeMounts)
.endConnectContainer()
.endTemplate()
.endSpec()
.build());

Expand All @@ -1545,21 +1586,25 @@ void testMountingSecretAndConfigMapAsVolumesAndEnvVars() {

LOGGER.info("Check if volumes contains desired values");
assertThat(
cmdKubeClient(testStorage.getNamespaceName()).execInPod(connectPodName, "/bin/bash", "-c", "cat external-configuration/" + configMapName + "/" + configMapKey).out().trim(),
cmdKubeClient(testStorage.getNamespaceName()).execInPod(connectPodName, "/bin/bash", "-c", "cat " + configMapMountPath + "/" + configMapKey).out().trim(),
equalTo(configMapValue)
);
assertThat(
cmdKubeClient(testStorage.getNamespaceName()).execInPod(connectPodName, "/bin/bash", "-c", "cat external-configuration/" + secretName + "/" + secretKey).out().trim(),
cmdKubeClient(testStorage.getNamespaceName()).execInPod(connectPodName, "/bin/bash", "-c", "cat " + secretMountPath + "/" + secretKey).out().trim(),
equalTo(secretPassword)
);
assertThat(
cmdKubeClient(testStorage.getNamespaceName()).execInPod(connectPodName, "/bin/bash", "-c", "cat external-configuration/" + dotedConfigMapName + "/" + configMapKey).out().trim(),
cmdKubeClient(testStorage.getNamespaceName()).execInPod(connectPodName, "/bin/bash", "-c", "cat " + dotedConfigMapMountPath + "/" + configMapKey).out().trim(),
equalTo(configMapValue)
);
assertThat(
cmdKubeClient(testStorage.getNamespaceName()).execInPod(connectPodName, "/bin/bash", "-c", "cat external-configuration/" + dotedSecretName + "/" + secretKey).out().trim(),
cmdKubeClient(testStorage.getNamespaceName()).execInPod(connectPodName, "/bin/bash", "-c", "cat " + dotedSecretMountPath + "/" + secretKey).out().trim(),
equalTo(secretPassword)
);
assertThat(
cmdKubeClient(testStorage.getNamespaceName()).execInPod(connectPodName, "/bin/bash", "-c", "cat external-configuration/" + configMapName + "/" + configMapKey).out().trim(),
equalTo(configMapValue)
);
}

@ParallelNamespaceTest
Expand Down

0 comments on commit ede3540

Please sign in to comment.