Skip to content

Commit

Permalink
fix (jkube-kit/resource/helm) : Helm values.yaml sorted alphabetically
Browse files Browse the repository at this point in the history
Signed-off-by: Rohan Kumar <rohaan@redhat.com>
  • Loading branch information
rohanKanojia committed Dec 28, 2023
1 parent 8222af1 commit d3f74b8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Usage:
* Fix #2257: Provide guidance when the final project packaged file is not found in Quarkus projeicts
* Fix #1690: Base images based on ubi9
* Fix #2070: build goals/tasks log warning if user forgets to run package/build goal/task
* Fix #2389: Helm `values.yaml` sorted alphabetically
* Fix #2390: support for all missing Chart.yaml fields
* Fix #2444: Add support for Spring Boot application properties placeholders
* Fix #2456: Add utility class to decompress archive files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.TreeMap;
import java.util.function.Consumer;
import java.util.function.UnaryOperator;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -330,7 +331,7 @@ 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);
ResourceUtil.save(new File(outputDir, VALUES_FILENAME), new TreeMap<>(mergedValues), ResourceFileType.yaml);
}

private static List<HelmParameter> collectParameters(HelmConfig helmConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,25 @@ void generateHelmCharts_withValidValuesYamlFragment_usesMergedValues() throws Ex
);
}

@Test
@SuppressWarnings("unchecked")
void generateHelmCharts_whenInvoked_thenGeneratedValuesYamlInAlphabeticalOrder() throws IOException {
// Given
resourceServiceConfig = ResourceServiceConfig.builder().resourceDirs(Collections.singletonList(
new File(Objects.requireNonNull(getClass().getResource("/valid-helm-fragments")).getFile())))
.build();
helmConfig.types(Collections.singletonList(HelmType.KUBERNETES));

// When
new HelmService(jKubeConfiguration, resourceServiceConfig, new KitLogger.SilentLogger())
.generateHelmCharts(helmConfig.build());

// Then
final Map<String, ?> savedValues = Serialization.unmarshal(helmOutputDirectory.resolve("kubernetes").resolve("values.yaml").toFile(), Map.class);
assertThat(savedValues.keySet())
.containsExactly("image", "ingress", "replaceableProperty", "replicaCount", "service", "serviceAccount");
}

@Test
void createChartYamlWithDependencies() throws Exception {
// Given
Expand Down

0 comments on commit d3f74b8

Please sign in to comment.