Skip to content
Open
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 @@ -52,18 +52,6 @@ void tearDown() {
helmServiceMockedConstruction.close();
}

@Test
void runTask_withNoTemplateDir_shouldThrowException() {
// Given
KubernetesHelmPushTask kubernetesHelmPushTask = new KubernetesHelmPushTask(KubernetesExtension.class);

// When & Then
assertThatIllegalStateException()
.isThrownBy(kubernetesHelmPushTask::runTask)
.withMessageContaining("META-INF/jkube/kubernetes")
.withCauseInstanceOf(NoSuchFileException.class);
}

@Test
void runTask_withTemplateDir_shouldCallHelmService() throws IOException, BadUploadException {
// Given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ void tearDown() {
helmServiceMockedConstruction.close();
}

@Test
void runTask_withNoTemplateDir_shouldThrowException() {
// Given
KubernetesHelmTask kubernetesHelmTask = new KubernetesHelmTask(KubernetesExtension.class);

// When & Then
assertThatIllegalStateException()
.isThrownBy(kubernetesHelmTask::runTask)
.withMessageContaining("META-INF/jkube/kubernetes")
.withCauseInstanceOf(NoSuchFileException.class);
}

@Test
void runTask_withTemplateDir_shouldCallHelmService() throws IOException {
// Given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ void tearDown() {
helmServiceMockedConstruction.close();
}

@Test
void runTask_withNoTemplateDir_shouldThrowException() {
// Given
OpenShiftHelmPushTask openShiftHelmPushTask = new OpenShiftHelmPushTask(OpenShiftExtension.class);

// When & Then
assertThatIllegalStateException()
.isThrownBy(openShiftHelmPushTask::runTask)
.withMessageContaining("META-INF/jkube/openshift")
.withCauseInstanceOf(NoSuchFileException.class);
}

@Test
void runTask_withTemplateDir_shouldCallHelmService() throws IOException, BadUploadException {
// Given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,6 @@ void tearDown() {
helmServiceMockedConstruction.close();
}

@Test
void runTask_withNoTemplateDir_shouldThrowException() {
// Given
OpenShiftHelmTask kubernetesHelmTask = new OpenShiftHelmTask(OpenShiftExtension.class);

// When & Then
assertThatIllegalStateException()
.isThrownBy(kubernetesHelmTask::runTask)
.withMessageContaining("META-INF/jkube/openshift")
.withCauseInstanceOf(NoSuchFileException.class);
}

