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

Always append '| quote' to map env vars #319

Merged
merged 1 commit into from
Feb 21, 2024
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 @@ -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
Loading