Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -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
6 changes: 6 additions & 0 deletions jkube-kit/parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,12 @@
<version>${version.mockito}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very strange that I needed this in OpenshiftHelmPushMojoTest for the org.mockito.Mockito.mockConstruction(HelmService.class); thingy, but HelmPushMojoTest doesn't need it...

Copy link
Member

Choose a reason for hiding this comment

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

I think you can avoid this by adding mockito-inline folder in src/test/resources

Copy link
Contributor Author

@Jurrie Jurrie Mar 11, 2024

Choose a reason for hiding this comment

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

Wow, I never knew! Thanks for the tip! Implemented in e463ef7.

<version>${version.mockito}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.fabric8</groupId>
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