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

fix (jkube-kit/helm) : k8s:helm generated chart tar archive contains reference to tar archive #2643

Merged
merged 1 commit into from
Feb 9, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Usage:
* Fix #2532: Bump version.kubernetes-client from 6.9.2 to 6.10.0
* Fix #2613: Added new helm lint goal task (k8s:helm-lint / k8sHelmLint)
* Fix #2541: Container image names can now be set as IPv6 addresses
* Fix #2622: `k8s:helm` generated chart tar archive contains reference to tar archive

_**Note**_:
Kubernetes manifests generated by JKube would now contain the following labels by default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -124,8 +125,12 @@ public void generateHelmCharts(HelmConfig helmConfig) throws IOException {
logger.debug("Creating Helm configuration Tarball: '%s'", tarballFile.getAbsolutePath());
final Consumer<TarArchiveEntry> prependNameAsDirectory = tae ->
tae.setName(String.format("%s/%s", helmConfig.getChart(), tae.getName()));
// outputDir might contain tarball already from previous run, filter out tarball file outputDir from recursive listing
List<File> helmTarballContents = FileUtil.listFilesAndDirsRecursivelyInDirectory(outputDir).stream()
.filter(f -> !f.equals(tarballFile))
.collect(Collectors.toList());
JKubeTarArchiver.createTarBall(
tarballFile, outputDir, FileUtil.listFilesAndDirsRecursivelyInDirectory(outputDir), Collections.emptyMap(),
tarballFile, outputDir, helmTarballContents, Collections.emptyMap(),
ArchiveCompression.fromFileName(tarballFile.getName()), null, prependNameAsDirectory);
Optional.ofNullable(helmConfig.getGeneratedChartListeners()).orElse(Collections.emptyList())
.forEach(listener -> listener.chartFileGenerated(helmConfig, helmType, tarballFile));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.jkube.kit.common.util.Serialization;
import org.eclipse.jkube.kit.config.resource.ResourceServiceConfig;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

Expand Down Expand Up @@ -113,6 +114,28 @@ void generateHelmChartsTest() throws Exception {
assertThat(generatedChartCount).hasValue(2);
}

@Test
@DisplayName("when chart generated subsequent runs, then tar archive generated in previous run not present in updated archive")
void generateHelmCharts_whenInvokedTwice_thenFinalChartTarballDoesNotContainPreviousGeneratedHelmChartTarballReference() throws IOException {
// Given
helmConfig.setChart("ITChart");
helmConfig.setVersion("1.33.7");
helmConfig.setChartExtension("tar.gz");
helmConfig.setTypes(Collections.singletonList(HelmConfig.HelmType.KUBERNETES));

// When
helmService.generateHelmCharts(helmConfig);
helmService.generateHelmCharts(helmConfig);

// Then
ArchiveAssertions.assertThat(new File(helmOutputDir, "kubernetes/ITChart-1.33.7.tar.gz"))
.exists().isNotEmpty().fileTree().containsExactlyInAnyOrder(
"ITChart/templates/",
"ITChart/templates/kubernetes.yaml",
"ITChart/Chart.yaml",
"ITChart/values.yaml");
}

@Test
void generateHelmChartsTest_withInvalidParameters_throwsException() {
// Given
Expand Down