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

Helm: Support configuration with the root alias already set #1144

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
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 @@ -132,8 +132,7 @@ public Map<String, String> writeHelmFiles(Session session, Project project,
Map<String, String> artifacts = new HashMap<>();
if (helmConfig.isEnabled()) {
validateHelmConfig(helmConfig);
List<ConfigReference> valuesReferences = mergeValuesReferencesFromDecorators(configReferences,
helmConfig.getAddIfStatements(), session);
List<ConfigReference> valuesReferences = mergeValuesReferencesFromDecorators(helmConfig, configReferences, session);

try {
LOGGER.info(String.format("Creating Helm Chart \"%s\"", helmConfig.getName()));
Expand Down Expand Up @@ -243,14 +242,15 @@ private Map<String, String> createEmptyChartFolder(HelmChartConfig helmConfig, P
return Collections.singletonMap(emptyChartsDir.toString(), EMPTY);
}

private List<ConfigReference> mergeValuesReferencesFromDecorators(List<ConfigReference> configReferencesFromConfig,
AddIfStatement[] addIfStatements, Session session) {
private List<ConfigReference> mergeValuesReferencesFromDecorators(HelmChartConfig helmConfig,
List<ConfigReference> configReferencesFromConfig, Session session) {
List<ConfigReference> configReferences = new LinkedList<>();
// From user
configReferences.addAll(configReferencesFromConfig);
// From if statements: these are boolean values
for (AddIfStatement addIfStatement : addIfStatements) {
configReferences.add(new ConfigReference(addIfStatement.getProperty(), null, addIfStatement.getWithDefaultValue()));
for (AddIfStatement addIfStatement : helmConfig.getAddIfStatements()) {
configReferences.add(new ConfigReference(deductProperty(helmConfig, addIfStatement.getProperty()),
null, addIfStatement.getWithDefaultValue()));
}
// From decorators: We need to reverse the order as the latest decorator was the latest applied and hence the one
// we should use.
Expand Down Expand Up @@ -319,7 +319,10 @@ private Map<String, String> createValuesYaml(HelmChartConfig helmConfig, List<Co

private String deductProperty(HelmChartConfig helmConfig, String property) {
if (!startWithDependencyPrefix(property, helmConfig.getDependencies())) {
property = helmConfig.getValuesRootAlias() + "." + property;
String prefix = helmConfig.getValuesRootAlias() + ".";
if (!property.startsWith(prefix)) {
property = prefix + property;
}
}

return property;
Expand Down Expand Up @@ -524,12 +527,12 @@ private List<Map<Object, Object>> replaceValuesInYamls(HelmChartConfig helmConfi
Map<String, Object> seen = new HashMap<>();

for (ConfigReference valueReference : valuesReferences) {
String valueReferenceProperty = helmConfig.getValuesRootAlias() + "." + valueReference.getProperty();
String valueReferenceProperty = deductProperty(helmConfig, valueReference.getProperty());

if (seen.containsKey(valueReference.getProperty())) {
if (seen.containsKey(valueReferenceProperty)) {
if (Strings.isNotNullOrEmpty(valueReference.getProfile())) {
Object value = Optional.ofNullable(valueReference.getValue())
.orElse(seen.get(valueReference.getProperty()));
.orElse(seen.get(valueReferenceProperty));
getValues(prodValues, valuesByProfile, valueReference).put(valueReferenceProperty, value);
}

Expand All @@ -546,7 +549,7 @@ private List<Map<Object, Object>> replaceValuesInYamls(HelmChartConfig helmConfi

Object value = Optional.ofNullable(valueReference.getValue()).orElse(found);
if (value != null) {
seen.put(valueReference.getProperty(), value);
seen.put(valueReferenceProperty, value);
getValues(prodValues, valuesByProfile, valueReference).put(valueReferenceProperty, value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dekorate.helm.values[2].property=vcs-url
dekorate.helm.values[2].paths=(kind == Deployment).spec.template.metadata.annotations.'app.dekorate.io/vcs-url'
dekorate.helm.values[2].value=Overridden
# Using values with profile
dekorate.helm.values[3].property=vcs-url
dekorate.helm.values[3].property=app.vcs-url
dekorate.helm.values[3].paths=(kind == Deployment).spec.template.metadata.annotations.'app.dekorate.io/vcs-url'
dekorate.helm.values[3].value=Only for DEV!
dekorate.helm.values[3].profile=dev
Expand Down