Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make OCP config map name unique for same mount paths #992

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ private Map<String, String> enrichProperties(Map<String, String> properties, Dep
String path = entry.getValue().replace(RESOURCE_PREFIX, StringUtils.EMPTY);
String mountPath = getMountPath(path);
String filename = getFileName(path);
String configMapName = normalizeConfigMapName(mountPath);
String configMapName = normalizeConfigMapName(mountPath, filename);

// Update config map
createOrUpdateConfigMap(configMapName, filename, getFileContent(path));
Expand All @@ -855,7 +855,7 @@ private Map<String, String> enrichProperties(Map<String, String> properties, Dep
volumes.put(mountPath, new CustomVolume(configMapName, "", CONFIG_MAP));
}

propertyValue = mountPath + SLASH + filename;
propertyValue = joinMountPathAndFileName(mountPath, filename);
} else if (isResourceWithDestinationPath(propertyValue)) {
String path = propertyValue.replace(RESOURCE_WITH_DESTINATION_PREFIX, StringUtils.EMPTY);
if (!propertyValue.matches(RESOURCE_WITH_DESTINATION_PREFIX_MATCHER)) {
Expand All @@ -867,11 +867,11 @@ private Map<String, String> enrichProperties(Map<String, String> properties, Dep
String mountPath = path.split(RESOURCE_WITH_DESTINATION_SPLIT_CHAR)[0];
String fileName = path.split(RESOURCE_WITH_DESTINATION_SPLIT_CHAR)[1];
String fileNameNormalized = getFileName(fileName);
String configMapName = normalizeConfigMapName(mountPath);
String configMapName = normalizeConfigMapName(mountPath, fileNameNormalized);

// Update config map
createOrUpdateConfigMap(configMapName, fileNameNormalized, getFileContent(fileName));
propertyValue = mountPath + SLASH + fileNameNormalized;
propertyValue = joinMountPathAndFileName(mountPath, fileNameNormalized);
// Add the volume
if (!volumes.containsKey(mountPath)) {
volumes.put(propertyValue, new CustomVolume(configMapName, fileNameNormalized, CONFIG_MAP));
Expand All @@ -880,13 +880,13 @@ private Map<String, String> enrichProperties(Map<String, String> properties, Dep
String path = entry.getValue().replace(SECRET_PREFIX, StringUtils.EMPTY);
String mountPath = getMountPath(path);
String filename = getFileName(path);
String secretName = normalizeConfigMapName(path);
String secretName = normalizeConfigMapName(path, filename);

// Push secret file
doCreateSecretFromFile(secretName, getFilePath(path));
volumes.put(mountPath, new CustomVolume(secretName, "", SECRET));

propertyValue = mountPath + SLASH + filename;
propertyValue = joinMountPathAndFileName(mountPath, filename);
}

output.put(entry.getKey(), propertyValue);
Expand Down Expand Up @@ -975,12 +975,21 @@ private String getFilePath(String path) {
return path;
}

private String normalizeConfigMapName(String name) {
return StringUtils.removeStart(name, SLASH)
private String normalizeConfigMapName(String mountPath, String fileName) {
// /some/mount/path/file-name => some-mount-path-file-name
return StringUtils.removeStart(joinMountPathAndFileName(mountPath, fileName), SLASH)
.replaceAll(Pattern.quote("."), "-")
.replaceAll(SLASH, "-");
}

private static String joinMountPathAndFileName(String mountPath, String fileName) {
if (!mountPath.endsWith(SLASH)) {
// /some/mount/path => /some/mount/path/
mountPath += SLASH;
}
return mountPath + fileName;
}

private boolean isResourceWithDestinationPath(String key) {
return key.startsWith(RESOURCE_WITH_DESTINATION_PREFIX);
}
Expand Down
Loading