@Test
void runTask_withTemplateDir_shouldCallHelmService() throws IOException {
// Given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ static List<Template> findTemplates(File templateDir) throws IOException {
}
for (File sourceFile : Objects
.requireNonNull(sourceFiles, "No template files found in the provided directory")) {
if (!sourceFile.exists()) {
continue;
}
final KubernetesResource dto = Serialization.unmarshal(sourceFile);
if (dto instanceof Template) {
ret.add((Template) dto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,43 @@
*/
package org.eclipse.jkube.maven.plugin.mojo.build;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.eclipse.jkube.kit.resource.helm.HelmConfig;
import org.eclipse.jkube.kit.resource.helm.HelmService;

@Mojo(name = "helm-lint", defaultPhase = LifecyclePhase.INTEGRATION_TEST, requiresDependencyResolution = ResolutionScope.COMPILE)
public class HelmLintMojo extends AbstractHelmMojo {

@Override
public void init() throws MojoFailureException {
super.init();

checkChartsExist(getHelm());
}

private void checkChartsExist(final HelmConfig helmConfig) {
for (HelmConfig.HelmType helmType : helmConfig.getTypes()) {
final Path chart = Paths.get(helmConfig.getOutputDir(), helmType.getOutputDir(), HelmService.CHART_FILENAME);
if (Files.notExists(chart)) {
logChartNotFoundWarning(chart);
}
}
}

@Override
public void executeInternal() throws MojoExecutionException {
jkubeServiceHub.getHelmService().lint(getHelm());
}

protected void logChartNotFoundWarning(final Path chart) {
getKitLogger().warn("No Helm chart has been generated yet by the k8s:helm goal at: " + chart);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,41 @@
*/
package org.eclipse.jkube.maven.plugin.mojo.build;

import static org.eclipse.jkube.kit.resource.helm.HelmServiceUtil.initHelmPushConfig;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.eclipse.jkube.kit.resource.helm.HelmConfig;
import org.eclipse.jkube.kit.resource.helm.HelmService;
import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher;

import static org.eclipse.jkube.kit.resource.helm.HelmServiceUtil.initHelmPushConfig;

@Mojo(name = "helm-push", defaultPhase = LifecyclePhase.INSTALL, requiresDependencyResolution = ResolutionScope.COMPILE)
public class HelmPushMojo extends AbstractHelmMojo {

@Override
public void init() throws MojoFailureException {
super.init();

checkChartsExist(getHelm());
initHelmPushConfig(helm, javaProject);
}

private void checkChartsExist(final HelmConfig helmConfig) {
for (HelmConfig.HelmType helmType : helmConfig.getTypes()) {
final Path chart = Paths.get(helmConfig.getOutputDir(), helmType.getOutputDir(), HelmService.CHART_FILENAME);
if (Files.notExists(chart)) {
logChartNotFoundWarning(chart);
}
}
}

@Override
public void executeInternal() throws MojoExecutionException {
try {
Expand All @@ -44,4 +60,8 @@ public void executeInternal() throws MojoExecutionException {
throw new MojoExecutionException(exp.getMessage(), exp);
}
}

protected void logChartNotFoundWarning(final Path chart) {
getKitLogger().warn("No Helm chart has been generated yet by the k8s:helm goal at: " + chart);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
*/
package org.eclipse.jkube.maven.plugin.mojo.build;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.file.Path;

import com.marcnuri.helm.Helm;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
Expand All @@ -23,13 +30,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.file.Path;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class HelmLintMojoTest {

@TempDir
Expand All @@ -38,20 +38,20 @@ class HelmLintMojoTest {
private ByteArrayOutputStream outputStream;
private HelmLintMojo helmLintMojo;


@BeforeEach
void setUp() throws Exception {
void setUp() {
originalPrintStream = System.out;
outputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(outputStream));
helmLintMojo = new HelmLintMojo();

helmLintMojo.helm = HelmConfig.builder().chartExtension("tgz").build();
helmLintMojo.interpolateTemplateParameters = true;
helmLintMojo.settings = new Settings();
helmLintMojo.project = new MavenProject();
helmLintMojo.project.setVersion("0.1.0");
helmLintMojo.project.getBuild()
.setOutputDirectory(projectDir.resolve("target").resolve("classes").toFile().getAbsolutePath());
.setOutputDirectory(projectDir.resolve("target").resolve("classes").toFile().getAbsolutePath());
helmLintMojo.project.getBuild().setDirectory(projectDir.resolve("target").toFile().getAbsolutePath());
helmLintMojo.project.setFile(projectDir.resolve("target").toFile());
}
Expand All @@ -65,23 +65,24 @@ void tearDown() {
@Test
void execute_withMissingHelmPackage_shouldThrowException() {
assertThatThrownBy(helmLintMojo::execute)
.isInstanceOf(JKubeException.class)
.hasMessage("Linting failed");
.isInstanceOf(JKubeException.class)
.hasMessage("Linting failed");
assertThat(outputStream.toString())
.contains("Linting empty-project 0.1.0\n")
.contains("Using packaged file:")
.contains("[[W]]Error unable to open tarball:");
.contains("No Helm chart has been generated yet by the k8s:helm goal at: ")
.contains("Linting empty-project 0.1.0\n")
.contains("Using packaged file:")
.contains("[[W]]Error unable to open tarball:");
}

@Test
void execute_withHelmPackage_shouldSucceed() throws Exception {
Helm.create().withDir(projectDir).withName("empty-project").call()
.packageIt().withDestination(projectDir.resolve("target").resolve("jkube").resolve("helm").resolve("empty-project").resolve("kubernetes")).call();
.packageIt().withDestination(projectDir.resolve("target").resolve("jkube").resolve("helm").resolve("empty-project").resolve("kubernetes")).call();
helmLintMojo.execute();
assertThat(outputStream.toString())
.contains("Linting empty-project 0.1.0\n")
.contains("Using packaged file:")
.contains("[[W]][INFO] Chart.yaml: icon is recommended")
.contains("Linting successful");
.contains("Linting empty-project 0.1.0\n")
.contains("Using packaged file:")
.contains("[[W]][INFO] Chart.yaml: icon is recommended")
.contains("Linting successful");
}
}
Loading