Skip to content

Commit

Permalink
Do not order all Yaml maps by keys, only the Helm values file
Browse files Browse the repository at this point in the history
Signed-off-by: Jurrie Overgoor <[email protected]>
  • Loading branch information
Jurrie committed Feb 16, 2024
1 parent 34503a1 commit 97e10a3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void simpleConstructor() {
// Since Base64.decodeBase64 handles URL-safe encoding, must explicitly check
// the correct characters are used
assertThat(config.toHeaderValue(new KitLogger.SilentLogger()))
.isEqualTo("eyJlbWFpbCI6InJvbGFuZEBqb2xva2lhLm9yZyIsInBhc3N3b3JkIjoiIz5zZWNyZXRzPz8iLCJ1c2VybmFtZSI6InJvbGFuZCJ9");
.isEqualTo("eyJ1c2VybmFtZSI6InJvbGFuZCIsInBhc3N3b3JkIjoiIz5zZWNyZXRzPz8iLCJlbWFpbCI6InJvbGFuZEBqb2xva2lhLm9yZyJ9");

String header = new String(Base64.getDecoder().decode(config.toHeaderValue(new KitLogger.SilentLogger())));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void check(RegistryAuth config) {
// Since Base64.decodeBase64 handles URL-safe encoding, must explicitly check
// the correct characters are used
assertThat(config.toHeaderValue())
.isEqualTo("eyJlbWFpbCI6InJvbGFuZEBqb2xva2lhLm9yZyIsInBhc3N3b3JkIjoiIz5zZWNyZXRzPz8iLCJ1c2VybmFtZSI6InJvbGFuZCJ9");
.isEqualTo("eyJ1c2VybmFtZSI6InJvbGFuZCIsInBhc3N3b3JkIjoiIz5zZWNyZXRzPz8iLCJlbWFpbCI6InJvbGFuZEBqb2xva2lhLm9yZyJ9");

String header = new String(Base64.getDecoder().decode(config.toHeaderValue()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class Serialization {
static {
for (ObjectMapper mapper : new ObjectMapper[]{JSON_MAPPER, YAML_MAPPER}) {
mapper.enable(SerializationFeature.INDENT_OUTPUT)
.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)
.disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS)
.disable(SerializationFeature.WRITE_NULL_MAP_VALUES);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.function.Consumer;
import java.util.function.UnaryOperator;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -368,7 +370,23 @@ private void createValuesYaml(List<HelmParameter> helmParameters, File outputDir
.collect(Collectors.toMap(HelmParameter::getName, HelmParameter::getValue));
final Map<String, Object> valuesFromFragment = readFragment(VALUES_FRAGMENT_PATTERN, Map.class);
final Map<String, Object> mergedValues = Serialization.merge(getNestedMap(valuesFromParameters), valuesFromFragment);
ResourceUtil.save(new File(outputDir, VALUES_FILENAME), mergedValues, ResourceFileType.yaml);
final Map<String, Object> sortedValues = sortValuesYaml(mergedValues);
ResourceUtil.save(new File(outputDir, VALUES_FILENAME), sortedValues, ResourceFileType.yaml);
}

private static SortedMap<String, Object> sortValuesYaml(final Map<String, Object> input) {
return (SortedMap<String, Object>) sortValuesYamlRecursive(input);
}

private static Object sortValuesYamlRecursive(final Object input) {
if (input instanceof Map) {
final Map<String, Object> inputMap = (Map<String, Object>) input;
final SortedMap<String, Object> result = new TreeMap<>();
inputMap.entrySet().stream().forEach(entry -> result.put(entry.getKey(), sortValuesYamlRecursive(entry.getValue())));
return result;
} else {
return input;
}
}

private static List<HelmParameter> collectParameters(HelmConfig helmConfig) {
Expand Down

0 comments on commit 97e10a3

Please sign in to comment.