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

Do not order all Yaml maps by keys, only the Helm values file #2702

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 @@ -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");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed because of https://github.com/eclipse/jkube/pull/2702/files#r1495937819.
Previously it read {"email":"[email protected]","password":"#>secrets??","username":"roland"} and now it reads {"username":"roland","password":"#>secrets??","email":"[email protected]"}

.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");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed because of https://github.com/eclipse/jkube/pull/2702/files#r1495937819.
Previously it read {"email":"[email protected]","password":"#>secrets??","username":"roland"} and now it reads {"username":"roland","password":"#>secrets??","email":"[email protected]"}

.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)
Copy link
Contributor Author

@Jurrie Jurrie Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to 2a478d1 (where this was introduced) it's used to order the Helm values.yaml file. That seems like using a sledgehammer to crack a nut. So that was reimplemented in https://github.com/eclipse/jkube/pull/2702/files#diff-33ee7412751801538cf1742ee790e3e2d82ab812d60f3d0c4913a9bf3a433ac0R377.

.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