Skip to content

Commit

Permalink
Always append '| quote' to map env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Carvajal Hilario authored and Sgitario committed Feb 21, 2024
1 parent 3162550 commit 2bc047e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static io.quarkiverse.helm.deployment.utils.YamlExpressionParserUtils.EMPTY;
import static io.quarkiverse.helm.deployment.utils.YamlExpressionParserUtils.END_EXPRESSION_TOKEN;
import static io.quarkiverse.helm.deployment.utils.YamlExpressionParserUtils.END_TAG;
import static io.quarkiverse.helm.deployment.utils.YamlExpressionParserUtils.QUOTE_CONVERSION;
import static io.quarkiverse.helm.deployment.utils.YamlExpressionParserUtils.SEPARATOR_QUOTES;
import static io.quarkiverse.helm.deployment.utils.YamlExpressionParserUtils.SEPARATOR_TOKEN;
import static io.quarkiverse.helm.deployment.utils.YamlExpressionParserUtils.START_EXPRESSION_TOKEN;
Expand Down Expand Up @@ -526,7 +527,7 @@ private List<Map<Object, Object>> populateValuesFromConfigReferences(HelmChartCo
String valueReferenceProperty = deductProperty(helmConfig, valueReference.getProperty());

processValueReference(valueReferenceProperty, valueReference.getValue(), valueReference, values, parser,
seen, paths);
seen, paths, EMPTY);
}
}

Expand All @@ -549,7 +550,7 @@ private List<Map<Object, Object>> populateValuesFromConfigReferences(HelmChartCo
}

processValueReference(valueReferenceProperty, valueReferenceValue, valueReference, values, parser, seen,
paths);
paths, QUOTE_CONVERSION);
}
}

Expand All @@ -574,7 +575,7 @@ private String getEnvironmentPropertyName(ConfigReference valueReference) {
}

private void processValueReference(String property, Object value, ConfigReference valueReference, ValuesHolder values,
YamlExpressionParser parser, Map<String, Object> seen, Set<String> paths) {
YamlExpressionParser parser, Map<String, Object> seen, Set<String> paths, String defaultConversion) {

String profile = valueReference.getProfile();
if (valueReference.getPaths() != null && valueReference.getPaths().length > 0) {
Expand All @@ -594,7 +595,7 @@ private void processValueReference(String property, Object value, ConfigReferenc
Object actualValue = Optional.ofNullable(value).orElse(found);

if (actualValue != null) {
set(parser, path, toExpression(property, value, found, valueReference));
set(parser, path, toExpression(property, value, found, valueReference, defaultConversion));
values.putIfAbsent(property, valueReference, actualValue, profile);
if (StringUtils.isEmpty(profile)) {
seen.putIfAbsent(property, actualValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public final class YamlExpressionParserUtils {
public static final String EMPTY = "";
public static final String VALUES_START_TAG = START_TAG + " .Values.";
public static final String VALUES_END_TAG = " " + END_TAG;
public static final String QUOTE_CONVERSION = " | quote";

private YamlExpressionParserUtils() {

Expand All @@ -39,19 +40,20 @@ public static Object readAndSet(YamlExpressionParser parser, String path, String
return found.stream().findFirst().orElse(null);
}

public static String toExpression(String property, Object provided, Object found, ConfigReference valueReference) {
public static String toExpression(String property, Object provided, Object found, ConfigReference valueReference,
String defaultConversion) {
Optional<String> expressionProvided = Optional.ofNullable(valueReference.getExpression())
.filter(StringUtils::isNotEmpty);

if (expressionProvided.isPresent()) {
return expressionProvided.get();
}

String conversion = EMPTY;
String conversion = defaultConversion;
// we only need to quote when the found value in the generated resources is a string, but the provided type isn't.
if (provided != null && !(provided instanceof String) && found instanceof String) {
// we need conversion
conversion = " | quote";
conversion = QUOTE_CONVERSION;
}

return VALUES_START_TAG + property + conversion + VALUES_END_TAG;
Expand Down

0 comments on commit 2bc047e

Please sign in to comment.