Source:
private void mountAsFile(E env, Secret secret, String targetContainerName) throws InfrastructureException { final String mountPath = secret.getMetadata().getAnnotations().get(ANNOTATION_MOUNT_PATH); if (mountPath == null) { throw new InfrastructureException( format( "Unable to mount secret '%s': it has to be mounted as file, but mountPath is not specified." + "Please make sure you specified '%s' annotation of secret.", secret.getMetadata().getName(), ANNOTATION_MOUNT_PATH)); } Volume volumeFromSecret = new VolumeBuilder() .withName(secret.getMetadata().getName()) .withSecret( new SecretVolumeSourceBuilder() .withNewSecretName(secret.getMetadata().getName()) .build()) .build(); for (PodData podData : env.getPodsData().values()) { if (!podData.getRole().equals(PodRole.DEPLOYMENT)) { continue; } if (podData .getSpec() .getVolumes() .stream() .anyMatch(v -> v.getName().equals(volumeFromSecret.getName()))) { throw new InfrastructureException( format( "Volume name '%s' provisioned from secret, clashes with existing volume name.", volumeFromSecret.getName())); } podData.getSpec().getVolumes().add(volumeFromSecret); for (Container container : podData.getSpec().getContainers()) { if (targetContainerName != null && !container.getName().equals(targetContainerName)) { continue; } if (container .getVolumeMounts() .stream() .anyMatch(vm -> vm.getMountPath().equals(mountPath))) { throw new InfrastructureException( format( "Volume Mount path '%s' provisioned from secret, clashes with existing volume mount path.", mountPath)); } container .getVolumeMounts() .add( new VolumeMountBuilder() .withName(volumeFromSecret.getName()) .withMountPath(mountPath) .withReadOnly(true) .build()); } } }

Target:
private void mountAsFile(E env, Secret secret, String targetContainerName) throws InfrastructureException { final String mountPath = secret.getMetadata().getAnnotations().get(ANNOTATION_MOUNT_PATH); if (mountPath == null) { throw new InfrastructureException( format( "Unable to mount secret '%s': It is configured to be mounted as a file but the mount path was not specified. Please define the '%s' annotation on the secret to specify it.", secret.getMetadata().getName(), ANNOTATION_MOUNT_PATH)); } Volume volumeFromSecret = new VolumeBuilder() .withName(secret.getMetadata().getName()) .withSecret( new SecretVolumeSourceBuilder() .withNewSecretName(secret.getMetadata().getName()) .build()) .build(); for (PodData podData : env.getPodsData().values()) { if (!podData.getRole().equals(PodRole.DEPLOYMENT)) { continue; } if (podData .getSpec() .getVolumes() .stream() .anyMatch(v -> v.getName().equals(volumeFromSecret.getName()))) { volumeFromSecret.setName(volumeFromSecret.getName() + "_" + NameGenerator.generate("", 6)); } podData.getSpec().getVolumes().add(volumeFromSecret); for (Container container : podData.getSpec().getContainers()) { if (targetContainerName != null && !container.getName().equals(targetContainerName)) { continue; } if (container .getVolumeMounts() .stream() .anyMatch(vm -> Paths.get(vm.getMountPath()).equals(Paths.get(mountPath)))) { throw new InfrastructureException( format( "The secret '%s' defines a mount path '%s' that clashes with another volume mount path already present on the workspace pod.", secret.getMetadata().getName(), mountPath)); } container .getVolumeMounts() .add( new VolumeMountBuilder() .withName(volumeFromSecret.getName()) .withMountPath(mountPath) .withReadOnly(true) .build()); } } }