VolumeUtils { public static Volume createSecretVolume(String name, String secretName, Map<String, String> items, boolean isOpenshift) { String validName = getValidVolumeName(name); int mode = 0444; if (isOpenshift) { mode = 0440; } List<KeyToPath> keysPaths = new ArrayList<>(); for (Map.Entry<String, String> item : items.entrySet()) { KeyToPath keyPath = new KeyToPathBuilder() .withNewKey(item.getKey()) .withNewPath(item.getValue()) .build(); keysPaths.add(keyPath); } SecretVolumeSource secretVolumeSource = new SecretVolumeSourceBuilder() .withDefaultMode(mode) .withSecretName(secretName) .withItems(keysPaths) .build(); Volume volume = new VolumeBuilder() .withName(validName) .withSecret(secretVolumeSource) .build(); log.trace("Created secret Volume named '{}' with source secret '{}'", validName, secretName); return volume; }  static Volume createConfigMapVolume(String name, String configMapName); static Volume createSecretVolume(String name, String secretName, Map<String, String> items, boolean isOpenshift); static Volume createSecretVolume(String name, String secretName, boolean isOpenshift); static Volume createEmptyDirVolume(String name, String sizeLimit); static PersistentVolumeClaim createPersistentVolumeClaimTemplate(String name, PersistentClaimStorage storage); static VolumeMount createVolumeMount(String name, String path); static List<Volume> getDataVolumes(Storage storage); static List<PersistentVolumeClaim> getDataPersistentVolumeClaims(Storage storage); static List<VolumeMount> getDataVolumeMountPaths(Storage storage, String mountPath); static String getVolumePrefix(Integer id); static String getValidVolumeName(String originalName);  }
@Test public void testCreateSecretVolumeWithValidName() { Volume volume = VolumeUtils.createSecretVolume("oauth-my-secret", "my-secret", true); assertThat(volume.getName(), is("oauth-my-secret")); }
@Test public void testCreateSecretVolumeWithInvalidName() { Volume volume = VolumeUtils.createSecretVolume("oauth-my.secret", "my.secret", true); assertThat(volume.getName(), is("oauth-my-secret-b744ae5a")); }